Hello and thank you so much for looking at my question.
My issue is that I can not figure out how to get the assistant’s reply after created thread and run.
I tried mesage = client.beta.threads.messages.list("thread_id")
with thread_id is return after creating thread and run api call but I only get my message not the assistant reply.
I have checked the url “https://platform.openai.com/playground?thread=thread_id”
and there is assistant reply created so there is no error.
So please help me with this issue, how can I retrieve the reply programmatically?
Thank you so much.
Hello there!
Do you mind showing us what your code looks like so we can help you? My guess is you might be forgetting a print() somewhere, which outputs the captured response to the terminal.
Looks lke a basic question a long time before. Look deeper into the docs or search forum may help.
Did you check the run’s status you created in a while loop until it is completed(or failed/expired)?
Current assistant api flow need get run by run_id to check run status, after it become completed, message_list will show model response at the end.Don’t forget to sleep some interval when pulling your run status.
If you already waited for run status and still get nothing, you may need to check run status, if you receive ‘requires_action’, then you need to execute the function you declared(provided) to this assistant and submit result(it is YOU responsable for the actual funtion implementation) to the model(call run.submit_tool_outputs).
If you don’t completed the function execution and return the result, it will just get hanged there.
Thank you so much!
Here is my code:
from openai import OpenAI
OPENAI_API_KEY = "openai_key"
client = OpenAI(api_key=OPENAI_API_KEY)
new_thread = client.beta.threads.create()
thread_id = new_thread.id
thread_message = client.beta.threads.messages.create(
thread_id,
role="user",
content="my question?",
)
run = client.beta.threads.runs.create(
thread_id=thread_id,
assistant_id="assistant_id"
)
messages = client.beta.threads.messages.list(
thread_id=thread_id
)
print(messages.data[0].content[0].text.value)
Thank you so so much. You saved my life.
I put it in sleep after run and I have my result.
My issue is solved.