Krista Pratico 2 weeks ago committed by GitHub
commit a2b43f8c50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

File diff suppressed because one or more lines are too long

@ -301,15 +301,13 @@
")\n",
"print(f\"Answer: {completion.choices[0].message.content}\")\n",
"\n",
"# prompt content filter result in \"model_extra\" for azure\n",
"prompt_filter_result = completion.model_extra[\"prompt_filter_results\"][0][\"content_filter_results\"]\n",
"prompt_filter_result = completion.prompt_filter_results[0][\"content_filter_results\"]\n",
"print(\"\\nPrompt content filter results:\")\n",
"for category, details in prompt_filter_result.items():\n",
" print(f\"{category}:\\n filtered={details['filtered']}\\n severity={details['severity']}\")\n",
"\n",
"# completion content filter result\n",
"print(\"\\nCompletion content filter results:\")\n",
"completion_filter_result = completion.choices[0].model_extra[\"content_filter_results\"]\n",
"completion_filter_result = completion.choices[0].content_filter_results\n",
"for category, details in completion_filter_result.items():\n",
" print(f\"{category}:\\n filtered={details['filtered']}\\n severity={details['severity']}\")"
]

@ -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 `dataSources`, 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_sources`, 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",
" \"dataSources\": [\n",
" \"data_sources\": [\n",
" {\n",
" \"type\": \"AzureCognitiveSearch\",\n",
" \"type\": \"azure_search\",\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",
" \"dataSources\": [\n",
" \"data_sources\": [\n",
" {\n",
" \"type\": \"AzureCognitiveSearch\",\n",
" \"type\": \"azure_search\",\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
},

Loading…
Cancel
Save