From f0e75bc6eacbc50b655c8b1404e70bf694e403c1 Mon Sep 17 00:00:00 2001 From: alisalim17 Date: Wed, 1 May 2024 15:54:17 +0400 Subject: [PATCH] fix conditional check for tool_calls in llm.py --- libs/superagent/app/agents/llm.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/superagent/app/agents/llm.py b/libs/superagent/app/agents/llm.py index d1c80cfb3..57600cd8e 100644 --- a/libs/superagent/app/agents/llm.py +++ b/libs/superagent/app/agents/llm.py @@ -261,7 +261,10 @@ async def _process_stream_response(self, res: CustomStreamWrapper): async for chunk in res: new_message = chunk.choices[0].delta - if new_message.tool_calls: + if ( + hasattr(new_message, "tool_calls") + and new_message.tool_calls is not None + ): new_tool_calls = self._process_tool_calls(new_message) tool_calls.extend(new_tool_calls) @@ -281,7 +284,7 @@ async def _process_model_response(self, res: ModelResponse): new_messages = self.messages new_message = res.choices[0].message - if new_message.tool_calls: + if hasattr(new_message, "tool_calls") and new_message.tool_calls is not None: new_tool_calls = self._process_tool_calls(new_message) tool_calls.extend(new_tool_calls)