You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-functions/create-first-function-cli-csharp.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -166,7 +166,7 @@ To learn more, see [Azure Functions HTTP triggers and bindings](./functions-bind
166
166
167
167
This command creates a function app running in your specified language runtime on Linux in the [Flex Consumption Plan](flex-consumption-plan.md), which is free for the amount of usage you incur here. The command also creates an associated Azure Application Insights instance in the same resource group, with which you can monitor your function app and view logs. For more information, see [Monitor Azure Functions](functions-monitoring.md). The instance incurs no costs until you activate it.
168
168
169
-
8. Add your user-assigned managed identity to the [Monitoring Metrics Publisher](../role-based-access-control/built-in-roles/monitor#monitoring-metrics-publisher) role in your Application Insights instance:
169
+
8. Add your user-assigned managed identity to the [Monitoring Metrics Publisher](../role-based-access-control/built-in-roles/monitor.md#monitoring-metrics-publisher) role in your Application Insights instance:
# Tutorial: Add Azure OpenAI text completion hints to your functions in Visual Studio Code
15
15
16
-
This article shows you how to use Visual Studio Code to add an HTTP endpoint to the function app you created in the previous quickstart article. When triggered, this new HTTP endpoint uses an [Azure OpenAI text completion input binding](functions-bindings-openai-textcompletion-input.md) to get text completion hints from your data model.
16
+
This article shows you how to add an HTTP endpoint to the function app you created in the previous quickstart article. When triggered, this new HTTP endpoint uses an [Azure OpenAI text completion input binding](functions-bindings-openai-textcompletion-input.md) to get text completion hints from your data model.
17
17
18
18
During this tutorial, you learn how to accomplish these tasks:
19
19
20
20
> [!div class="checklist"]
21
21
> * Create resources in Azure OpenAI.
22
+
> * Enable managed identity access to your OpenAI resource.
22
23
> * Deploy a model in OpenAI the resource.
23
24
> * Set access permissions to the model resource.
24
25
> * Enable your function app to connect to OpenAI.
25
26
> * Add OpenAI bindings to your HTTP triggered function.
26
27
27
-
## 1. Check prerequisites
28
-
:::zone pivot="programming-language-csharp"
29
-
* Complete the steps in [part 1 of the Visual Studio Code quickstart](create-first-function-vs-code-csharp.md).
30
-
:::zone-end
31
-
:::zone pivot="programming-language-java"
32
-
* Complete the steps in [part 1 of the Visual Studio Code quickstart](create-first-function-vs-code-java.md).
33
-
:::zone-end
34
-
:::zone pivot="programming-language-javascript"
35
-
* Complete the steps in [part 1 of the Visual Studio Code quickstart](create-first-function-vs-code-node.md).
36
-
:::zone-end
37
-
:::zone pivot="programming-language-typescript"
38
-
* Complete the steps in [part 1 of the Visual Studio Code quickstart](create-first-function-vs-code-typescript.md).
39
-
:::zone-end
40
-
:::zone pivot="programming-language-python"
41
-
* Complete the steps in [part 1 of the Visual Studio Code quickstart](create-first-function-vs-code-python.md).
42
-
:::zone-end
43
-
:::zone pivot="programming-language-powershell"
44
-
* Complete the steps in [part 1 of the Visual Studio Code quickstart](create-first-function-vs-code-powershell.md).
45
-
:::zone-end
46
-
* Obtain access to Azure OpenAI in your Azure subscription. If you haven't already been granted access, complete [this form](https://aka.ms/oai/access) to request access.
* The [Azurite storage emulator](../storage/common/storage-use-azurite.md?tabs=npm#install-azurite). While you can also use an actual Azure Storage account, the article assumes you're using this emulator.
51
-
52
-
## 2. Create your Azure OpenAI resources
28
+
## Prerequisites
29
+
30
+
- Complete the steps in [Quickstart: Create and deploy functions to Azure Functions using the Azure Developer CLI](create-first-function-azure-developer-cli.md).
31
+
32
+
- Obtain access to Azure OpenAI in your Azure subscription. If you haven't already been granted access, complete [this form](https://aka.ms/oai/access) to request access.
33
+
34
+
## Create your Azure OpenAI resources
53
35
54
-
The following steps show how to create an Azure OpenAI data model in the Azure portal.
36
+
Use these steps to create an Azure OpenAI data model:
55
37
56
-
1. Sign in with your Azure subscription in the [Azure portal](https://portal.azure.com).
38
+
### [Azure portal](#tab/azure-portal)
57
39
58
-
1.Select**Create a resource** and search for the **Azure OpenAI**. When you locate the service, select **Create**.
40
+
1.In the Azure portal, select**Create a resource** and search for the **Azure OpenAI**. When you locate the service, select **Create**.
59
41
60
42
1. On the **Create Azure OpenAI** page, provide the following information for the fields on the **Basics** tab:
61
43
62
44
| Field | Description |
63
45
|---|---|
64
46
|**Subscription**| Your subscription, which has been onboarded to use Azure OpenAI. |
65
-
|**Resource group**|The resource group you created for the function app in the previous article. You can find this resource group name by right-clicking the function app in the Azure Resources browser, selecting properties, and then searching for the `resourceGroup` setting in the returned JSON resource file. |
66
-
|**Region**| Ideally, the same location as the function app. |
47
+
|**Resource group**|Use the same same resource group as your existing function app. |
48
+
|**Region**| Ideally, use the same same region where your existing function app is hosted. |
67
49
|**Name**| A descriptive name for your Azure OpenAI Service resource, such as _mySampleOpenAI_. |
68
50
|**Pricing Tier**| The pricing tier for the resource. Currently, only the Standard tier is available for the Azure OpenAI Service. For more info on pricing visit the [Azure OpenAI pricing page](https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/)|
69
51
@@ -77,54 +59,78 @@ The following steps show how to create an Azure OpenAI data model in the Azure p
77
59
78
60
The Azure portal displays a notification when the new resource is available. Select **Go to resource** in the notification or search for your new Azure OpenAI resource by name.
79
61
80
-
1. In the Azure OpenAI resource page for your new resource, select **Click here to view endpoints** under **Essentials** > **Endpoints**. Copy the **endpoint** URL and the **keys**. Save these values, you need them later.
62
+
1. In the Azure OpenAI resource page for your new resource, select **Click here to view endpoints** under **Essentials** > **Endpoints**.
81
63
82
-
Now that you have the credentials to connect to your model in Azure OpenAI, you need to set these access credentials in application settings.
64
+
1. Copy the **endpoint** URL, which you need to use later.
83
65
84
-
## 3. Deploy a model
66
+
### [Azure CLI](#tab/azure-cli)
67
+
68
+
1. Use the command to
69
+
70
+
---
71
+
72
+
Next, you grant access to the user-assigned managed identity to be able to connect to your Azure OpenAI resource.
73
+
74
+
## 4. Grant user access to Azure OpenAI
75
+
76
+
Use these steps to grant access in your new Azure OpenAI resource both to the user-assigned manage identity associated with your app and to your Azure account.
77
+
78
+
1. In your Azure OpenAI resource, select **Access control (IAM)** on the left pane.
79
+
80
+
1. Select **Add** > **Add role assignment**.
81
+
82
+
1. On the **Role** tab on the next screen, select **Cognitive Services OpenAI User** and then **Next**.
83
+
84
+
1. On the **Members** tab, select **Assign access to** > **Managed identity** then **Select members**.
85
+
86
+
1. In the **Select managed identities** pane, select **Managed identity** > **User assigned managed identity**.
87
+
88
+
1. Choose your user-assigned managed identity from the list and then **Select** > **Review + assign**.
89
+
90
+
1. On the **Review + assign** tab, select **Review + assign** to assign the role.
91
+
92
+
## 5. Deploy a model
85
93
86
94
Now you can deploy a model. You can select from one of several available models in Azure OpenAI Studio.
87
95
88
96
To deploy a model, follow these steps:
89
97
90
98
1. Sign in to [Azure OpenAI Studio](https://oai.azure.com).
91
99
92
-
1.Choose the subscription and the Azure OpenAI resource you created, and select **Use resource**.
100
+
1.In the correct **Subscription**and**Directory**, select the name of the Azure OpenAI resource you created, and select **Use resource**.
93
101
94
-
1. Under **Management** select **Deployments**.
102
+
1. Under **Shared resources** select **Deployments**.
95
103
96
-
1. Select **Create new deployment** and configure the following fields:
104
+
1. Select **Deploy model** > **Deploy base model**, choose your base model from the list, such as `gpt-4o`, and select **Confirm**.
97
105
98
-
| Field | Description |
99
-
|---|---|
100
-
|**Deployment name**| Choose a name carefully. The deployment name is used in your code to call the model by using the client libraries and the REST APIs, so you must save for use later on. |
101
-
|**Select a model**| Model availability varies by region. For a list of available models per region, see [Model summary table and region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability). |
106
+
Model availability varies by region. For a list of available models per region, see [Model summary table and region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability).
102
107
103
-
> [!IMPORTANT]
104
-
> When you access the model via the API, you need to refer to the deployment name rather than the underlying model name in API calls, which is one of the key differences between OpenAI and Azure OpenAI. OpenAI only requires the model name. Azure OpenAI always requires deployment name, even when using the model parameter. In our docs, we often have examples where deployment names are represented as identical to model names to help indicate which model works with a particular API endpoint. Ultimately your deployment names can follow whatever naming convention is best for your use case.
108
+
1. Confirm the **Deployment name** for your model deployment and select **Deploy**.
105
109
106
-
1. Accept the default values for the rest of the setting and select **Create**.
110
+
Choose a deployment name carefully. The deployment name is used in your code to call the model by using the client libraries and the REST APIs, so you must save it for use later on.
107
111
108
-
The deployments table shows a new entry that corresponds to your newly created model.
112
+
> [!IMPORTANT]
113
+
> When you access the model via the API, you need to refer to the deployment name rather than the underlying model name in API calls, which is one of the key differences between OpenAI and Azure OpenAI. OpenAI only requires the model name. Azure OpenAI always requires deployment name, even when using the model parameter. In our docs, we often have examples where deployment names are represented as identical to model names to help indicate which model works with a particular API endpoint. Ultimately your deployment names can follow whatever naming convention is best for your use case.
109
114
110
115
You now have everything you need to add Azure OpenAI-based text completion to your function app.
111
116
112
-
## 4. Update application settings
117
+
## 6. Update application settings
113
118
114
119
1. In Visual Studio Code, open the local code project you created when you completed the [previous article](./create-first-function-vs-code-csharp.md).
115
120
116
121
1. In the local.settings.json file in the project root folder, update the `AzureWebJobsStorage` setting to `UseDevelopmentStorage=true`. You can skip this step if the `AzureWebJobsStorage` setting in *local.settings.json* is set to the connection string for an existing Azure Storage account instead of `UseDevelopmentStorage=true`.
117
122
118
123
1. In the local.settings.json file, add these settings values:
119
124
120
-
+**`AZURE_OPENAI_ENDPOINT`**: required by the binding extension. Set this value to the endpoint of the Azure OpenAI resource you created earlier.
121
-
+**`AZURE_OPENAI_KEY`**: required by the binding extension. Set this value to the key for the Azure OpenAI resource.
122
-
+**`CHAT_MODEL_DEPLOYMENT_NAME`**: used to define the input binding. Set this value to the name you chose for your model deployment.
125
+
+**`AzureOpenAI__endpoint`**: required by the binding extension. Set this value to the endpoint of the Azure OpenAI resource you created earlier.
126
+
+**`"AzureOpenAI__tenantId"`**: required when running locally to connect to Azure OpenAI with the user-assigned managed identity. Set this value to the **Tenant ID** value you saved earlier.
127
+
+**`AzureOpenAI__clientId`**: required when running locally and in Azure. Set this value to the **Client ID** value you saved earlier.
128
+
+**`CHAT_MODEL_DEPLOYMENT_NAME`**: used by input binding settings. Set this value to the name you chose for your model deployment.
123
129
124
130
1. Save the file. When you deploy to Azure, you must also add these settings to your function app.
125
131
126
132
:::zone pivot="programming-language-csharp"
127
-
## 5. Register binding extensions
133
+
## 7. Register binding extensions
128
134
129
135
Because you're using an Azure OpenAI output binding, you must have the corresponding bindings extension installed before you run the project.
<!---NOTE: Update this after preview to `## Verify the extension bundle`-->
139
-
## 5. Update the extension bundle
145
+
## 7. Update the extension bundle
140
146
141
147
To access the preview Azure OpenAI bindings, you must use a preview version of the extension bundle that contains this extension.
142
148
@@ -151,7 +157,7 @@ Replace the `extensionBundle` setting in your current `host.json` file with this
151
157
:::zone-end
152
158
Now, you can use the Azure OpenAI output binding in your project.
153
159
154
-
## 6. Return text completion from the model
160
+
## 8. Return text completion from the model
155
161
156
162
The code you add creates a `whois` HTTP function endpoint in your existing project. In this function, data passed in a URL `name` parameter of a GET request is used to dynamically create a completion prompt. This dynamic prompt is bound to a text completion input binding, which returns a response from the model based on the prompt. The completion from the model is returned in the HTTP response.
157
163
:::zone pivot="programming-language-csharp"
@@ -234,7 +240,7 @@ The code you add creates a `whois` HTTP function endpoint in your existing proje
234
240
235
241
:::zone-end
236
242
237
-
## 7. Run the function
243
+
## 9. Run the function
238
244
239
245
1. In Visual Studio Code, Press F1 and in the command palette type `Azurite: Start` and press Enter to start the Azurite storage emulator.
240
246
@@ -250,15 +256,10 @@ The code you add creates a `whois` HTTP function endpoint in your existing proje
InAzure, *resources*refertofunctionapps, functions, storageaccounts, andsoforth. They're grouped into *resource groups*, and you can delete everything in a group by deleting the group.
0 commit comments