From bb5411cd9a88f6da99f877229ea1365ee95388ba Mon Sep 17 00:00:00 2001
From: Daniel Rodriguez <daniel@danielfrg.com>
Date: Wed, 28 Aug 2024 17:36:50 -0500
Subject: [PATCH] fix(openai): first chunk emit errors (#337)

---
 lua/avante/providers/openai.lua | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lua/avante/providers/openai.lua b/lua/avante/providers/openai.lua
index cfbe516..aa37382 100644
--- a/lua/avante/providers/openai.lua
+++ b/lua/avante/providers/openai.lua
@@ -95,7 +95,9 @@ M.parse_response = function(data_stream, _, opts)
       if choice.finish_reason == "stop" then
         opts.on_complete(nil)
       elseif choice.delta.content then
-        opts.on_chunk(choice.delta.content)
+        if choice.delta.content ~= vim.NIL then
+            opts.on_chunk(choice.delta.content)
+        end
       end
     end
   end