From e1f10a697e48be33ec10cdb8f27a38dc6d504b12 Mon Sep 17 00:00:00 2001 From: HuangZiy <38649663+HuangZiy@users.noreply.github.com> Date: Fri, 29 Mar 2024 05:46:27 +0800 Subject: [PATCH] openai[patch]: perform judgment processing on chat model streaming delta (#18983) **PR title:** partners: openai chat model **PR message:** perform judgment processing on chat model streaming delta Closes #18977 Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> --- libs/partners/openai/langchain_openai/chat_models/base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/partners/openai/langchain_openai/chat_models/base.py b/libs/partners/openai/langchain_openai/chat_models/base.py index f11c13ce96d..90b7c9c8fd5 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 )