Error using tool for run run_Rxgzky62FkliPZQXiDNTUHu4: 'dict' object has no attribute 'output'

I’m getting the error in the title, I’m beginning to think it’s a bug in the library… I got openai version 1.59.7.

This is my code:

def handle_function_call(call, run, sender_id, thread_id):
    tool_output = ''
    if call.function.name == 'fetch_user_profile':
        logger.info(f'Calling fetch_user_profile with arguments: {sender_id}, {call.function.arguments}')
        tool_output = fetch_user_profile(sender_id, json.loads(call.function.arguments)['fields'])
        logger.info(f'fetch_user_profile response: {tool_output}')
    if tool_output:
        output_submission = ToolOutput()
        output_submission.output = tool_output
        output_submission.tool_call_id = call.id
        openai_api.beta.threads.runs.submit_tool_outputs(run_id=run.id, thread_id=thread_id,
                                                         tool_outputs=[output_submission])
    else:
        logger.error(f'Tool call {call} failed! Cancelling run for {sender_id}')
        openai_api.beta.threads.runs.cancel(run_id=run.id, thread_id=thread_id)

fetch_user_profile() returns an str like this one:

{'name': 'Piotr Kobus', 'picture': {'data': {'height': 50, 'is_silhouette': False, 'url': 'https://platform-lookaside.fbsbx.com/platform/profilepic/?eai=AXGq11wEYroQukqJwmT-S_Pl-bjs8b-e6ff-Awst51bFerXwH-k40y2rqq6nb0jbsRuoUNyK-5Tp&psid=9015655468510817&height=50&width=50&ext=1739871341&hash=AbagUiEtnY1zlE4h9fR1o6DR', 'width': 50}}, 'id': '9015655468510817'}

Welcome to the community, @kobiliusz!

Here are some recommendations from my side based on the docs:

  • Replace the ToolOutput() line and use a dictionary for tool_outputs.
if tool_output:
    output_submission = {
        "output": tool_output,
        "tool_call_id": call.id
    }
    openai_api.beta.threads.runs.submit_tool_outputs(
        run_id=run.id,
        thread_id=thread_id,
        tool_outputs=[output_submission]
    )
  • Ensure fetch_user_profile returns a string, not a dictionary. If it returns a dictionary, convert it to a string using json.dumps:
tool_output = json.dumps(fetch_user_profile(sender_id, json.loads(call.function.arguments)['fields']))
1 Like

OK, it works like that. So I guess the type declaration needs fixing.

Hi,

I’ve created a PR to update the type declaration for tool_outputs. You can check it out here: PR #2035.

Hope this helps!

1 Like

This topic was automatically closed after 15 hours. New replies are no longer allowed.