from openai import OpenAI
client = OpenAI(
organization=<org>,
api_key=<api_key>
)
# Upload a file with an "assistants" purpose
file = client.files.create(
file=open("filename.txt", "rb"),
purpose='assistants'
)
# Add the file to the assistant
assistant = client.beta.assistants.create(
instructions="You are a customer support chatbot. Use your knowledge base to best respond to customer queries.",
model="gpt-4-1106-preview",
tools=[{"type": "retrieval"}],
file_ids=[file.id]
)
thread = client.beta.threads.create()
message = client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content=<User question>
file_ids=[file.id]
)
run = client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id,
instructions="Address user as <User name>"
)
messages = client.beta.threads.messages.list(
thread_id=thread.id
)
print(messages)
The above code uploads file. Also registers the user question but when I print messages the assistant has not given any reply. What am I doing wrong ?
How to do that ? I tried putting ārunā into a while loop that finished once run.status does not equal iin_progress. But it immediately, exits the loop and the status is still āin_progressā
I think while run.status != 'completed':
should be: while run.status in ['queued', 'in_progress']:
Since a run could be cancelled or failed or expired. if like that program will never get out of while loop.