fix: Gemini not reaching end state (#1027)

This commit is contained in:
William Heryanto 2025-01-05 20:11:04 +07:00 committed by GitHub
parent 0536c6e552
commit 369410bdb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -69,8 +69,13 @@ M.parse_response = function(data_stream, _, opts)
if not ok then opts.on_complete(json) end
if json.candidates then
if #json.candidates > 0 then
opts.on_chunk(json.candidates[1].content.parts[1].text)
elseif json.candidates.finishReason and json.candidates.finishReason == "STOP" then
if json.candidates[1].finishReason and json.candidates[1].finishReason == "STOP" then
opts.on_chunk(json.candidates[1].content.parts[1].text)
opts.on_complete(nil)
else
opts.on_chunk(json.candidates[1].content.parts[1].text)
end
else
opts.on_complete(nil)
end
end