@ -99,7 +99,7 @@
},
{
"cell_type": "code",
"execution_count": 2 ,
"execution_count": 3 ,
"metadata": {},
"outputs": [],
"source": [
@ -117,7 +117,7 @@
},
{
"cell_type": "code",
"execution_count": 3 ,
"execution_count": 4 ,
"metadata": {},
"outputs": [],
"source": [
@ -128,10 +128,10 @@
" deployment = \"<deployment-id-of-the-model-to-use>\"\n",
"\n",
" client = openai.AzureOpenAI(\n",
" base_url=f\"{endpoint}/openai/deployments/{deployment}/extensions\" ,\n",
" azure_endpoint=endpoint ,\n",
" api_key=api_key,\n",
" api_version=\"2023-09-01-preview \"\n",
" )"
" api_version=\"2024-02-01 \"\n",
" )\n "
]
},
{
@ -168,9 +168,9 @@
" deployment = \"<deployment-id-of-the-model-to-use>\"\n",
"\n",
" client = openai.AzureOpenAI(\n",
" base_url=f\"{endpoint}/openai/deployments/{deployment}/extensions\" ,\n",
" azure_endpoint=endpoint ,\n",
" azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n",
" api_version=\"2023-09-01-preview \"\n",
" api_version=\"2024-02-01 \"\n",
" )"
]
},
@ -218,7 +218,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can use Azure on your own data with Chat Completions. Providing our search endpoint, key, and index name in `dataS ources`, any questions posed to the model will now be grounded in our own data. An additional property, `context`, will be provided in the response to show the data the model referenced to answer the question."
"Now we can use Azure on your own data with Chat Completions. Providing our search endpoint, key, and index name in `data_s ources`, any questions posed to the model will now be grounded in our own data. An additional property, `context`, will be provided in the response to show the data the model referenced to answer the question."
]
},
{
@ -231,13 +231,16 @@
" messages=[{\"role\": \"user\", \"content\": \"What are the differences between Azure Machine Learning and Azure AI services?\"}],\n",
" model=deployment,\n",
" extra_body={\n",
" \"dataS ources\": [\n",
" \"data_s ources\": [\n",
" {\n",
" \"type\": \"AzureCognitiveS earch\",\n",
" \"type\": \"azure_s earch\",\n",
" \"parameters\": {\n",
" \"endpoint\": os.environ[\"SEARCH_ENDPOINT\"],\n",
" \"key\": os.environ[\"SEARCH_KEY\"],\n",
" \"indexName\": os.environ[\"SEARCH_INDEX_NAME\"],\n",
" \"index_name\": os.environ[\"SEARCH_INDEX_NAME\"],\n",
" \"authentication\": {\n",
" \"type\": \"api_key\",\n",
" \"key\": os.environ[\"SEARCH_KEY\"],\n",
" }\n",
" }\n",
" }\n",
" ]\n",
@ -245,8 +248,7 @@
")\n",
"print(f\"{completion.choices[0].message.role}: {completion.choices[0].message.content}\")\n",
"\n",
"# `context` is in the model_extra for Azure\n",
"print(f\"\\nContext: {completion.choices[0].message.model_extra['context']['messages'][0]['content']}\")"
"print(f\"\\nContext: {completion.choices[0].message.context}\")"
]
},
{
@ -266,13 +268,16 @@
" messages=[{\"role\": \"user\", \"content\": \"What are the differences between Azure Machine Learning and Azure AI services?\"}],\n",
" model=deployment,\n",
" extra_body={\n",
" \"dataS ources\": [\n",
" \"data_s ources\": [\n",
" {\n",
" \"type\": \"AzureCognitiveS earch\",\n",
" \"type\": \"azure_s earch\",\n",
" \"parameters\": {\n",
" \"endpoint\": os.environ[\"SEARCH_ENDPOINT\"],\n",
" \"key\": os.environ[\"SEARCH_KEY\"],\n",
" \"indexName\": os.environ[\"SEARCH_INDEX_NAME\"],\n",
" \"index_name\": os.environ[\"SEARCH_INDEX_NAME\"],\n",
" \"authentication\": {\n",
" \"type\": \"api_key\",\n",
" \"key\": os.environ[\"SEARCH_KEY\"],\n",
" }\n",
" }\n",
" }\n",
" ]\n",
@ -287,8 +292,10 @@
" print(\"\\n\"+ delta.role + \": \", end=\"\", flush=True)\n",
" if delta.content:\n",
" print(delta.content, end=\"\", flush=True)\n",
" if delta.model_extra.get(\"context\"):\n",
" print(f\"Context: {delta.model_extra['context']}\", end=\"\", flush=True)"
" if hasattr(delta, \"context\"):\n",
" context = delta.context\n",
"\n",
"print(f\"\\nContext: {context}\")"
]
}
],
@ -308,7 +315,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0 "
"version": "3.11.7 "
},
"orig_nbformat": 4
},