Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion astrbot/core/provider/sources/anthropic_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ async def _query_stream(
try:
if "input_json" in tool_info:
tool_info["input"] = json.loads(tool_info["input_json"])
else:
tool_info["input"] = tool_info.get("input", {})
Comment on lines 422 to +425
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The else block here is redundant. tool_info is guaranteed to have an "input": {} entry from its initialization on line 377. If "input_json" is not present, the existing empty input dictionary is correctly used by the subsequent code. Adding an else block that re-assigns the same value makes the code more verbose and potentially confusing, as it implies the "input" key might be missing.

To improve clarity and remove the redundancy, the else block can be removed.

Suggested change
if "input_json" in tool_info:
tool_info["input"] = json.loads(tool_info["input_json"])
else:
tool_info["input"] = tool_info.get("input", {})
if "input_json" in tool_info:
tool_info["input"] = json.loads(tool_info["input_json"])


# 添加到最终结果
final_tool_calls.append(
Expand All @@ -442,7 +444,7 @@ async def _query_stream(
id=id,
)
except json.JSONDecodeError:
# JSON 解析失败,跳过这个工具调用
# JSON 解析失败,跳过这个工具调用,不 yield
logger.warning(f"工具调用参数 JSON 解析失败: {tool_info}")

# 清理缓冲区
Expand Down
Loading