I copied codes from https://platform.openai.com/docs/assistants/overview
finally, the message.data 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"}],
model="gpt-3.5-turbo-1106"
)
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": "I need to solve the equation `3x + 11 = 14`. Can you help me?"
}
]
)
run = client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id,
instructions="Please address the user as Jane Doe. The user has a premium account."
)
run = client.beta.threads.runs.retrieve(
thread_id=thread.id,
run_id=run.id
)
messages = client.beta.threads.messages.list(
thread_id=thread.id
)
the message.data[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.