Skip to content

关于KeyError: 'tool_calls'的建议 #28

@Balmy-afterGlow

Description

@Balmy-afterGlow

@tjb-tech

File "/.../.../Auto-Deep-Research/autoagent/core.py", line 162, in get_chat_completion
converted_tool_calls = [ChatCompletionMessageToolCall(**tool_call) for tool_call in converted_message[0]["tool_calls"]]

KeyError: 'tool_calls'

You can add a layer of conditional judgment. Modify the get_chat_completion function in the core file (line 162) as follows:

converted_tool_calls = [ChatCompletionMessageToolCall(**tool_call) for tool_call in converted_message[0]["tool_calls"]]

change to:

if "tool_calls" in converted_message[0]:
    converted_tool_calls = [
        ChatCompletionMessageToolCall(**tool_call)
        for tool_call in converted_message[0]["tool_calls"]
    ]
else:
    converted_tool_calls = None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions