Share via

AzureOpenAI: BadRequestError: Unrecognized request argument supplied: dataSources

Anonymous
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 in Foundry Models

Answer accepted by question author

YutongTie-9091 54,021 Reputation points Moderator
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.

Was this answer helpful?

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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.