No answer message with openai assistants api

Try adding a wait in there, the run command is asynchronous so need to wait for the AI to process the input

import time

def wait_on_run(run, thread):
    while run.status == "queued" or run.status == "in_progress":
        run = client.beta.threads.runs.retrieve(
            thread_id=thread.id,
            run_id=run.id,
        )
        time.sleep(0.5)
    return run

Take a look at Assistants API Overview (Python SDK) | OpenAI Cookbook for the full guide

2 Likes