From 369410bdb1fc8c18b52113df0860dc9d8b4e566c Mon Sep 17 00:00:00 2001 From: William Heryanto Date: Sun, 5 Jan 2025 20:11:04 +0700 Subject: [PATCH] fix: Gemini not reaching end state (#1027) --- lua/avante/providers/gemini.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/avante/providers/gemini.lua b/lua/avante/providers/gemini.lua index 3a42124..11a1660 100644 --- a/lua/avante/providers/gemini.lua +++ b/lua/avante/providers/gemini.lua @@ -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