diff --git a/examples/azure/archive/chat_with_your_own_data.ipynb b/examples/azure/archive/chat_with_your_own_data.ipynb index 1c8eca72..98d6a96c 100644 --- a/examples/azure/archive/chat_with_your_own_data.ipynb +++ b/examples/azure/archive/chat_with_your_own_data.ipynb @@ -93,14 +93,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "openai.api_base = os.environ[\"OPENAI_API_BASE\"]\n", "\n", - "# Azure OpenAI on your own data is only supported by the 2023-08-01-preview API version\n", - "openai.api_version = \"2023-08-01-preview\"" + "# Azure OpenAI on your own data is only supported by preview API versions\n", + "openai.api_version = \"2024-02-15-preview\"" ] }, { @@ -114,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -133,7 +133,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -241,113 +241,21 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "To chat with Azure OpenAI models using your own data with the Python SDK, we must first set up the code to target the chat completions extensions endpoint which is designed to work with your own data. To do this, we've created a convenience function that can be called to set a custom adapter for the library which will target the extensions endpoint for a given deployment ID." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "import requests\n", - "\n", - "def setup_byod(deployment_id: str) -> None:\n", - " \"\"\"Sets up the OpenAI Python SDK to use your own data for the chat endpoint.\n", - " \n", - " :param deployment_id: The deployment ID for the model to use with your own data.\n", - "\n", - " To remove this configuration, simply set openai.requestssession to None.\n", - " \"\"\"\n", - "\n", - " class BringYourOwnDataAdapter(requests.adapters.HTTPAdapter):\n", - "\n", - " def send(self, request, **kwargs):\n", - " request.url = f\"{openai.api_base}/openai/deployments/{deployment_id}/extensions/chat/completions?api-version={openai.api_version}\"\n", - " return super().send(request, **kwargs)\n", - "\n", - " session = requests.Session()\n", - "\n", - " # Mount a custom adapter which will use the extensions endpoint for any call using the given `deployment_id`\n", - " session.mount(\n", - " prefix=f\"{openai.api_base}/openai/deployments/{deployment_id}\",\n", - " adapter=BringYourOwnDataAdapter()\n", - " )\n", - "\n", - " if use_azure_active_directory:\n", - " session.auth = TokenRefresh(default_credential, [\"https://cognitiveservices.azure.com/.default\"])\n", - "\n", - " openai.requestssession = session\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we can call the convenience function to configure the SDK with the model we plan to use for our own data." + "Providing our search endpoint, key, and index name for the `data_sources` keyword argument, any questions posed to the model will now be grounded in our own data. An additional property, `context`, will be provided to show the data the model referenced to answer the question." ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "setup_byod(\"gpt-4\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Providing our search endpoint, key, and index name for the `dataSources` keyword argument, any questions posed to the model will now be grounded in our own data. An additional property, `context`, will be provided to show the data the model referenced to answer the question." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\n", - " \"id\": \"65b485bb-b3c9-48da-8b6f-7d3a219f0b40\",\n", - " \"model\": \"gpt-4\",\n", - " \"created\": 1693338769,\n", - " \"object\": \"extensions.chat.completion\",\n", - " \"choices\": [\n", - " {\n", - " \"index\": 0,\n", - " \"finish_reason\": \"stop\",\n", - " \"message\": {\n", - " \"role\": \"assistant\",\n", - " \"content\": \"Azure AI services and Azure Machine Learning (AML) both aim to apply artificial intelligence (AI) to enhance business operations, but they target different audiences and offer different capabilities [doc1]. \\n\\nAzure AI services are designed for developers without machine learning experience and provide pre-trained models to solve general problems such as text analysis, image recognition, and natural language processing [doc5]. These services require general knowledge about your data without needing experience with machine learning or data science and provide REST APIs and language-based SDKs [doc2].\\n\\nOn the other hand, Azure Machine Learning is tailored for data scientists and involves a longer process of data collection, cleaning, transformation, algorithm selection, model training, and deployment [doc5]. It allows users to create custom solutions for highly specialized and specific problems, requiring familiarity with the subject matter, data, and expertise in data science [doc5].\\n\\nIn summary, Azure AI services offer pre-trained models for developers without machine learning experience, while Azure Machine Learning is designed for data scientists to create custom solutions for specific problems.\",\n", - " \"end_turn\": true,\n", - " \"context\": {\n", - " \"messages\": [\n", - " {\n", - " \"role\": \"tool\",\n", - " \"content\": \"{\\\"citations\\\": [{\\\"content\\\": \\\"
Both have the end-goal of applying artificial intelligence (AI) to enhance business operations, though how each provides this in the respective offerings is different..
\\\\nGenerally, the audiences are different:
\\\\n\\\\n
\\\\nUse Azure AI services when you:
\\\\nUse other machine-learning solutions when you:
\\\\nMachine learning is a concept where you bring together data and an algorithm to solve a specific need..Once the data and algorithm are trained, the output is a model that you can use again with different data..The trained model provides insights based on the new data..
\\\\nThe process of building a machine learning system requires some knowledge of machine learning or data science..
\\\\nMachine learning is provided using Azure Machine Learning (AML) products and services..
\\\\nAn Azure AI service provides part or all of the components in a machine learning solution: data, algorithm, and trained model..These services are meant to require general knowledge about your data without needing experience with machine learning or data science..These services provide both REST API(s) and language-based SDKs..As a result, you need to have programming language knowledge to use the services..
\\\", \\\"id\\\": null, \\\"title\\\": \\\"Azure AI services and machine learning\\\", \\\"filepath\\\": \\\"cognitive-services-and-machine-learning.md\\\", \\\"url\\\": \\\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\\\", \\\"metadata\\\": {\\\"chunking\\\": \\\"orignal document size=1188. Scores=5.689296 and None.Org Highlight count=160.Filtering to chunk no. 1/Highlights=67 of size=506\\\"}, \\\"chunk_id\\\": \\\"1\\\"}, {\\\"content\\\": \\\"title: Azure AI services and Machine Learning\\\\ntitleSuffix: Azure AI services\\\\ndescription: Learn where Azure AI services fits in with other Azure offerings for machine learning.\\\\nservices: cognitive-services\\\\nmanager: nitinme\\\\nauthor: aahill\\\\nms.author: aahi\\\\nms.service: cognitive-services\\\\nms.topic: conceptual\\\\nms.date: 10/28/2021
\\\\nAzure AI services provides machine learning capabilities to solve general problems such as analyzing text for emotional sentiment or analyzing images to recognize objects or faces..You don't need special machine learning or data science knowledge to use these services../what-are-ai-services.md\\\\\\\">Azure AI services is a group of services, each supporting different, generalized prediction capabilities..The services are divided into different categories to help you find the right service..
\\\\nService category | \\\\nPurpose | \\\\n||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Decision | \\\\nBuild apps that surface recommendations for informed and efficient decision-making.. | \\\\n||||||||||||||||||||
Language | \\\\nAllow your apps to process natural language with pre-built scripts, evaluate sentiment and learn how to recognize what users want.. | \\\\n||||||||||||||||||||
Search | \\\\nAdd Bing Search APIs to your apps and harness the ability to comb billions of webpages, images, videos, and news with a single API call.. | \\\\n||||||||||||||||||||
Speech | \\\", \\\"id\\\": null, \\\"title\\\": \\\"Azure AI services and machine learning\\\", \\\"filepath\\\": \\\"cognitive-services-and-machine-learning.md\\\", \\\"url\\\": \\\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\\\", \\\"metadata\\\": {\\\"chunking\\\": \\\"orignal document size=1188. Scores=5.689296 and None.Org Highlight count=160.Filtering to chunk no. 0/Highlights=63 of size=526\\\"}, \\\"chunk_id\\\": \\\"0\\\"}, {\\\"content\\\": \\\"
Azure AI service | \\\\nModel information | \\\\n
---|---|
Custom Vision | \\\\nExport for Tensorflow for Android, CoreML for iOS11, ONNX for Windows ML | \\\\n
How are Azure AI services different from machine learning?.
\\\\nAzure AI services provide a trained model for you..This brings data and an algorithm together, available from a REST API(s) or SDK..An Azure AI service provides answers to general problems such as key phrases in text or item identification in images..
\\\\nMachine learning is a process that generally requires a longer period of time to implement successfully..This time is spent on data collection, cleaning, transformation, algorithm selection, model training, and deployment to get to the same level of functionality provided by an Azure AI service..With machine learning, it is possible to provide answers to highly specialized and/or specific problems..Machine learning problems require familiarity with the specific subject matter and data of the problem under consideration, as well as expertise in data science..
\\\\nAzure AI services, as a group of services, can require none, some, or all custom data for the trained model..
\\\\nServices that provide a fully-trained model can be treated as a opaque box..You don't need to know how they work or what data was used to train them..
\\\\nSome services allow you to bring your own data, then train a model..This allows you to extend the model using the Service's data and algorithm with your own data..The output matches your needs..When you bring your own data, you may need to tag the data in a way specific to the service..For example, if you are training a model to identify flowers, you can provide a catalog of flower images along with the location of the flower in each image to train the model..These services process significant amounts of model data..
\\\\nThe following data categorizes each service by which kind of data it allows or requires..
\\\\nAzure AI service | \\\\nNo training data required | \\\\nYou provide some or all training data | \\\\nReal-time or near real-time data collection | \\\\n
---|---|---|---|
Language Understanding (LUIS) | \\\\n\\\\n | x | \\\\n\\\\n |
Personalizer1 | \\\\nx | \\\\nx | \\\\nx | \\\\n
Vision | \\\\nx | \\\\n\\\\n | \\\\n |
1 Personalizer only needs training data collected by the service (as it operates in real-time) to evaluate your policy and data..
\\\\nThe services are used in any application that can make REST API(s) or SDK calls..Examples of applications include web sites, bots, virtual or mixed reality, desktop and mobile applications.\\\", \\\"id\\\": null, \\\"title\\\": \\\"Azure AI services and machine learning\\\", \\\"filepath\\\": \\\"cognitive-services-and-machine-learning.md\\\", \\\"url\\\": \\\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\\\", \\\"metadata\\\": {\\\"chunking\\\": \\\"orignal document size=1734. Scores=3.1447978 and None.Org Highlight count=66.Filtering to highlight size=891\\\"}, \\\"chunk_id\\\": \\\"4\\\"}], \\\"intent\\\": \\\"[\\\\\\\"What are the differences between Azure Machine Learning and Azure AI services?\\\\\\\"]\\\"}\",\n", - " \"end_turn\": false\n", - " }\n", - " ]\n", - " }\n", - " }\n", - " }\n", - " ]\n", - "}\n" - ] - } - ], "source": [ "completion = openai.ChatCompletion.create(\n", " messages=[{\"role\": \"user\", \"content\": \"What are the differences between Azure Machine Learning and Azure AI services?\"}],\n", " deployment_id=\"gpt-4\",\n", - " dataSources=[ # camelCase is intentional, as this is the format the API expects\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", @@ -368,39 +276,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Context: {\n", - " \"messages\": [\n", - " {\n", - " \"role\": \"tool\",\n", - " \"content\": \"{\\\"citations\\\":[{\\\"content\\\":\\\"
Both have the end-goal of applying artificial intelligence (AI) to enhance business operations, though how each provides this in the respective offerings is different..
\\\\nGenerally, the audiences are different:
\\\\nUse Azure AI services when you:
\\\\nUse other machine-learning solutions when you:
\\\\nMachine learning is a concept where you bring together data and an algorithm to solve a specific need..Once the data and algorithm are trained, the output is a model that you can use again with different data..The trained model provides insights based on the new data..
\\\\nThe process of building a machine learning system requires some knowledge of machine learning or data science..
\\\\nMachine learning is provided using Azure Machine Learning (AML) products and services..
\\\\nAn Azure AI service provides part or all of the components in a machine learning solution: data, algorithm, and trained model..These services are meant to require general knowledge about your data without needing experience with machine learning or data science..These services provide both REST API(s) and language-based SDKs..As a result, you need to have programming language knowledge to use the services..
\\\",\\\"id\\\":null,\\\"title\\\":\\\"Azure AI services and machine learning\\\",\\\"filepath\\\":\\\"cognitive-services-and-machine-learning.md\\\",\\\"url\\\":\\\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\\\",\\\"metadata\\\":{\\\"chunking\\\":\\\"orignal document size=1188. Scores=5.689296 and None.Org Highlight count=160.Filtering to chunk no. 1/Highlights=67 of size=506\\\"},\\\"chunk_id\\\":\\\"1\\\"},{\\\"content\\\":\\\"title: Azure AI services and Machine Learning\\\\ntitleSuffix: Azure AI services\\\\ndescription: Learn where Azure AI services fits in with other Azure offerings for machine learning.\\\\nservices: cognitive-services\\\\nmanager: nitinme\\\\nauthor: aahill\\\\nms.author: aahi\\\\nms.service: cognitive-services\\\\nms.topic: conceptual\\\\nms.date: 10/28/2021
\\\\nAzure AI services provides machine learning capabilities to solve general problems such as analyzing text for emotional sentiment or analyzing images to recognize objects or faces..You don't need special machine learning or data science knowledge to use these services../what-are-ai-services.md\\\\\\\">Azure AI services is a group of services, each supporting different, generalized prediction capabilities..The services are divided into different categories to help you find the right service..
\\\\nService category | \\\\nPurpose | \\\\n|||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Decision | \\\\nBuild apps that surface recommendations for informed and efficient decision-making.. | \\\\n|||||||||||||||||||
Language | \\\\nAllow your apps to process natural language with pre-built scripts, evaluate sentiment and learn how to recognize what users want.. | \\\\n|||||||||||||||||||
Search | \\\\nAdd Bing Search APIs to your apps and harness the ability to comb billions of webpages, images, videos, and news with a single API call.. | \\\\n|||||||||||||||||||
Speech | \\\",\\\"id\\\":null,\\\"title\\\":\\\"Azure AI services and machine learning\\\",\\\"filepath\\\":\\\"cognitive-services-and-machine-learning.md\\\",\\\"url\\\":\\\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\\\",\\\"metadata\\\":{\\\"chunking\\\":\\\"orignal document size=1188. Scores=5.689296 and None.Org Highlight count=160.Filtering to chunk no. 0/Highlights=63 of size=526\\\"},\\\"chunk_id\\\":\\\"0\\\"},{\\\"content\\\":\\\"
Azure AI service | \\\\nModel information | \\\\n
---|---|
Custom Vision | \\\\nExport for Tensorflow for Android, CoreML for iOS11, ONNX for Windows ML | \\\\n
How are Azure AI services different from machine learning?.
\\\\nAzure AI services provide a trained model for you..This brings data and an algorithm together, available from a REST API(s) or SDK..An Azure AI service provides answers to general problems such as key phrases in text or item identification in images..
\\\\nMachine learning is a process that generally requires a longer period of time to implement successfully..This time is spent on data collection, cleaning, transformation, algorithm selection, model training, and deployment to get to the same level of functionality provided by an Azure AI service..With machine learning, it is possible to provide answers to highly specialized and/or specific problems..Machine learning problems require familiarity with the specific subject matter and data of the problem under consideration, as well as expertise in data science..
\\\\nAzure AI services, as a group of services, can require none, some, or all custom data for the trained model..
\\\\nServices that provide a fully-trained model can be treated as a opaque box..You don't need to know how they work or what data was used to train them..
\\\\nSome services allow you to bring your own data, then train a model..This allows you to extend the model using the Service's data and algorithm with your own data..The output matches your needs..When you bring your own data, you may need to tag the data in a way specific to the service..For example, if you are training a model to identify flowers, you can provide a catalog of flower images along with the location of the flower in each image to train the model..These services process significant amounts of model data..
\\\\nThe following data categorizes each service by which kind of data it allows or requires..
\\\\nAzure AI service | \\\\nNo training data required | \\\\nYou provide some or all training data | \\\\nReal-time or near real-time data collection | \\\\n
---|---|---|---|
Language Understanding (LUIS) | \\\\n\\\\n | x | \\\\n\\\\n |
Personalizer1 | \\\\nx | \\\\nx | \\\\nx | \\\\n
Vision | \\\\nx | \\\\n\\\\n | \\\\n |
1 Personalizer only needs training data collected by the service (as it operates in real-time) to evaluate your policy and data..
\\\\nThe services are used in any application that can make REST API(s) or SDK calls..Examples of applications include web sites, bots, virtual or mixed reality, desktop and mobile applications.\\\",\\\"id\\\":null,\\\"title\\\":\\\"Azure AI services and machine learning\\\",\\\"filepath\\\":\\\"cognitive-services-and-machine-learning.md\\\",\\\"url\\\":\\\"https://krpraticstorageacc.blob.core.windows.net/azure-openai/cognitive-services-and-machine-learning.md\\\",\\\"metadata\\\":{\\\"chunking\\\":\\\"orignal document size=1734. Scores=3.1447978 and None.Org Highlight count=66.Filtering to highlight size=891\\\"},\\\"chunk_id\\\":\\\"4\\\"}],\\\"intent\\\":\\\"[\\\\\\\"What are the differences between Azure Machine Learning and Azure AI services?\\\\\\\"]\\\"}\",\n",
- " \"end_turn\": false\n",
- " }\n",
- " ]\n",
- "}\n",
- "assistant: Azure AI services and Azure Machine Learning (AML) both aim to apply artificial intelligence (AI) to enhance business operations, but they target different audiences and offer different capabilities [doc1]. \n",
- "\n",
- "Azure AI services are designed for developers without machine learning experience and provide pre-trained models to solve general problems such as text analysis, image recognition, and natural language processing [doc5]. These services require general knowledge about your data without needing experience with machine learning or data science and provide REST APIs and language-based SDKs [doc2].\n",
- "\n",
- "On the other hand, Azure Machine Learning is tailored for data scientists and offers a platform to build, train, and deploy custom machine learning models [doc1]. It requires knowledge of machine learning or data science and allows users to choose the algorithm and train on very specific data [doc2].\n",
- "\n",
- "In summary, Azure AI services offer pre-trained models for developers without machine learning experience, while Azure Machine Learning is a platform for data scientists to build and deploy custom machine learning models."
- ]
- }
- ],
+ "outputs": [],
"source": [
"response = openai.ChatCompletion.create(\n",
" messages=[{\"role\": \"user\", \"content\": \"What are the differences between Azure Machine Learning and Azure AI services?\"}],\n",
" deployment_id=\"gpt-4\",\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",
@@ -439,7 +324,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.10.0"
+ "version": "3.11.7"
},
"orig_nbformat": 4
},
diff --git a/examples/azure/chat.ipynb b/examples/azure/chat.ipynb
index d239e2ee..44905008 100644
--- a/examples/azure/chat.ipynb
+++ b/examples/azure/chat.ipynb
@@ -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']}\")"
]
diff --git a/examples/azure/chat_with_your_own_data.ipynb b/examples/azure/chat_with_your_own_data.ipynb
index 6f8b05fb..90d00b94 100644
--- a/examples/azure/chat_with_your_own_data.ipynb
+++ b/examples/azure/chat_with_your_own_data.ipynb
@@ -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 = \"