fix: copilot gemini function calling (#1947)

This commit is contained in:
yetone
2025-05-01 00:09:39 +08:00
committed by GitHub
parent 59554e1cb0
commit 99a2e35ff3

View File

@@ -246,17 +246,10 @@ function M:parse_response(ctx, data_stream, _, opts)
if choice.finish_reason == "stop" or choice.finish_reason == "eos_token" then
if choice.delta.content and choice.delta.content ~= vim.NIL then
self:add_text_message(ctx, choice.delta.content, "generated", opts)
opts.on_chunk(choice.delta.content)
if opts.on_chunk then opts.on_chunk(choice.delta.content) end
end
self:finish_pending_messages(ctx, opts)
opts.on_stop({ reason = "complete" })
elseif choice.finish_reason == "tool_calls" then
self:finish_pending_messages(ctx, opts)
opts.on_stop({
reason = "tool_use",
-- tool_use_list = ctx.tool_use_list,
usage = jsn.usage,
})
elseif choice.delta.reasoning_content and choice.delta.reasoning_content ~= vim.NIL then
if ctx.returned_think_start_tag == nil or not ctx.returned_think_start_tag then
ctx.returned_think_start_tag = true
@@ -284,7 +277,7 @@ function M:parse_response(ctx, data_stream, _, opts)
local tool_use = {
name = tool_call["function"].name,
id = tool_call.id,
input_json = "",
input_json = type(tool_call["function"].arguments) == "string" and tool_call["function"].arguments or "",
}
ctx.tool_use_list[tool_call.index + 1] = tool_use
self:add_tool_use_message(tool_use, "generating", opts)
@@ -313,6 +306,13 @@ function M:parse_response(ctx, data_stream, _, opts)
self:add_text_message(ctx, choice.delta.content, "generating", opts)
end
end
if choice.finish_reason == "tool_calls" then
self:finish_pending_messages(ctx, opts)
opts.on_stop({
reason = "tool_use",
usage = jsn.usage,
})
end
end
function M:parse_response_without_stream(data, _, opts)