Math assistant does not solve

Hello. I use the provided code of assistant:

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-4-1106-preview”
)

thread = client.beta.threads.create()

message = client.beta.threads.messages.create(
thread_id=thread.id,
role=“user”,
content=“I need to solve the equation 2x + 1 = 5. 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
)

print(messages)

And i get the following messages:
yncCursorPage[ThreadMessage](data=[ThreadMessage(id=‘msg_t3xrZ6yy8LatnaFsoyRirTSv’, assistant_id=‘asst_KaUBITwyjYxN1OZSmKPWEDQy’, content=[MessageContentText(text=Text(annotations=, value=‘’), type=‘text’)], created_at=1699529380, file_ids=, metadata={}, object=‘thread.message’, role=‘assistant’, run_id=‘run_nVC6FRtTd4q6OWTnsLacQcwb’, thread_id=‘thread_jxqVr4ur7pnot4oKVux1dCzI’), ThreadMessage(id=‘msg_DHtscnuzwICQFMEt9fBxSPqV’, assistant_id=None, content=[MessageContentText(text=Text(annotations=, value=‘I need to solve the equation 2x + 1 = 5. Can you help me?’), type=‘text’)], created_at=1699529379, file_ids=, metadata={}, object=‘thread.message’, role=‘user’, run_id=None, thread_id=‘thread_jxqVr4ur7pnot4oKVux1dCzI’)], object=‘list’, first_id=‘msg_t3xrZ6yy8LatnaFsoyRirTSv’, last_id=‘msg_DHtscnuzwICQFMEt9fBxSPqV’, has_more=False)

Well, I do not get any solution to my problem. What I’m missing in my code?

1 Like

I think you have to check if run status is complete (or failed), for example

let runComplete = false;
while (!runComplete) {
  const runStatus = await openai.beta.threads.runs.retrieve(
    thread.id,
    run.id
  );
  runComplete = runStatus.status === "completed" || runStatus.status === "failed";
}

console.log("runComplete");

const messages = await openai.beta.threads.messages.list(
  thread.id,
  {}
);