refactor: history messages (#1934)
This commit is contained in:
@@ -16,7 +16,7 @@ M.is_reasoning_model = P.openai.is_reasoning_model
|
||||
|
||||
function M:is_disable_stream() return false end
|
||||
|
||||
function M:parse_stream_data(ctx, data, handler_opts)
|
||||
function M:parse_stream_data(ctx, data, opts)
|
||||
local ok, json_data = pcall(vim.json.decode, data)
|
||||
if not ok or not json_data then
|
||||
-- Add debug logging
|
||||
@@ -26,11 +26,13 @@ function M:parse_stream_data(ctx, data, handler_opts)
|
||||
|
||||
if json_data.message and json_data.message.content then
|
||||
local content = json_data.message.content
|
||||
if content and content ~= "" then handler_opts.on_chunk(content) end
|
||||
P.openai:add_text_message(ctx, content, "generating", opts)
|
||||
if content and content ~= "" and opts.on_chunk then opts.on_chunk(content) end
|
||||
end
|
||||
|
||||
if json_data.done then
|
||||
handler_opts.on_stop({ reason = "complete" })
|
||||
P.openai:finish_pending_messages(ctx, opts)
|
||||
opts.on_stop({ reason = "complete" })
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user