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