@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.