fix: reasoning content processing (#1171)

This commit is contained in:
yetone 2025-02-03 21:55:12 +08:00 committed by GitHub
parent 5ac934f228
commit 8536d102be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -124,11 +124,20 @@ M.parse_response = function(ctx, data_stream, _, opts)
ctx.returned_think_start_tag = true
opts.on_chunk("<think>\n")
end
ctx.last_think_content = choice.delta.reasoning_content
opts.on_chunk(choice.delta.reasoning_content)
elseif choice.delta.content then
if ctx.returned_think_end_tag == nil or not ctx.returned_think_end_tag then
ctx.returned_think_end_tag = true
opts.on_chunk("\n</think>\n\n")
if
ctx.last_think_content
and ctx.last_think_content ~= vim.NIL
and ctx.last_think_content:sub(-1) ~= "\n"
then
opts.on_chunk("\n</think>\n")
else
opts.on_chunk("</think>\n")
end
end
if choice.delta.content ~= vim.NIL then opts.on_chunk(choice.delta.content) end
end