fix: gemini content parts is nil (#1942)
This commit is contained in:
@@ -137,20 +137,22 @@ function M:parse_response(ctx, data_stream, _, opts)
|
|||||||
local candidate = json.candidates[1]
|
local candidate = json.candidates[1]
|
||||||
---@type AvanteLLMToolUse[]
|
---@type AvanteLLMToolUse[]
|
||||||
local tool_use_list = {}
|
local tool_use_list = {}
|
||||||
for _, part in ipairs(candidate.content.parts) do
|
if candidate.content.parts ~= nil then
|
||||||
if part.text then
|
for _, part in ipairs(candidate.content.parts) do
|
||||||
if opts.on_chunk then opts.on_chunk(part.text) end
|
if part.text then
|
||||||
OpenAI:add_text_message(ctx, part.text, "generating", opts)
|
if opts.on_chunk then opts.on_chunk(part.text) end
|
||||||
elseif part.functionCall then
|
OpenAI:add_text_message(ctx, part.text, "generating", opts)
|
||||||
if not ctx.function_call_id then ctx.function_call_id = 0 end
|
elseif part.functionCall then
|
||||||
ctx.function_call_id = ctx.function_call_id + 1
|
if not ctx.function_call_id then ctx.function_call_id = 0 end
|
||||||
local tool_use = {
|
ctx.function_call_id = ctx.function_call_id + 1
|
||||||
id = ctx.session_id .. "-" .. tostring(ctx.function_call_id),
|
local tool_use = {
|
||||||
name = part.functionCall.name,
|
id = ctx.session_id .. "-" .. tostring(ctx.function_call_id),
|
||||||
input_json = vim.json.encode(part.functionCall.args),
|
name = part.functionCall.name,
|
||||||
}
|
input_json = vim.json.encode(part.functionCall.args),
|
||||||
table.insert(tool_use_list, tool_use)
|
}
|
||||||
OpenAI:add_tool_use_message(tool_use, "generated", opts)
|
table.insert(tool_use_list, tool_use)
|
||||||
|
OpenAI:add_tool_use_message(tool_use, "generated", opts)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if candidate.finishReason and candidate.finishReason == "STOP" then
|
if candidate.finishReason and candidate.finishReason == "STOP" then
|
||||||
|
|||||||
Reference in New Issue
Block a user