Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme committed Jul 5, 2024
1 parent efb9578 commit 58f4fe4
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions libs/core/langchain_core/messages/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 58f4fe4

Please sign in to comment.