AzureOpenAI: BadRequestError: Unrecognized request argument supplied: dataSources

Sikder Tahsin Al Amin 155 Reputation points
2024-04-12T17:01:28.94+00:00

I'm trying Azure chat completion models with your own data using API key.

https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb

However, I am getting the following error on client.chat.completions.create()

BadRequestError: Error code: 400 - {'error': {'message': 'Unrecognized request argument supplied: dataSources', 'type': 'invalid_request_error', 'param': None, 'code': None}}

Below is the code and full error to reproduce:

  • OpenAI version: 1.2.0
completion = client.chat.completions.create(
    messages=[{"role": "user", "content": "What are the differences between Azure Machine Learning and Azure AI services?"}],
    model=AZURE_OPENAI_CHATGPT_MODEL,
    extra_body={
        "dataSources": [
            {
                "type": "AzureCognitiveSearch",
                "parameters": {
                    "endpoint": search_endpoint,
                    "key": search_key,
                    "indexName": index_name,
                }
            }
        ]
    }
)
print(f"{completion.choices[0].message.role}: {completion.choices[0].message.content}")

# `context` is in the model_extra for Azure
print(f"\nContext: {completion.choices[0].message.model_extra['context']['messages'][0]['content']}")

I'm getting the following error:

User's image

Any idea how to resolve this? I didn't find any proper documentation of client.chat.completions.create(). The one I found (https://autocode.com/openai/api/playground/0.1.1/chat-completions-create/) doesn't have extra_body{}as its parameters.

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

Accepted answer
  1. YutongTie-MSFT 46,991 Reputation points
    2024-04-12T22:58:25.7433333+00:00

    @Sikder Tahsin Al Amin Thanks for reaching out to us, as the confirmation the issue was caused by the sample.

    Below document works for the case - https://learn.microsoft.com/en-us/azure/ai-services/openai/references/on-your-data?tabs=python#examples

    Install the latest pip packages openai, azure-identity.

    import os
    from openai import AzureOpenAI
    from azure.identity import DefaultAzureCredential, get_bearer_token_provider
    endpoint = os.environ.get("AzureOpenAIEndpoint")
    deployment = os.environ.get("ChatCompletionsDeploymentName")
    search_endpoint = os.environ.get("SearchEndpoint")
    search_index = os.environ.get("SearchIndex")
    token_provider = get_bearer_token_provider(DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default")
    client = AzureOpenAI(
        azure_endpoint=endpoint,
        azure_ad_token_provider=token_provider,
        api_version="2024-02-01",
    )
    completion = client.chat.completions.create(
        model=deployment,
        messages=[
            {
                "role": "user",
                "content": "Who is DRI?",
            },
            {
                "role": "assistant",
                "content": "DRI stands for Directly Responsible Individual of a service. Which service are you asking about?"
            },
            {
                "role": "user",
                "content": "Opinion mining service"
            }
        ],
        extra_body={
            "data_sources": [
                {
                    "type": "azure_search",
                    "parameters": {
                        "endpoint": search_endpoint,
                        "index_name": search_index,
                        "authentication": {
                            "type": "system_assigned_managed_identity"
                        }
                    }
                }
            ]
        }
    )
    print(completion.model_dump_json(indent=2))
    

    Please take a look and see if the example works for you, I hope it helps!

    As Sikder mentioned, the main difference between the cook book and official document is need to change the name dataSources to data_sources and have authentication key inside parameters.

    Regards,

    Yutong

    -Please kindly accept the answer if you feel helpful to support the community, thanks a lot.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful