fix: gemini & vertex tools (#2053)

* fix: tool calling with gemini and vertex

* chore: remove unnecessary comments

* chore: fix doc type errors

* feat: do not manually pass tool use list
This commit is contained in:
kernitus
2025-05-20 15:06:25 +01:00
committed by GitHub
parent ef61ba52c0
commit 87c4c6b493
2 changed files with 110 additions and 49 deletions

View File

@@ -14,6 +14,7 @@ M.role_map = {
M.is_disable_stream = Gemini.is_disable_stream
M.parse_messages = Gemini.parse_messages
M.parse_response = Gemini.parse_response
M.transform_to_function_declaration = Gemini.transform_to_function_declaration
local function execute_command(command)
local handle = io.popen(command)
@@ -34,23 +35,17 @@ end
function M:parse_curl_args(prompt_opts)
local provider_conf, request_body = P.parse_config(self)
local location = vim.fn.getenv("LOCATION")
local project_id = vim.fn.getenv("PROJECT_ID")
local model_id = provider_conf.model or "default-model-id"
if location == nil or location == vim.NIL then location = "default-location" end
if project_id == nil or project_id == vim.NIL then project_id = "default-project-id" end
local url = provider_conf.endpoint:gsub("LOCATION", location):gsub("PROJECT_ID", project_id)
local url = provider_conf.endpoint:gsub("LOCATION", location):gsub("PROJECT_ID", project_id)
url = string.format("%s/%s:streamGenerateContent?alt=sse", url, model_id)
request_body = vim.tbl_deep_extend("force", request_body, {
generationConfig = {
temperature = request_body.temperature,
maxOutputTokens = request_body.max_tokens,
},
})
request_body.temperature = nil
request_body.max_tokens = nil
local bearer_token = M.parse_api_key()
return {
@@ -61,7 +56,7 @@ function M:parse_curl_args(prompt_opts)
},
proxy = provider_conf.proxy,
insecure = provider_conf.allow_insecure,
body = vim.tbl_deep_extend("force", {}, self:parse_messages(prompt_opts), request_body),
body = Gemini.prepare_request_body(self, prompt_opts, provider_conf, request_body),
}
end