fix: gemini content parts is nil (#1942)

This commit is contained in:
yetone
2025-04-30 14:07:59 +08:00
committed by GitHub
parent 48a415ef01
commit ca181b44c1

View File

@@ -137,6 +137,7 @@ function M:parse_response(ctx, data_stream, _, opts)
local candidate = json.candidates[1]
---@type AvanteLLMToolUse[]
local tool_use_list = {}
if candidate.content.parts ~= nil then
for _, part in ipairs(candidate.content.parts) do
if part.text then
if opts.on_chunk then opts.on_chunk(part.text) end
@@ -153,6 +154,7 @@ function M:parse_response(ctx, data_stream, _, opts)
OpenAI:add_tool_use_message(tool_use, "generated", opts)
end
end
end
if candidate.finishReason and candidate.finishReason == "STOP" then
OpenAI:finish_pending_messages(ctx, opts)
if #tool_use_list > 0 then