I am using the code below to build a simple Assistant that is capable of reading a pdf file attached as a part of a message thread. But this does not seem to work as even though the message_files object is being created it does not seem to get uploaded and I am unsure as for the cause of this since this is the code from the api documentation.
client = OpenAI()
assist_id='some id'
# Upload the user provided file to OpenAI
message_file = client.files.create(
file=open("./file.pdf", "rb"), purpose="assistants"
)
# Create a thread and attach the file to the message
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": "What is the highest value in the file?",
# Attach the new file to the message.
"attachments": [
{ "file_id": message_file.id, "tools": [{"type": "file_search"}] }
],
}
]
)
print(thread.tool_resources.file_search)
assistant_id=assist_id
thread_id= thread.id
run=client.beta.threads.runs.create(
thread_id=thread_id,
assistant_id=assistant_id,
instructions="Ensure to provide a simple response for the average person to be able to understand"
)
def wait_for_run(client,thread_id,run_id,sleep_interval=5):
while True:
try:
run=client.beta.threads.runs.retrieve(thread_id=thread_id,run_id=run_id)
if run.completed_at:
print(f"Run completed")
logging.info(f"Run completed")
message=client.beta.threads.messages.list(thread_id=thread_id)
last_message=message.data[0]
response=last_message.content[0].text.value
print(f"Assistants Response:{response}")
break
except Exception as e:
logging.error(f"AN error occured while retrieving the run:{e}")
break
logging.info("Waiting for run to complete....")
time.sleep(sleep_interval)
wait_for_run(client=client,thread_id=thread_id,run_id=run.id)
For more context I tried other methods like building vector stores but I only found examples where it was being uploaded to the assistant as a knowledge base I do not want that as the information being sent in a thread must be available only there and outside of the same thread should not be available.
I understand that there is some type of bug going around relating to this but I wish to get this operational so any and all help regarding this issue is much appreciated.