From 8d676aec6048d0cdd1b641862f26a287bb17b219 Mon Sep 17 00:00:00 2001 From: Tom Hunze Date: Tue, 24 Sep 2024 15:32:23 +0200 Subject: [PATCH] community[patch]: Fix `tool_calls` parsing when streaming from DeepInfra `tool_calls` can also be `None`. --- libs/community/langchain_community/chat_models/deepinfra.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/chat_models/deepinfra.py b/libs/community/langchain_community/chat_models/deepinfra.py index 061bed9e8b0c7..71389cc2c901d 100644 --- a/libs/community/langchain_community/chat_models/deepinfra.py +++ b/libs/community/langchain_community/chat_models/deepinfra.py @@ -144,13 +144,12 @@ def _convert_delta_to_message_chunk( ) -> BaseMessageChunk: role = _dict.get("role") content = _dict.get("content") or "" + tool_calls = _dict.get("tool_calls") or [] if role == "user" or default_class == HumanMessageChunk: return HumanMessageChunk(content=content) elif role == "assistant" or default_class == AIMessageChunk: - tool_calls = [ - _parse_tool_calling(tool_call) for tool_call in _dict.get("tool_calls", []) - ] + tool_calls = [_parse_tool_calling(tool_call) for tool_call in tool_calls] return AIMessageChunk(content=content, tool_calls=tool_calls) elif role == "system" or default_class == SystemMessageChunk: return SystemMessageChunk(content=content)