openai.error.InvalidRequestError: Unrecognized request argument supplied: dataSources

David Yang 0 Reputation points
2023-11-27T08:29:10.3833333+00:00

I am trying to replicate the the add your own data feature for Azure Open AI following the instruction found here: Quickstart: Chat with Azure OpenAI models using your own data

import os
import openai
import dotenv
dotenv.load_dotenv()
endpoint = os.environ.get("AOAIEndpoint")
api_key = os.environ.get("AOAIKey")
deployment = "gpt-4-32k"
client = openai.AzureOpenAI(
    # base_url=f"{endpoint}/openai/deployments/{deployment}/extensions",
    azure_endpoint=endpoint,
    api_key=api_key,
    api_version="2023-08-01-preview",
)
completion = client.chat.completions.create(
    model=deployment,
    messages=[
        {
            "role": "user",
            "content": "My user query",
        },
    ],
    extra_body={
        "dataSources": [
            {
                "type": "AzureCognitiveSearch",
                "parameters": {
                    "endpoint": os.environ["SearchEndpoint"],
                    "key": os.environ["SearchKey"],
                    "indexName": os.environ["SearchIndex"]
                }
            }
        ]
    }
)
print(f"{completion.choices[0].message.role}: {completion.choices[0].message.content}")

However, I was not able to use the 'dataSources' parameter in the API call. I would get the following error: BadRequestError: Error code: 400 - {'error': {'message': 'Unrecognized request argument supplied: dataSources', 'type': 'invalid_request_error', 'param': None, 'code': None}}. If I were to use the base_url like the example, I would get an error: InternalServerError: upstream request timeout. Running the code with without the extra_body parameter would work just fine.

I am currently using the newest openai python library. I have also tried the example with openai==0.28.1 and I got the error: InvalidRequestError: Unrecognized request argument supplied: dataSources

I have look into the official github for OpenAI Python API library and it is not clear how I should implement the add your own data feature.

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