From 8536d102be3ffda04702eabe46bb89a39f3e9e1f Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 3 Feb 2025 21:55:12 +0800 Subject: [PATCH] fix: reasoning content processing (#1171) --- lua/avante/providers/openai.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/avante/providers/openai.lua b/lua/avante/providers/openai.lua index 59942d3..8aa2441 100644 --- a/lua/avante/providers/openai.lua +++ b/lua/avante/providers/openai.lua @@ -124,11 +124,20 @@ M.parse_response = function(ctx, data_stream, _, opts) ctx.returned_think_start_tag = true opts.on_chunk("\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\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\n") + else + opts.on_chunk("\n") + end end if choice.delta.content ~= vim.NIL then opts.on_chunk(choice.delta.content) end end