Skip to content

Commit

Permalink
feat: default to openai compatible headers (#168)
Browse files Browse the repository at this point in the history
so API like groq don't have to be added explicitly
  • Loading branch information
marceldev89 authored Jul 24, 2024
1 parent 872f537 commit 7b84846
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions lua/gp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1440,40 +1440,20 @@ M.query = function(buf, provider, payload, handler, on_exit, callback)
"-H",
"Authorization: Bearer " .. bearer,
}
end

if provider == "openai" then
elseif provider == "openai" then
headers = {
"-H",
"Authorization: Bearer " .. bearer,
-- backwards compatibility
"-H",
"api-key: " .. bearer,
}
end

if provider == "openrouter" then
headers = {
"-H",
"Authorization: Bearer " .. bearer,
}
end

if provider == "pplx" then
headers = {
"-H",
"Authorization: Bearer " .. bearer,
}
end

if provider == "googleai" then
elseif provider == "googleai" then
headers = {}
endpoint = M._H.template_replace(endpoint, "{{secret}}", bearer)
endpoint = M._H.template_replace(endpoint, "{{model}}", payload.model)
payload.model = nil
end

if provider == "anthropic" then
elseif provider == "anthropic" then
headers = {
"-H",
"x-api-key: " .. bearer,
Expand All @@ -1482,14 +1462,17 @@ M.query = function(buf, provider, payload, handler, on_exit, callback)
"-H",
"anthropic-beta: messages-2023-12-15",
}
end

if provider == "azure" then
elseif provider == "azure" then
headers = {
"-H",
"api-key: " .. bearer,
}
endpoint = M._H.template_replace(endpoint, "{{model}}", payload.model)
else -- default to openai compatible headers
headers = {
"-H",
"Authorization: Bearer " .. bearer,
}
end

local curl_params = vim.deepcopy(M.config.curl_params or {})
Expand Down

0 comments on commit 7b84846

Please sign in to comment.