tool工具解析bug
bug已解决
问题描述 (Description)
在 tool_parser.py 的 extract_tool_calls 函数中,解析模型输出的 JSON 动作时,程序硬编码了使用 action["arguments"] 来获取工具参数。然而,部分模型或特定格式下,工具调用的参数键名可能是 parameters 而不是 arguments。当模型输出后者时,程序会抛出 KeyError: 'arguments' 异常并导致解析中断。
def extract_tool_calls(
self,
model_output: str,
tools,
) -> ExtractedToolCallInformation:
# ... 省略部分代码
for match_result in match_result_list:
index += 1
action = json.loads(match_result)
# 下面这一行在 action 包含 "parameters" 而非 "arguments" 时会崩溃
name, arguments = action["name"], json.dumps(
action["arguments"], ensure_ascii=False
)
2 条评论