@Zandarashvili, Levani Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
.
I was able to make this work at my end. I used the below sample code for the client.files.create
:
# Import necessary libraries
from openai import AzureOpenAI
import os
# Initialize the Azure OpenAI client
client = AzureOpenAI(
api_key= "48bXXXXXXX3664",
api_version="2024-08-01-preview",
azure_endpoint = "https://XXXXX.openai.azure.com/"
)
# Create the assistant with the file_search tool
assistant = client.beta.assistants.create(
name="Financial Analyst Assistant",
instructions="You are an expert financial analyst. Use your knowledge base to answer questions about audited financial statements.",
model="gpt4o",
tools=[{"type": "file_search"}]
)
# Create a vector store called "Financial Statements"
vector_store = client.beta.vector_stores.create(name="Financial Statements")
# Ready the files for upload to OpenAI
file_paths = [r"C:\acs_paas\mydirectory\myfile1.pdf", r"C:\acs_paas\mydirectory\myfile2.pdf"]
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
)
# 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)
# Upload the user-provided file to OpenAI
message_file = client.files.create(
file=open(r"C:\acs_paas\mydirectory\myfile1.pdf", "rb"), purpose="assistants"
)
# Create a thread and attach the file to the message
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": "How many company shares were outstanding last quarter?",
# Attach the new file to the message
"attachments": [
{"file_id": message_file.id, "tools": [{"type": "file_search"}]}
],
}
]
)
# The thread now has a vector store with that file in its tool resources
print(thread.tool_resources.file_search)
vector_store_ids = thread.tool_resources.file_search.vector_store_ids
# Update the assistant with the correct vector_store_ids
assistant123 = client.beta.assistants.update(
assistant_id=assistant.id,
description="test",
instructions="You are an expert financial analyst. Use your knowledge base to answer questions about audited financial statements.",
tools=[{
"type": "file_search",
"file_search": {
"max_num_results": 5,
"ranking_options": {
"score_threshold": 0.6
}
}
}],
tool_resources={"file_search": {"vector_store_ids": vector_store_ids}},
temperature=0.00001,
model="gpt4o"
)
.
Action Plan:
- Try with api-version:
2024-08-01-preview
- Ensure that you have given the correct model name in your code.
- Try with my above sample and check if that helps.
.
Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help.