From 58f4fe402efd3ce542a3c62d7511586b5e34879d Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Fri, 5 Jul 2024 14:44:39 -0400 Subject: [PATCH] code review --- libs/core/langchain_core/messages/ai.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/libs/core/langchain_core/messages/ai.py b/libs/core/langchain_core/messages/ai.py index 9f23b1df95ec1..2c50f71b86a8f 100644 --- a/libs/core/langchain_core/messages/ai.py +++ b/libs/core/langchain_core/messages/ai.py @@ -241,7 +241,7 @@ def init_tool_calls(cls, values: dict) -> dict: invalid_tool_calls = [] for chunk in values["tool_call_chunks"]: try: - args_ = parse_partial_json(chunk["args"]) + args_ = parse_partial_json(chunk["args"]) if chunk["args"] != "" else {} if isinstance(args_, dict): tool_calls.append( ToolCall( @@ -253,23 +253,14 @@ def init_tool_calls(cls, values: dict) -> dict: else: raise ValueError("Malformed args.") except Exception: - if chunk["args"] == "": - tool_calls.append( - ToolCall( - name=chunk["name"] or "", - args={}, - id=chunk["id"], - ) - ) - else: - invalid_tool_calls.append( - InvalidToolCall( - name=chunk["name"], - args=chunk["args"], - id=chunk["id"], - error=None, - ) + invalid_tool_calls.append( + InvalidToolCall( + name=chunk["name"], + args=chunk["args"], + id=chunk["id"], + error=None, ) + ) values["tool_calls"] = tool_calls values["invalid_tool_calls"] = invalid_tool_calls return values