Assistant api message no answer only question

I copied codes from

finally, the has one element only, that is question, none of the anwser!

from openai import OpenAI

client = OpenAI()

assistant = client.beta.assistants.create(
    name="Math Tutor",
    instructions="You are a personal math tutor. Write and run code to answer math questions.",
    tools=[{"type": "code_interpreter"}],
thread = client.beta.threads.create(
      "role": "user",
      "content": "I need to solve the equation `3x + 11 = 14`. Can you help me?"
run = client.beta.threads.runs.create(,,
  instructions="Please address the user as Jane Doe. The user has a premium account."
run = client.beta.threads.runs.retrieve(,
messages = client.beta.threads.messages.list(

the[0] is
“I need to solve the equation 3x + 11 = 14. Can you help me?”

but if I write codes in ipynb file, run code one by one, I can got the correct message
‘The solution to the equation 3x + 11 = 14 is x = 1.’

In my opinion, maybe thread need wait.

First, you can only provide one instruction, which has all that you want the AI to know. The instruction provided with “run” will overwrite the one with “assistant”.

Second, you must continue to check the status of the run to finally get an answer after the AI has been writing (or retrieving or coding) and is finished. A script that immediately checks just once isn’t enough waiting.


thanks, but the code that I writed is copied from official website, both assistant and run has the instruction. is there error with official website?

I had browsed all of the document, likely the run not have event or callback. so I how to check the status of run? is need to use loop & break?

There is an error with that usage from the official website. They are completely changing the operation of the assistant with the overwrite.

A math tutor submitted to OpenAI by third party without that error Assistants API Overview (Python SDK) | OpenAI Cookbook

You can go to “list runs” in the API reference to get the status, and discover the run object data.

1 Like

thanks for a lot :100:
I’ll modify my code right now