From 3ab2a5d68ea2c6e06161fc49c0de56cee5c0a2e0 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 7 May 2025 01:02:11 +0800 Subject: [PATCH] fix: check on_chunk if it is a nil (#1998) --- lua/avante/providers/openai.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/avante/providers/openai.lua b/lua/avante/providers/openai.lua index fed0433..7abdb1e 100644 --- a/lua/avante/providers/openai.lua +++ b/lua/avante/providers/openai.lua @@ -335,7 +335,8 @@ function M:parse_response_without_stream(data, _, opts) if json.choices and json.choices[1] then local choice = json.choices[1] if choice.message and choice.message.content then - opts.on_chunk(choice.message.content) + if opts.on_chunk then opts.on_chunk(choice.message.content) end + self:add_text_message({}, choice.message.content, "generated", opts) vim.schedule(function() opts.on_stop({ reason = "complete" }) end) end end