Skip to content

The agent engineering platform.

community: delta in openai choice can be None, creates handler for that (#25954)

Tom Daniel Grande0207dc1431c2
diff --git a/libs/community/langchain_community/chat_models/openai.py b/libs/community/langchain_community/chat_models/openai.py
index a8d197d3be..54326d0acc 100644
--- a/libs/community/langchain_community/chat_models/openai.py
+++ b/libs/community/langchain_community/chat_models/openai.py
@@ -403,6 +403,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
)
@@ -495,6 +497,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
)