From 71656090300cf23cc5fdfb22620ebfa793748b7f Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Fri, 16 Dec 2022 11:48:32 +0100 Subject: [PATCH 01/10] Update embeddings notebook * Update api_version to 2022-12-01 * Fix some texts --- examples/azure/embeddings.ipynb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/examples/azure/embeddings.ipynb b/examples/azure/embeddings.ipynb index 6b78113..3e99f11 100644 --- a/examples/azure/embeddings.ipynb +++ b/examples/azure/embeddings.ipynb @@ -6,7 +6,7 @@ "source": [ "# Azure embeddings example\n", "In this example we'll try to go over all operations for embeddings that can be done using the Azure endpoints. \\\n", - "This example focuses on finetuning but touches on the majority of operations that are also available using the API. This example is meant to be a quick way of showing simple operations and is not meant as a tutorial." + "This example focuses on embeddings but also touches on the some other operations that are also available using the API. This example is meant to be a quick way of showing simple operations and is not meant as a tutorial." ] }, { @@ -38,7 +38,7 @@ "openai.api_base = '' # Please add your endpoint here\n", "\n", "openai.api_type = 'azure'\n", - "openai.api_version = '2022-03-01-preview' # this may change in the future" + "openai.api_version = '2022-12-01' # this may change in the future" ] }, { @@ -46,7 +46,7 @@ "metadata": {}, "source": [ "## Deployments\n", - "In this section we are going to create a deployment using the finetune model that we just adapted and then used the deployment to create a simple completion operation." + "In this section we are going to create a deployment that we can use to create embeddings." ] }, { @@ -54,7 +54,7 @@ "metadata": {}, "source": [ "### Deployments: Create Manually\n", - "Let's create a deployment using the text-similarity-curie-001 engine. You can create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Deployments\"." + "Let's create a deployment using the `text-similarity-curie-001` engine. Create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Deployments\"." ] }, { @@ -113,18 +113,24 @@ "metadata": {}, "outputs": [], "source": [ - "print('While deployment running, selecting a completed one.')\n", + "print('While deployment running, selecting a completed one that supports embeddings.')\n", "deployment_id = None\n", "result = openai.Deployment.list()\n", "for deployment in result.data:\n", - " if deployment[\"status\"] == \"succeeded\":\n", - " deployment_id = deployment[\"id\"]\n", - " break\n", + " if deployment[\"status\"] != \"succeeded\":\n", + " continue\n", + " \n", + " model = openai.Model.retrieve(deployment[\"model\"])\n", + " if model[\"capabilities\"][\"embeddings\"] != True:\n", + " continue\n", + " \n", + " deployment_id = deployment[\"id\"]\n", + " break\n", "\n", "if not deployment_id:\n", " print('No deployment with status: succeeded found.')\n", "else:\n", - " print(f'Found a successful deployment with id: {deployment_id}.')" + " print(f'Found a succeeded deployment that supports embeddings with id: {deployment_id}.')" ] }, { From 918c497ecd5e1bce0e1d4d52a41311a9697dda5c Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Fri, 16 Dec 2022 12:19:34 +0100 Subject: [PATCH 02/10] Fix finetuning example --- examples/azure/finetuning.ipynb | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/examples/azure/finetuning.ipynb b/examples/azure/finetuning.ipynb index 1692b42..0a538d5 100644 --- a/examples/azure/finetuning.ipynb +++ b/examples/azure/finetuning.ipynb @@ -37,7 +37,7 @@ "openai.api_base = '' # Please add your endpoint here\n", "\n", "openai.api_type = 'azure'\n", - "openai.api_version = '2022-03-01-preview' # this may change in the future" + "openai.api_version = '2022-12-01'" ] }, { @@ -89,9 +89,9 @@ "training_file_name = 'training.jsonl'\n", "validation_file_name = 'validation.jsonl'\n", "\n", - "sample_data = [{\"prompt\": \"When I go to the store, I want an\", \"completion\": \"apple\"},\n", - " {\"prompt\": \"When I go to work, I want a\", \"completion\": \"coffe\"},\n", - " {\"prompt\": \"When I go home, I want a\", \"completion\": \"soda\"}]\n", + "sample_data = [{\"prompt\": \"When I go to the store, I want an\", \"completion\": \"apple.\"},\n", + " {\"prompt\": \"When I go to work, I want a\", \"completion\": \"coffee.\"},\n", + " {\"prompt\": \"When I go home, I want a\", \"completion\": \"soda.\"}]\n", "\n", "print(f'Generating the training file: {training_file_name}')\n", "with open(training_file_name, 'w') as training_file:\n", @@ -141,7 +141,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(f'Deleting already uploaded files.')\n", + "print(f'Deleting already uploaded files...')\n", "for id in results:\n", " openai.File.delete(sid = id)\n" ] @@ -197,7 +197,7 @@ "source": [ "print(f'Downloading training file: {training_id}')\n", "result = openai.File.download(training_id)\n", - "print(result)" + "print(result.decode('utf-8'))" ] }, { @@ -225,9 +225,12 @@ "create_args = {\n", " \"training_file\": training_id,\n", " \"validation_file\": validation_id,\n", - " \"model\": \"curie\",\n", + " \"model\": \"babbage\",\n", " \"compute_classification_metrics\": True,\n", - " \"classification_n_classes\": 3\n", + " \"classification_n_classes\": 3,\n", + " \"n_epochs\": 20,\n", + " \"batch_size\": 3,\n", + " \"learning_rate_multiplier\": 0.3\n", "}\n", "resp = openai.FineTune.create(**create_args)\n", "job_id = resp[\"id\"]\n", @@ -258,7 +261,7 @@ " print(f\"Stream interrupted. Job is still {status}.\")\n", " return\n", "\n", - "print('Streaming events for the fine-tuning job: {job_id}')\n", + "print(f'Streaming events for the fine-tuning job: {job_id}')\n", "signal.signal(signal.SIGINT, signal_handler)\n", "\n", "events = openai.FineTune.stream_events(job_id)\n", @@ -296,7 +299,7 @@ "\n", "print('Checking other finetune jobs in the subscription.')\n", "result = openai.FineTune.list()\n", - "print(f'Found {len(result)} finetune jobs.')" + "print(f'Found {len(result.data)} finetune jobs.')" ] }, { @@ -413,10 +416,10 @@ "outputs": [], "source": [ "print('Sending a test completion job')\n", - "start_phrase = 'When I go to the store, I want a'\n", - "response = openai.Completion.create(deployment_id=deployment_id, prompt=start_phrase, max_tokens=4)\n", + "start_phrase = 'When I go home, I want a'\n", + "response = openai.Completion.create(deployment_id=deployment_id, prompt=start_phrase, temperature=0, stop=\".\")\n", "text = response['choices'][0]['text'].replace('\\n', '').replace(' .', '.').strip()\n", - "print(f'\"{start_phrase} {text}\"')\n" + "print(f'\"{start_phrase} {text}.\"')" ] }, { From 3eee35e24ff67184fd1866a4960558fe7adbeb82 Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Fri, 16 Dec 2022 12:34:49 +0100 Subject: [PATCH 03/10] Simple example just for completions with davinci --- examples/azure/completions.ipynb | 218 +++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 examples/azure/completions.ipynb diff --git a/examples/azure/completions.ipynb b/examples/azure/completions.ipynb new file mode 100644 index 0000000..5e67466 --- /dev/null +++ b/examples/azure/completions.ipynb @@ -0,0 +1,218 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Azure completions example\n", + "In this example we'll try to go over all operations needed to get completions working using the Azure endpoints. \\\n", + "This example focuses on completions but also touches on the some other operations that are also available using the API. This example is meant to be a quick way of showing simple operations and is not meant as a tutorial." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import openai\n", + "from openai import cli" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup\n", + "For the following sections to work properly we first have to setup some things. Let's start with the `api_type`, `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "openai.api_type = 'azure'\n", + "openai.api_version = '2022-12-01'\n", + "\n", + "openai.api_base = '' # Please add your endpoint here" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We next have to setup the `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Setup: Portal\n", + "Let's first look at getting the key from the portal. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for one of the \"Keys\" values." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "openai.api_key = '' # Please add your api key here" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### (Optional) Setup: Microsoft Active Directory Authentication\n", + "Let's now see how we can get a key via Microsoft Active Directory Authentication." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "from azure.identity import DefaultAzureCredential\n", + "\n", + "default_credential = DefaultAzureCredential()\n", + "token = default_credential.get_token(\"https://cognitiveservices.azure.com\")\n", + "\n", + "openai.api_key = token.token\n", + "\"\"\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Deployments\n", + "In this section we are going to create a deployment using the `text-davinci-002` model that we can use to create completions." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Deployments: Create Manually\n", + "Create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Model deployments\". Select `text-davinci-002` as the model." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### (Optional) Deployments: Create Programatically\n", + "We can also create a deployment using code:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "model = \"text-davinci-002\"\n", + "\n", + "# Now let's create the deployment\n", + "print(f'Creating a new deployment with model: {model}')\n", + "result = openai.Deployment.create(model=model, scale_settings={\"scale_type\":\"standard\"})\n", + "deployment_id = result[\"id\"]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### (Optional) Deployments: Wait for deployment to succeed\n", + "Now let's check the status of the newly created deployment and wait till it is succeeded." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(f'Checking for deployment status.')\n", + "resp = openai.Deployment.retrieve(id=deployment_id)\n", + "status = resp[\"status\"]\n", + "print(f'Deployment {deployment_id} has status: {status}')\n", + "while status not in [\"succeeded\", \"failed\"]:\n", + " resp = openai.Deployment.retrieve(id=deployment_id)\n", + " status = resp[\"status\"]\n", + " print(f'Deployment {deployment_id} has status: {status}')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Completions\n", + "Now let's send a sample completion to the deployment." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "prompt = \"The food was delicious and the waiter\"\n", + "completion = openai.Completion.create(deployment_id=deployment_id,\n", + " prompt=prompt, stop=\".\", temperature=0)\n", + " \n", + "print(f\"{prompt}{completion['choices'][0]['text']}.\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### (Optional) Deployments: Delete\n", + "Finally let's delete the deployment" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(f'Deleting deployment: {deployment_id}')\n", + "openai.Deployment.delete(sid=deployment_id)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.8" + }, + "vscode": { + "interpreter": { + "hash": "3a5103089ab7e7c666b279eeded403fcec76de49a40685dbdfe9f9c78ad97c17" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 7ce4de8467eb58822446f013bb4be2cabcf7193a Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Fri, 16 Dec 2022 16:43:18 +0100 Subject: [PATCH 04/10] Update metadata of azure notebooks --- examples/azure/completions.ipynb | 4 ++-- examples/azure/embeddings.ipynb | 5 ++--- examples/azure/finetuning.ipynb | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/azure/completions.ipynb b/examples/azure/completions.ipynb index 5e67466..a2baf40 100644 --- a/examples/azure/completions.ipynb +++ b/examples/azure/completions.ipynb @@ -191,7 +191,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -205,7 +205,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.8.10" }, "vscode": { "interpreter": { diff --git a/examples/azure/embeddings.ipynb b/examples/azure/embeddings.ipynb index 3e99f11..761dd32 100644 --- a/examples/azure/embeddings.ipynb +++ b/examples/azure/embeddings.ipynb @@ -174,7 +174,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.9.9 ('openai')", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -188,9 +188,8 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.9" + "version": "3.8.10" }, - "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "365536dcbde60510dc9073d6b991cd35db2d9bac356a11f5b64279a5e6708b97" diff --git a/examples/azure/finetuning.ipynb b/examples/azure/finetuning.ipynb index 0a538d5..23efca1 100644 --- a/examples/azure/finetuning.ipynb +++ b/examples/azure/finetuning.ipynb @@ -450,7 +450,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.9.9 64-bit ('3.9.9')", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -464,9 +464,8 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.9" + "version": "3.8.10" }, - "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "cb9817b186a29e4e9713184d901f26c1ee05ad25243d878baff7f31bb1fef480" From 53a989113321d69812a5509cb4d212b3bc900f0c Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Mon, 19 Dec 2022 09:17:29 +0100 Subject: [PATCH 05/10] Fix completions notebook --- examples/azure/completions.ipynb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/azure/completions.ipynb b/examples/azure/completions.ipynb index a2baf40..f5ba33b 100644 --- a/examples/azure/completions.ipynb +++ b/examples/azure/completions.ipynb @@ -6,7 +6,7 @@ "source": [ "# Azure completions example\n", "In this example we'll try to go over all operations needed to get completions working using the Azure endpoints. \\\n", - "This example focuses on completions but also touches on the some other operations that are also available using the API. This example is meant to be a quick way of showing simple operations and is not meant as a tutorial." + "This example focuses on completions but also touches on some other operations that are also available using the API. This example is meant to be a quick way of showing simple operations and is not meant as a tutorial." ] }, { @@ -81,33 +81,36 @@ "from azure.identity import DefaultAzureCredential\n", "\n", "default_credential = DefaultAzureCredential()\n", - "token = default_credential.get_token(\"https://cognitiveservices.azure.com\")\n", + "token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", "\n", "openai.api_key = token.token\n", "\"\"\"" ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Deployments\n", - "In this section we are going to create a deployment using the `text-davinci-002` model that we can use to create completions." + "In this section we are going to create a deployment using the `text-davinci-002` model that we can then use to create completions." ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "### Deployments: Create Manually\n", + "### Deployments: Create manually\n", "Create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Model deployments\". Select `text-davinci-002` as the model." ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "### (Optional) Deployments: Create Programatically\n", + "### (Optional) Deployments: Create programatically\n", "We can also create a deployment using code:" ] }, @@ -122,7 +125,8 @@ "# Now let's create the deployment\n", "print(f'Creating a new deployment with model: {model}')\n", "result = openai.Deployment.create(model=model, scale_settings={\"scale_type\":\"standard\"})\n", - "deployment_id = result[\"id\"]" + "deployment_id = result[\"id\"]\n", + "print(f'Successfully created deployment with id: {deployment_id}')" ] }, { @@ -205,7 +209,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.10.8" }, "vscode": { "interpreter": { From ca628a18be465df68b5fcd50c72ca19115958384 Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Mon, 19 Dec 2022 10:25:32 +0100 Subject: [PATCH 06/10] Add ad auth to embeddings example --- examples/azure/embeddings.ipynb | 73 +++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/examples/azure/embeddings.ipynb b/examples/azure/embeddings.ipynb index 761dd32..9715821 100644 --- a/examples/azure/embeddings.ipynb +++ b/examples/azure/embeddings.ipynb @@ -24,8 +24,7 @@ "metadata": {}, "source": [ "## Setup\n", - "In the following section the endpoint and key need to be set up of the next sections to work. \\\n", - "Please go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value and one of the Keys. They will act as api_base and api_key in the code below." + "For the following sections to work properly we first have to setup some things. Let's start with the `api_type`, `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value." ] }, { @@ -34,11 +33,61 @@ "metadata": {}, "outputs": [], "source": [ - "openai.api_key = '' # Please add your api key here\n", - "openai.api_base = '' # Please add your endpoint here\n", - "\n", "openai.api_type = 'azure'\n", - "openai.api_version = '2022-12-01' # this may change in the future" + "openai.api_version = '2022-12-01'\n", + "\n", + "openai.api_base = '' # Please add your endpoint here" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We next have to setup the `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication." + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Setup: Portal\n", + "Let's first look at getting the key from the portal. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for one of the \"Keys\" values." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "openai.api_key = '' # Please add your api key here" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### (Optional) Setup: Microsoft Active Directory Authentication\n", + "Let's now see how we can get a key via Microsoft Active Directory Authentication." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "from azure.identity import DefaultAzureCredential\n", + "\n", + "default_credential = DefaultAzureCredential()\n", + "token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", + "\n", + "openai.api_key = token.token\n", + "\"\"\"" ] }, { @@ -53,15 +102,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Deployments: Create Manually\n", - "Let's create a deployment using the `text-similarity-curie-001` engine. Create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Deployments\"." + "### Deployments: Create manually\n", + "Let's create a deployment using the `text-similarity-curie-001` model. Create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Model deployments\"." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### (Optional) Deployments: Create Programatically\n", + "### (Optional) Deployments: Create programatically\n", "We can also create a deployment using code:" ] }, @@ -174,7 +223,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -188,11 +237,11 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.10.8" }, "vscode": { "interpreter": { - "hash": "365536dcbde60510dc9073d6b991cd35db2d9bac356a11f5b64279a5e6708b97" + "hash": "3a5103089ab7e7c666b279eeded403fcec76de49a40685dbdfe9f9c78ad97c17" } } }, From 3708c288340a95b6ab9c3cf8a3475cd68a802412 Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Mon, 19 Dec 2022 10:40:02 +0100 Subject: [PATCH 07/10] Adjust finetuning setup section --- examples/azure/finetuning.ipynb | 49 +++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/examples/azure/finetuning.ipynb b/examples/azure/finetuning.ipynb index 23efca1..171863b 100644 --- a/examples/azure/finetuning.ipynb +++ b/examples/azure/finetuning.ipynb @@ -24,7 +24,7 @@ "metadata": {}, "source": [ "## Setup\n", - "In the following section the endpoint and key need to be set up of the next sections to work.
Please go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value and one of the Keys. They will act as api_base and api_key in the code below." + "For the following sections to work properly we first have to setup some things. Let's start with the `api_type`, `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value." ] }, { @@ -33,19 +33,43 @@ "metadata": {}, "outputs": [], "source": [ - "openai.api_key = '' # Please add your api key here\n", - "openai.api_base = '' # Please add your endpoint here\n", - "\n", "openai.api_type = 'azure'\n", - "openai.api_version = '2022-12-01'" + "openai.api_version = '2022-12-01'\n", + "\n", + "openai.api_base = '' # Please add your endpoint here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Microsoft Active Directory Authentication\n", - "Instead of key based authentication, you can use Active Directory to authenticate using credential tokens. Uncomment the next code section to use credential based authentication:" + "We next have to setup the `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Setup: Portal\n", + "Let's first look at getting the key from the portal. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for one of the \"Keys\" values." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "openai.api_key = '' # Please add your api key here" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### (Optional) Setup: Microsoft Active Directory Authentication\n", + "Let's now see how we can get a key via Microsoft Active Directory Authentication." ] }, { @@ -60,12 +84,7 @@ "default_credential = DefaultAzureCredential()\n", "token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", "\n", - "openai.api_type = 'azure_ad'\n", "openai.api_key = token.token\n", - "openai.api_version = '2022-03-01-preview' # this may change in the future\n", - "\n", - "\n", - "openai.api_base = '' # Please add your endpoint here\n", "\"\"\"" ] }, @@ -450,7 +469,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -464,11 +483,11 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.10.8" }, "vscode": { "interpreter": { - "hash": "cb9817b186a29e4e9713184d901f26c1ee05ad25243d878baff7f31bb1fef480" + "hash": "3a5103089ab7e7c666b279eeded403fcec76de49a40685dbdfe9f9c78ad97c17" } } }, From 9b3fd89a26b0810bf08828748b57e60dcb9522d9 Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Mon, 19 Dec 2022 10:43:23 +0100 Subject: [PATCH 08/10] Fix typo --- examples/azure/embeddings.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/azure/embeddings.ipynb b/examples/azure/embeddings.ipynb index 9715821..5bd7761 100644 --- a/examples/azure/embeddings.ipynb +++ b/examples/azure/embeddings.ipynb @@ -1,12 +1,13 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Azure embeddings example\n", "In this example we'll try to go over all operations for embeddings that can be done using the Azure endpoints. \\\n", - "This example focuses on embeddings but also touches on the some other operations that are also available using the API. This example is meant to be a quick way of showing simple operations and is not meant as a tutorial." + "This example focuses on embeddings but also touches some other operations that are also available using the API. This example is meant to be a quick way of showing simple operations and is not meant as a tutorial." ] }, { From 0bd2dcfa5ce2e2dee268f5df93834dfabba1bfb0 Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Tue, 20 Dec 2022 16:19:15 +0100 Subject: [PATCH 09/10] Fix setup sections --- examples/azure/completions.ipynb | 8 ++++---- examples/azure/embeddings.ipynb | 9 +++++---- examples/azure/finetuning.ipynb | 10 +++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/examples/azure/completions.ipynb b/examples/azure/completions.ipynb index f5ba33b..b1cf30f 100644 --- a/examples/azure/completions.ipynb +++ b/examples/azure/completions.ipynb @@ -24,7 +24,7 @@ "metadata": {}, "source": [ "## Setup\n", - "For the following sections to work properly we first have to setup some things. Let's start with the `api_type`, `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value." + "For the following sections to work properly we first have to setup some things. Let's start with the `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value." ] }, { @@ -33,9 +33,7 @@ "metadata": {}, "outputs": [], "source": [ - "openai.api_type = 'azure'\n", "openai.api_version = '2022-12-01'\n", - "\n", "openai.api_base = '' # Please add your endpoint here" ] }, @@ -43,7 +41,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We next have to setup the `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication." + "We next have to setup the `api_type` and `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication. Depending on this the `api_type` is either `azure` or `azure_ad`." ] }, { @@ -60,6 +58,7 @@ "metadata": {}, "outputs": [], "source": [ + "openai.api_type = 'azure'\n", "openai.api_key = '' # Please add your api key here" ] }, @@ -83,6 +82,7 @@ "default_credential = DefaultAzureCredential()\n", "token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", "\n", + "openai.api_type = 'azure_ad'\n", "openai.api_key = token.token\n", "\"\"\"" ] diff --git a/examples/azure/embeddings.ipynb b/examples/azure/embeddings.ipynb index 5bd7761..f7729e7 100644 --- a/examples/azure/embeddings.ipynb +++ b/examples/azure/embeddings.ipynb @@ -21,11 +21,12 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", - "For the following sections to work properly we first have to setup some things. Let's start with the `api_type`, `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value." + "For the following sections to work properly we first have to setup some things. Let's start with the `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value." ] }, { @@ -34,9 +35,7 @@ "metadata": {}, "outputs": [], "source": [ - "openai.api_type = 'azure'\n", "openai.api_version = '2022-12-01'\n", - "\n", "openai.api_base = '' # Please add your endpoint here" ] }, @@ -45,7 +44,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We next have to setup the `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication." + "We next have to setup the `api_type` and `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication. Depending on this the `api_type` is either `azure` or `azure_ad`." ] }, { @@ -63,6 +62,7 @@ "metadata": {}, "outputs": [], "source": [ + "openai.api_type = 'azure'\n", "openai.api_key = '' # Please add your api key here" ] }, @@ -87,6 +87,7 @@ "default_credential = DefaultAzureCredential()\n", "token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", "\n", + "openai.api_type = 'azure_ad'\n", "openai.api_key = token.token\n", "\"\"\"" ] diff --git a/examples/azure/finetuning.ipynb b/examples/azure/finetuning.ipynb index 171863b..3f6ed66 100644 --- a/examples/azure/finetuning.ipynb +++ b/examples/azure/finetuning.ipynb @@ -6,7 +6,7 @@ "source": [ "# Azure Fine tuning example\n", "In this example we'll try to go over all operations that can be done using the Azure endpoints and their differences with the openAi endpoints (if any).
\n", - "This example focuses on finetuning but touches on the majority of operations that are also available using the API. This example is meant to be a quick way of showing simple operations and is not meant as a finetune model adaptation tutorial.\n" + "This example focuses on finetuning but also touches on the majority of operations that are available using the API. This example is meant to be a quick way of showing simple operations and is not meant as a finetune model adaptation tutorial.\n" ] }, { @@ -24,7 +24,7 @@ "metadata": {}, "source": [ "## Setup\n", - "For the following sections to work properly we first have to setup some things. Let's start with the `api_type`, `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value." + "For the following sections to work properly we first have to setup some things. Let's start with the `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value." ] }, { @@ -33,9 +33,7 @@ "metadata": {}, "outputs": [], "source": [ - "openai.api_type = 'azure'\n", "openai.api_version = '2022-12-01'\n", - "\n", "openai.api_base = '' # Please add your endpoint here" ] }, @@ -43,7 +41,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We next have to setup the `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication." + "We next have to setup the `api_type` and `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication. Depending on this the `api_type` is either `azure` or `azure_ad`." ] }, { @@ -60,6 +58,7 @@ "metadata": {}, "outputs": [], "source": [ + "openai.api_type = 'azure'\n", "openai.api_key = '' # Please add your api key here" ] }, @@ -84,6 +83,7 @@ "default_credential = DefaultAzureCredential()\n", "token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", "\n", + "openai.api_type = 'azure_ad'\n", "openai.api_key = token.token\n", "\"\"\"" ] From 934f4d863b36d781638de137a23163831aa17b0f Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Tue, 20 Dec 2022 16:50:42 +0100 Subject: [PATCH 10/10] Update ad auth section --- examples/azure/completions.ipynb | 21 +++++++++++++-------- examples/azure/embeddings.ipynb | 14 ++++++-------- examples/azure/finetuning.ipynb | 14 ++++++-------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/examples/azure/completions.ipynb b/examples/azure/completions.ipynb index b1cf30f..da72f2f 100644 --- a/examples/azure/completions.ipynb +++ b/examples/azure/completions.ipynb @@ -67,7 +67,7 @@ "metadata": {}, "source": [ "### (Optional) Setup: Microsoft Active Directory Authentication\n", - "Let's now see how we can get a key via Microsoft Active Directory Authentication." + "Let's now see how we can get a key via Microsoft Active Directory Authentication. Uncomment the following code if you want to use Active Directory Authentication instead of keys from the portal." ] }, { @@ -76,15 +76,13 @@ "metadata": {}, "outputs": [], "source": [ - "\"\"\"\n", - "from azure.identity import DefaultAzureCredential\n", + "# from azure.identity import DefaultAzureCredential\n", "\n", - "default_credential = DefaultAzureCredential()\n", - "token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", + "# default_credential = DefaultAzureCredential()\n", + "# token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", "\n", - "openai.api_type = 'azure_ad'\n", - "openai.api_key = token.token\n", - "\"\"\"" + "# openai.api_type = 'azure_ad'\n", + "# openai.api_key = token.token" ] }, { @@ -191,6 +189,13 @@ "print(f'Deleting deployment: {deployment_id}')\n", "openai.Deployment.delete(sid=deployment_id)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/examples/azure/embeddings.ipynb b/examples/azure/embeddings.ipynb index f7729e7..cef6a0c 100644 --- a/examples/azure/embeddings.ipynb +++ b/examples/azure/embeddings.ipynb @@ -72,7 +72,7 @@ "metadata": {}, "source": [ "### (Optional) Setup: Microsoft Active Directory Authentication\n", - "Let's now see how we can get a key via Microsoft Active Directory Authentication." + "Let's now see how we can get a key via Microsoft Active Directory Authentication. Uncomment the following code if you want to use Active Directory Authentication instead of keys from the portal." ] }, { @@ -81,15 +81,13 @@ "metadata": {}, "outputs": [], "source": [ - "\"\"\"\n", - "from azure.identity import DefaultAzureCredential\n", + "# from azure.identity import DefaultAzureCredential\n", "\n", - "default_credential = DefaultAzureCredential()\n", - "token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", + "# default_credential = DefaultAzureCredential()\n", + "# token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", "\n", - "openai.api_type = 'azure_ad'\n", - "openai.api_key = token.token\n", - "\"\"\"" + "# openai.api_type = 'azure_ad'\n", + "# openai.api_key = token.token" ] }, { diff --git a/examples/azure/finetuning.ipynb b/examples/azure/finetuning.ipynb index 3f6ed66..434901d 100644 --- a/examples/azure/finetuning.ipynb +++ b/examples/azure/finetuning.ipynb @@ -68,7 +68,7 @@ "metadata": {}, "source": [ "### (Optional) Setup: Microsoft Active Directory Authentication\n", - "Let's now see how we can get a key via Microsoft Active Directory Authentication." + "Let's now see how we can get a key via Microsoft Active Directory Authentication. Uncomment the following code if you want to use Active Directory Authentication instead of keys from the portal." ] }, { @@ -77,15 +77,13 @@ "metadata": {}, "outputs": [], "source": [ - "\"\"\"\n", - "from azure.identity import DefaultAzureCredential\n", + "# from azure.identity import DefaultAzureCredential\n", "\n", - "default_credential = DefaultAzureCredential()\n", - "token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", + "# default_credential = DefaultAzureCredential()\n", + "# token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n", "\n", - "openai.api_type = 'azure_ad'\n", - "openai.api_key = token.token\n", - "\"\"\"" + "# openai.api_type = 'azure_ad'\n", + "# openai.api_key = token.token" ] }, {