Azure OpenAI Assistants file search tool - not working for azure gpt-4o.

Rakesh Amman 40 Reputation points
2024-07-25T08:25:30.8566667+00:00

I am trying to use Azure OpenAI Assistants file search tool using deployed gpt-4o model in azure but i do face below error, Error code: 400 - {'error': {'message': "Invalid value: 'file_search'. Supported values are: 'code_interpreter', 'function', and 'retrieval'.", 'type': 'invalid_request_error', 'param': 'tools[0].type', 'code': 'invalid_value'}}

But the same works if I directly use gpt-4o model from OpenAI instance.
What could be the solution for this?

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,059 questions
{count} votes

Accepted answer
  1. navba-MSFT 24,190 Reputation points Microsoft Employee
    2024-07-25T09:56:13.98+00:00

    @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)
    
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.