Skip to content

Commit

Permalink
fix: openai json parse
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone committed Aug 15, 2024
1 parent b3132f4 commit 918b517
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lua/avante/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 918b517

Please sign in to comment.