Skip to content

The agent engineering platform.

openai[patch]: perform judgment processing on chat model streaming delta (#18983)

HuangZiye1f10a697e48
diff --git a/libs/partners/openai/langchain_openai/chat_models/base.py b/libs/partners/openai/langchain_openai/chat_models/base.py
index f11c13ce96..90b7c9c8fd 100644
--- a/libs/partners/openai/langchain_openai/chat_models/base.py
+++ b/libs/partners/openai/langchain_openai/chat_models/base.py
@@ -463,6 +463,8 @@ class ChatOpenAI(BaseChatModel):
if len(chunk["choices"]) == 0:
continue
choice = chunk["choices"][0]
+ if choice["delta"] is None:
+ continue
chunk = _convert_delta_to_message_chunk(
choice["delta"], default_chunk_class
)
@@ -557,6 +559,8 @@ class ChatOpenAI(BaseChatModel):
if len(chunk["choices"]) == 0:
continue
choice = chunk["choices"][0]
+ if choice["delta"] is None:
+ continue
chunk = _convert_delta_to_message_chunk(
choice["delta"], default_chunk_class
)