From 3ec5f5d62803a710bcccf4d679cdfb6ec51ae78e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lenoir=20j=C3=A9r=C3=A9mie?= <lenoir.jeremie@roodeo.com>
Date: Wed, 6 Mar 2024 22:24:15 +0100
Subject: [PATCH] fix OpenAIAgent function not called in stream mode after a
 tools_call type response (#11713)

---
 llama-index-core/llama_index/core/chat_engine/types.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llama-index-core/llama_index/core/chat_engine/types.py b/llama-index-core/llama_index/core/chat_engine/types.py
index 29d27731bc..2e8fab6b02 100644
--- a/llama-index-core/llama_index/core/chat_engine/types.py
+++ b/llama-index-core/llama_index/core/chat_engine/types.py
@@ -115,7 +115,8 @@ class StreamingAgentChatResponse:
             final_text = ""
             for chat in self.chat_stream:
                 self._is_function = is_function(chat.message)
-                self.put_in_queue(chat.delta)
+                if chat.delta:
+                    self.put_in_queue(chat.delta)
                 final_text += chat.delta or ""
             if self._is_function is not None:  # if loop has gone through iteration
                 # NOTE: this is to handle the special case where we consume some of the
@@ -153,7 +154,8 @@ class StreamingAgentChatResponse:
             final_text = ""
             async for chat in self.achat_stream:
                 self._is_function = is_function(chat.message)
-                self.aput_in_queue(chat.delta)
+                if chat.delta:
+                    self.aput_in_queue(chat.delta)
                 final_text += chat.delta or ""
                 self._new_item_event.set()
                 if self._is_function is False:
-- 
GitLab