I have followed the OpenAI Assistant file search documentation very closely according to this link: https://platform.openai.com/docs/assistants/tools/file-search?context=without-streaming
This is how a glimpse of how my code looks like:
Create a vector store for resumes
vector_store = client.beta.vector_stores.create(name="Resumes")
# Ready the files for upload to OpenAI
file_paths = [file_path]
file_streams = [open(path, "rb") for path in file_paths]
# Use the upload and poll SDK helper to upload the files, add them to the vector store,
# and poll the status of the file batch for completion.
file_batch = client.beta.vector_stores.file_batches.upload_and_poll(
vector_store_id=vector_store.id, files=file_streams
)
# You can print the status and the file counts of the batch to see the result of this operation.
print(file_batch.status)
print(file_batch.file_counts)
# Updates assistant
client.beta.assistants.update(
assistant_id=assistant.id,
tool_resources={"file_search": {"vector_store_ids": [vector_store.id]}},
)
# Upload the user provided file to OpenAI
message_file = client.files.create(
file=open(file_path, "rb"), purpose="assistants"
)
# Create a thread and attach the file to the message (Thread no.of msgs = 1)
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": "Convert the content of the resume into JSON format with relevant headers.",
"attachments": [
{"file_id": message_file.id, "tools": [{"type": "file_search"}]}
],
}
]
)
# Poll for the thread run
run = client.beta.threads.runs.create_and_poll(
thread_id=thread.id, assistant_id=assistant.id
)
# Retrieve the messages from the run
messages = list(client.beta.threads.messages.list(thread_id=thread.id, run_id=run.id))
if not messages:
raise ValueError("No messages returned from the assistant")
if not messages[0].content:
raise ValueError("No content in the first message returned from the assistant")
if not messages[0].content[0].text:
raise ValueError("No text content in the first message content")
message_content = messages[0].content[0].text
print(message_content)
assistant_response = message_content.value
But it seems to continually say this:
An error occurred during file processing: No messages returned from the assistant
Traceback (most recent call last):
File “C:\Users\tooth\OneDrive - Temasek Polytechnic\TP Y3S1N2\Major Project\Codes\op.py”, line 172, in extract_data_from_file
raise ValueError(“No messages returned from the assistant”)
ValueError: No messages returned from the assistant
It was working 5-6hrs ago and even yesterday but now it seems there is a problem with the file search tool. Am I tripping?