Skip to content

Commit

Permalink
fix: refactor ask function to handle content properly
Browse files Browse the repository at this point in the history
This commit ensures that response content of non-streaming types
(when is_stream has false) is not ignored due to the finish_reason.
  • Loading branch information
JunKi Jin authored and deathbeam committed Dec 10, 2024
1 parent 1fe19d1 commit 57c0696
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions lua/CopilotChat/copilot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -635,25 +635,19 @@ function Copilot:ask(prompt, opts)

last_message = content
local choice = content.choices[1]

if choice.finish_reason then
if job then
finish_stream(nil, job)
end
return
end

content = choice.message and choice.message.content or choice.delta and choice.delta.content

if not content then
return
if content then
full_response = full_response .. content
end

if on_progress then
if content and on_progress then
on_progress(content)
end

full_response = full_response .. content
if choice.finish_reason and job then
finish_stream(nil, job)
end
end

local function parse_stream_line(line, job)
Expand Down

0 comments on commit 57c0696

Please sign in to comment.