From 381dde363fe10f1d5c34726541814bbdaec10b97 Mon Sep 17 00:00:00 2001 From: Christian Muertz Date: Mon, 19 Dec 2022 10:25:32 +0100 Subject: [PATCH] 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 761dd326..9715821f 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" } } },