Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow OpenAI endpoint configuration via config #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

k2589
Copy link

@k2589 k2589 commented Feb 21, 2024

When a user wants to use other API-compatible services or use a local instance of GPT, might be needed to redefine the OpenAI base URL.

With new configuration option openai_base_url, the user is able to set up whatever he wants.
For example usage with a local instance of "g4f":

Run g4f container:

docker run -p 8080:8080 -p 1337:1337 -p 7900:7900 --shm-size="2g" hlohaus789/g4f:latest

Update plugin config to use it:

return {
    {
        "piersolenski/wtf.nvim",
        dependencies = {
            "MunifTanjim/nui.nvim",
        },
        config = function ()
            local wtf = require("wtf")
            wtf.setup({
                openai_api_key = "sk-xxxxxxxxxxxxxx",
                openai_model_id = "gpt-3.5-turbo",
                openai_base_url = "http:https://127.0.0.1:1337",
            })
        end
    },
}

@k2589
Copy link
Author

k2589 commented Feb 23, 2024

@piersolenski Hey! Could you review please?

if url == nil then
if vim.g.wtf_base_url_complained == nil then
local message =
"No OpenAI Base URL foun. Please set openai_base_url in the setup table. Defaulting to https://api.openai.com for now"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny typo with foun!

local function get_base_url()
local url = config.options.openai_base_url
if url == nil then
if vim.g.wtf_base_url_complained == nil then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor to not use vim globals?

@@ -67,13 +67,29 @@ local function get_api_key()
return api_key
end

local function get_base_url()
local url = config.options.openai_base_url
if url == nil then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the nil check necessary here? As we already have the default API endpoint set in the default_ops as a fallback for if one is not specified? Even if you intentionally set it to be nil in your config, the default will still be set in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants