@Rakesh Amman I also tested it from my end and it worked just fine in East US region. I am sharing the sample code for your reference:
# Import necessary libraries
from openai import AzureOpenAI
import os
# Initialize the Azure OpenAI client
client = AzureOpenAI(
api_key= "48b4fXXXXXXXXX393664",
api_version="2024-05-01-preview",
azure_endpoint= "https://XXXXXXX.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 = ["mydirectory/myfile1.pdf", "mydirectory/myfile2.txt"]
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("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)