Being able to reference attachments added to messages works sometimes.
Often, the assistant does not use the attachment when it’s at the message level at all which results in a rather poor experience for our end-users.
I am posting complete usage of files, messages, etc just in case someone has a suggestion. I think I have read every post on the forum with suggestions for better prompting, using filenames in the prompt, etc. But nothing has made this work reliably. Any help is greatly appreciated.
Here are the details
I am using both the file.filename and file.id, and prompting for retrieval and file_search as part of the additional_instructions that reads like this:
" Use
retrieval(akafile_search) to find documents with filename and file.id: {filenames_and_ids} as part of your response."
The instructions at the assistant level also contains this:
Use file_search to answer questions based on documents provided to you both in the primary vector store and any vector stores created for messages in given threads.
Files are created like this:
file = client.files.create(
file=(file_name, file_bytes),
purpose='assistants',
)
Messages are created with file_ids like this:
message_data = {
"thread_id": thread_id,
"role": "user",
"content": templated_content,
}
# Add attachments only if file_ids is not None and not empty
if len(file_ids) > 0:
message_data["attachments"] = [
{"file_id": file_id, "tools": [{"type": "file_search"}]} for file_id in file_ids
]
logger.info(f"message_data: {message_data}")
message = await client.beta.threads.messages.create(**message_data)
My create_stream_and_run call looks like this:
async with client.beta.threads.runs.create_and_stream(
thread_id=thread_id,
assistant_id=assistant_id,
instructions=instructions.safe_substitute(__formatted_time__=formatted_time),
additional_instructions=additional_instructions,
model="gpt-4o-mini",
tools=[
{
"type": "file_search"
}
]
) as stream: