|
1 | 1 | ---
|
2 |
| -title: 'How to use the Azure CLI to create an Azure OpenAI Service resource and manage deployments' |
| 2 | +title: 'Create and manage Azure OpenAI Service deployments with the Azure CLI' |
3 | 3 | titleSuffix: Azure OpenAI
|
4 |
| -description: Step by step guide for using the Azure CLI to deploy an Azure OpenAI Resource and manage deployments |
| 4 | +description: Learn how to use the Azure CLI to create an Azure OpenAI resource and manage deployments with the Azure OpenAI Service. |
5 | 5 | services: cognitive-services
|
6 | 6 | manager: nitinme
|
7 | 7 | ms.service: cognitive-services
|
8 | 8 | ms.subservice: openai
|
9 | 9 | ms.custom: devx-track-azurecli
|
10 | 10 | ms.topic: include
|
11 |
| -ms.date: 6/30/2022 |
| 11 | +ms.date: 08/14/2023 |
12 | 12 | keywords:
|
13 | 13 | ---
|
14 | 14 |
|
15 | 15 | ## Prerequisites
|
16 | 16 |
|
17 |
| -- An Azure subscription - <a href="https://azure.microsoft.com/free/cognitive-services" target="_blank">Create one for free</a> |
18 |
| -- Access granted to Azure OpenAI in the desired Azure subscription |
| 17 | +- An Azure subscription. <a href="https://azure.microsoft.com/free/ai-services" target="_blank">Create one for free</a>. |
| 18 | +- Access granted to Azure OpenAI in the desired Azure subscription. |
| 19 | +- The Azure CLI. For more information, see [How to install the Azure CLI](/cli/azure/install-azure-cli). |
19 | 20 |
|
20 |
| - Currently, access to this service is granted only by application. You can apply for access to the Azure OpenAI service by completing the form at <a href="https://aka.ms/oai/access" target="_blank">https://aka.ms/oai/access</a>. Open an issue on this repo to contact us if you have an issue. |
21 |
| -- Azure CLI. [Installation guide](/cli/azure/install-azure-cli) |
| 21 | +> [!NOTE] |
| 22 | +> Currently, you must submit an application to access Azure OpenAI Service. To apply for access, complete [this form](https://aka.ms/oai/access). If you need assistance, open an issue on this repository to contact Microsoft. |
22 | 23 |
|
23 |
| -## Sign in to the CLI |
| 24 | +## Sign in to the Azure CLI |
24 | 25 |
|
25 |
| -run the az login command to log in, `az login` |
| 26 | +[Sign in](/cli/azure/authenticate-azure-cli) to the Azure CLI or select **Open Cloudshell** in the following steps. |
26 | 27 |
|
27 |
| -## Create a new Azure Resource Group |
28 |
| -You must have an Azure resource group in order to create an OpenAI resource. When you create a new resource, you have the option to either create a new resource group, or use an existing one. This article shows how to create a new resource group. You can create a new resource group in the Azure CLI using the `az group create` command. The example below creates a new resource group in the eastus location. you can find the full [reference documentation here](/cli/azure/group?view=azure-cli-latest&preserve-view=true#az-group-create). |
| 28 | +## Create an Azure resource group |
29 | 29 |
|
30 |
| -```azurecli |
| 30 | +To create an Azure OpenAI resource, you need an Azure resource group. When you create a new resource through the Azure CLI, you can also create a new resource group or instruct Azure to use an existing group. The following example shows how to create a new resource group named _OAIResourceGroup_ with the [az group create](/cli/azure/group?view=azure-cli-latest&preserve-view=true#az-group-create) command. The resource group is created in the East US location. |
| 31 | + |
| 32 | +```azurecli-interactive |
31 | 33 | az group create \
|
32 | 34 | --name OAIResourceGroup \
|
33 | 35 | --location eastus
|
34 | 36 | ```
|
35 | 37 |
|
36 | 38 | ## Create a resource
|
37 |
| -Run the following command to create an OpenAI resource in the new resource group. In this example, we create a resource called MyOpenAIResource in the resource group called OAIResourceGroup. Make sure to update with your own values for the resource group, resource name and your Azure Subscription ID. You can find the full [reference documentation here](/cli/azure/cognitiveservices/account?view=azure-cli-latest&preserve-view=true#az-cognitiveservices-account-create). |
| 39 | + |
| 40 | +Use the [az cognitiveservices account create](/cli/azure/cognitiveservices/account?view=azure-cli-latest&preserve-view=true#az-cognitiveservices-account-create) command to create an Azure OpenAI resource in the resource group. In the following example, you create a resource named _MyOpenAIResource_ in the _OAIResourceGroup_ resource group. When you try the example, update the code to use your desired values for the resource group and resource name, along with your Azure subscription ID _\<subscriptionID>_. |
38 | 41 |
|
39 | 42 | ```azurecli
|
40 | 43 | az cognitiveservices account create \
|
41 |
| --n MyOpenAIResource \ |
42 |
| --g OAIResourceGroup \ |
43 |
| --l eastus \ |
| 44 | +--name MyOpenAIResource \ |
| 45 | +--resource-group OAIResourceGroup \ |
| 46 | +--location eastus \ |
44 | 47 | --kind OpenAI \
|
45 | 48 | --sku s0 \
|
46 |
| ---subscription 00000000-0000-0000-0000-000000000000 |
| 49 | +--subscription <subscriptionID> |
47 | 50 | ```
|
48 | 51 |
|
49 |
| -## Retrieve information from your resource |
50 |
| -Once your resource has been created, you can use the Azure CLI to find useful information about your service such as your REST API endpoint base URL and the access keys. Below are examples on how to do both. You can find the full [reference documentation here](/cli/azure/cognitiveservices/account?view=azure-cli-latest&preserve-view=true). |
51 |
| - |
52 |
| -1. **Retrieve your endpoint**: |
53 |
| - |
54 |
| - ```azurecli |
55 |
| - az cognitiveservices account show \ |
56 |
| - -n $myResourceName \ |
57 |
| - -g $myResourceGroupName \ |
58 |
| - | jq -r .properties.endpoint |
59 |
| - ``` |
60 |
| -1. **Retrieve your primary API key**: |
61 |
| - ```azurecli |
62 |
| - az cognitiveservices account keys list \ |
63 |
| - -n $myResourceName \ |
64 |
| - -g $myResourceGroupName |
65 |
| - | jq -r .key1 |
66 |
| - ``` |
| 52 | +## Retrieve information about the resource |
67 | 53 |
|
68 |
| -## Deploy a model |
| 54 | +After you create the resource, you can use different commands to find useful information about your Azure OpenAI Service instance. The following examples demonstrate how to retrieve the REST API endpoint base URL and the access keys for the new resource. |
| 55 | + |
| 56 | +### Get the endpoint URL |
69 | 57 |
|
70 |
| -To deploy a model, you can use the Azure CLI to run the following command to deploy an instance of text-curie-001. In this example, we deploy a model called MyModel. Make sure to update with your own values. You don't need to change the `model-version`, `model-format` or `scale-settings-scale-type` values. You can find the full [reference documentation here](/cli/azure/cognitiveservices/account/deployment?view=azure-cli-latest&preserve-view=true). |
| 58 | +Use the [az cognitiveservices account show](/cli/azure/cognitiveservices/account?view=azure-cli-latest&preserve-view=true#az-cognitiveservices-account-show) command to retrieve the REST API endpoint base URL for the resource. In this example, we direct the command output through the [jq](https://jqlang.github.io/jq/) JSON processor to locate the `.properties.endpoint` value. |
71 | 59 |
|
| 60 | +When you try the example, update the code to use your values for the resource group _\<myResourceGroupName>_ and resource _\<myResourceName>_. |
| 61 | + |
| 62 | +```azurecli |
| 63 | +az cognitiveservices account show \ |
| 64 | +--name <myResourceName> \ |
| 65 | +--resource-group <myResourceGroupName> \ |
| 66 | +| jq -r .properties.endpoint |
| 67 | +``` |
| 68 | + |
| 69 | +### Get the primary API key |
| 70 | + |
| 71 | +To retrieve the access keys for the resource, use the [az cognitiveservices account keys list](/cli/azure/cognitiveservices/account?view=azure-cli-latest&preserve-view=true#az-cognitiveservices-account-keys-list) command. In this example, we direct the command output through the [jq](https://jqlang.github.io/jq/) JSON processor to locate the `.key1` value. |
| 72 | + |
| 73 | +When you try the example, update the code to use your values for the resource group and resource. |
| 74 | + |
| 75 | +```azurecli |
| 76 | +az cognitiveservices account keys list \ |
| 77 | +--name <myResourceName> \ |
| 78 | +--resource-group <myResourceGroupName> \ |
| 79 | +| jq -r .key1 |
| 80 | +``` |
| 81 | + |
| 82 | +## Deploy a model |
| 83 | + |
| 84 | +To deploy a model, use the [az cognitiveservices account deployment create](/cli/azure/cognitiveservices/account/deployment?view=azure-cli-latest&preserve-view=true#az-cognitiveservices-account-deployment-create) command. In the following example, you deploy an instance of the `text-embedding-ada-002` model and give it the name _MyModel_. When you try the example, update the code to use your values for the resource group and resource. You don't need to change the `model-version`, `model-format` or `sku-capacity`, and `sku-name` values. |
72 | 85 |
|
73 | 86 | ```azurecli
|
74 | 87 | az cognitiveservices account deployment create \
|
75 |
| - -g $myResourceGroupName \ |
76 |
| - -n $myResourceName \ |
77 |
| - --deployment-name MyModel \ |
78 |
| - --model-name text-curie-001 \ |
79 |
| - --model-version "1" \ |
80 |
| - --model-format OpenAI \ |
81 |
| - --scale-settings-scale-type "Standard" |
| 88 | +--name <myResourceName> \ |
| 89 | +--resource-group <myResourceGroupName> \ |
| 90 | +--deployment-name MyModel \ |
| 91 | +--model-name text-embedding-ada-002 \ |
| 92 | +--model-version "1" \ |
| 93 | +--model-format OpenAI \ |
| 94 | +--sku-capacity "1" \ |
| 95 | +--sku-name "Standard" |
82 | 96 | ```
|
83 | 97 |
|
84 | 98 | ## Delete a model from your resource
|
85 | 99 |
|
86 |
| -You can delete any model you've deployed from your resource. To do so, you can use the Azure CLI to run the following command. In this example, we delete a model called MyModel. Make sure to update with your own values. You can find the full [reference documentation here](/cli/azure/cognitiveservices/account/deployment?view=azure-cli-latest&preserve-view=true#az-cognitiveservices-account-deployment-delete). |
| 100 | +You can delete any model deployed from your resource with the [az cognitiveservices account deployment delete](/cli/azure/cognitiveservices/account/deployment?view=azure-cli-latest&preserve-view=true#az-cognitiveservices-account-deployment-delete) command. In the following example, you delete a model named _MyModel_. When you try the example, update the code to use your values for the resource group, resource, and deployed model. |
87 | 101 |
|
88 | 102 | ```azurecli
|
89 | 103 | az cognitiveservices account deployment delete \
|
90 |
| - -g $myResourceGroupName \ |
91 |
| - -n $myResourceName \ |
92 |
| - --deployment-name MyModel |
| 104 | +--name <myResourceName> \ |
| 105 | +--resource-group <myResourceGroupName> \ |
| 106 | +--deployment-name MyModel |
93 | 107 | ```
|
94 | 108 |
|
95 | 109 | ## Delete a resource
|
96 |
| -If you want to clean up and remove your OpenAI resource, you can delete it or the resource group. Deleting the resource group also deletes any other resources contained in the group. |
97 | 110 |
|
98 |
| -To remove the resource group and its associated resources, use the `az group delete` command. |
| 111 | +If you want to clean up after these exercises, you can remove your Azure OpenAI resource by deleting the resource through the Azure CLI. You can also delete the resource group. If you choose to delete the resource group, all resources contained in the group are also deleted. |
99 | 112 |
|
100 |
| -If you're not going to continue to use this application, delete your resource with the following steps: |
| 113 | +To remove the resource group and its associated resources, use the [az cognitiveservices account delete](/cli/azure/cognitiveservices/account/deployment?view=azure-cli-latest&preserve-view=true#az-cognitiveservices-account-delete) command. |
| 114 | + |
| 115 | +If you're not going to continue to use the resources created in these exercises, run the following command to delete your resource group. Be sure to update the example code to use your values for the resource group and resource. |
101 | 116 |
|
102 | 117 | ```azurecli
|
103 | 118 | az cognitiveservices account delete \
|
104 |
| ---name MyOpenAIResource \ |
105 |
| --g OAIResourceGroup |
| 119 | +--name <myResourceName> \ |
| 120 | +--resource-group <myResourceGroupName> |
106 | 121 | ```
|
107 |
| - |
|
0 commit comments