No new message received after run completed

Hi, I am following the document to integrate assistant API, I have a problem to get Assistants reply:

From the document, the steps to build a assistant are:

  1. Create an Assistant in the API by defining its custom instructions and picking a model. If helpful, enable tools like Code Interpreter, Retrieval, and Function calling.
  2. Create a Thread when a user starts a conversation.
  3. Add Messages to the Thread as the user ask questions.
  4. Run the Assistant on the Thread to trigger responses. This automatically calls the relevant tools.

What I did it:
1: Upload files:

                file=open(os.path.join(file_dir, file), "rb"),

2: Create a new assistants with the file_ids got from step1:

assistant = get_openai_client().beta.assistants.create(
        name="Disclosure Gpt - 3.5 Turbo 1106",
        instructions="You are a real-estate agent, answer questions",
        tools=[{"type": "retrieval"}],

3: Create a thread:
thread_id = get_openai_client().beta.threads.create()

4: Create new message:

  message = get_openai_client().beta.threads.messages.create(

5: Create a run:

run = get_openai_client().beta.threads.runs.create(

6: Check run status, once completed, list all message:

if res.status == 'completed':
       messages = get_openai_client().beta.threads.messages.list(thread_id=thread_id)

I got messages from step6, but the last message is the one I created in step4, I didn’t get assistants response message, anything missing in my workflow??


When I test the assistants in playground, I could always get new message(assistants’ replies)

The code snippet says “res.status” and not “run.status”, not sure if that’s a typo. But the symptoms you describe sound like you’re retrieving the messages before the run has actually completed.

This is discussed in the related question Retriever Assistant API not giving answer but playground gives

I’d suggest copying their polling code. Also at the same time you’re displaying the messages, print(run) and look at resulting parameters like created_at, completed_at, status, thread_id, etc. for more clues.

1 Like