We’re using the Assistant API to create a special-purpose chat interface. We recently added the ability to attach files to the conversation, but we’re getting inconsistent and irregular results. Using the same assistant and uploaded file three times in a row, only one of the responses referenced the file content. One other response referred to a file that we don’t know anything about, and the other response just asked for more information.
From other questions here it seems like the file upload integration may still have some issues, but I wanted to see if anyone who’s encountered problems like this has a workaround. At first we thought there might be a race condition – like the system was processing the message before the files had been fully uploaded – but from checking my code it appears that the uploads all show state “processed” before we submit the user-entered message that refers to them.
Here’s the code we’re using:
attachments = []
for file in files:
message_file = self.openai_client.files.create(
file=(file.filename, file.stream), purpose="assistants"
)
attachments.append(
{"file_id": message_file.id, "tools": [{"type": "file_search"}]}
)
if not message:
message = "Here are the files to review."
try:
self.openai_client.beta.threads.messages.create(
thread_id=state.thread_id,
role="user",
content=message,
attachments=attachments,
)
except ...
...
Does this look okay?
Thanks in advance for any help or insight anyone can share!