From 918b5175ab8c9f6c28bd229ea14a96eb1fd1374b Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 15 Aug 2024 14:09:13 +0800 Subject: [PATCH] fix: openai json parse --- lua/avante/init.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lua/avante/init.lua b/lua/avante/init.lua index 927c31e..841d0d7 100644 --- a/lua/avante/init.lua +++ b/lua/avante/init.lua @@ -357,8 +357,13 @@ local function call_openai_api_stream(question, code_lang, code_content, on_chun return end vim.schedule(function() - local success, parsed = pcall(fn.json_decode, line:sub(7)) + local piece = line:sub(7) + local success, parsed = pcall(fn.json_decode, piece) if not success then + if piece == "[DONE]" then + on_complete(nil) + return + end error("Error: failed to parse json: " .. parsed) return end @@ -572,7 +577,13 @@ function M.render_sidebar() local timestamp = get_timestamp() update_result_buf_content( - "## " .. timestamp .. "\n\n> " .. user_input:gsub("\n", "\n> ") .. "\n\nGenerating response...\n" + "## " + .. timestamp + .. "\n\n> " + .. user_input:gsub("\n", "\n> ") + .. "\n\nGenerating response from " + .. M.config.provider + .. " ...\n" ) local code_buf = get_cur_code_buf()