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:
- 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.
- Create a Thread when a user starts a conversation.
- Add Messages to the Thread as the user ask questions.
- Run the Assistant on the Thread to trigger responses. This automatically calls the relevant tools.
What I did it:
1: Upload files:
get_openai_client().files.create(
file=open(os.path.join(file_dir, file), "rb"),
purpose="assistants"
)
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"}],
file_ids=openai_file_ids,
model="gpt-3.5-turbo-1106"
)
3: Create a thread:
thread_id = get_openai_client().beta.threads.create()
4: Create new message:
message = get_openai_client().beta.threads.messages.create(
thread_id=thread_id,
role="user",
content=prompt,
)
5: Create a run:
run = get_openai_client().beta.threads.runs.create(
thread_id=thread_id,
assistant_id=assistant_id
)
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??
Thanks!
When I test the assistants in playground, I could always get new message(assistants’ replies)