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/functions-add-openai-text-completion.md
+24-27Lines changed: 24 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: 'Tutorial: Connect to OpenAI from Azure Functions in Visual Studio Code'
3
3
description: Learn how to connect Azure Functions to OpenAI by adding an output binding to your Visual Studio Code project.
4
-
ms.date: 07/08/2024
4
+
ms.date: 07/11/2024
5
5
ms.topic: tutorial
6
6
author: dbandaru
7
7
ms.author: dbandaru
@@ -51,7 +51,7 @@ This article shows you how to use Visual Studio Code to connect Azure OpenAI to
51
51
52
52
The following steps show how to create an Azure OpenAI data model in the Azure portal.
53
53
54
-
1. Sign in with your Azure subscription in the Azure portal.
54
+
1. Sign in with your Azure subscription in the [Azure portal](https://portal.azure.com).
55
55
56
56
1. Select **Create a resource** and search for the **Azure OpenAI**. When you locate the service, select **Create**.
57
57
@@ -60,7 +60,7 @@ The following steps show how to create an Azure OpenAI data model in the Azure p
60
60
| Field | Description |
61
61
|---|---|
62
62
|**Subscription**| Your subscription, which has been onboarded to use Azure OpenAI. |
63
-
|**Resource group**| The resource group you created for the function app in the previous article. |
63
+
|**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. |
64
64
|**Region**| Ideally, the same location as the function app. |
65
65
|**Name**| A descriptive name for your Azure OpenAI Service resource, such as _mySampleOpenAI_. |
66
66
|**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/)|
@@ -73,7 +73,11 @@ The following steps show how to create an Azure OpenAI data model in the Azure p
73
73
74
74
1. Confirm your configuration settings, and select **Create**.
75
75
76
-
The Azure portal displays a notification when the new resource is available.
76
+
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.
77
+
78
+
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.
79
+
80
+
Now that you have the credentials to connect to your model in Azure OpenAI, you need to set these access credentials in application settings.
77
81
78
82
## 3. Deploy a model
79
83
@@ -91,23 +95,23 @@ To deploy a model, follow these steps:
91
95
92
96
| Field | Description |
93
97
|---|---|
98
+
|**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. |
94
99
|**Select a model**| Model availability varies by region. For a list of available models per region, see [Model summary table and region availability](../ai-services/openai/concepts/models.md#model-summary-table-and-region-availability). |
95
-
|**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. |
96
100
97
101
> [!IMPORTANT]
98
102
> 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.
99
103
100
-
1.Leave the **Advanced options** set to the defaults, and select **Create**.
104
+
1.Accept the default values for the rest of the setting and select **Create**.
101
105
102
106
The deployments table shows a new entry that corresponds to your newly created model.
103
107
104
-
1. After the deployment completes, navigate to the Azure OpenAI resource page in the Azure portal, and select **Click here to view endpoints** under **Essentials**. Copy the **endpoint** URL and the **keys**. Save these values, you need them later.
105
-
106
-
Now that you have the credentials to connect to your model in Azure OpenAI, you need to set these access credentials in application settings.
108
+
You now have everything you need to add Azure OpenAI-based text completion to your function app.
107
109
108
110
## 4. Update application settings
109
111
110
-
1. In Visual Studio Code, open the code project you created when you completed the [previous article](./create-first-function-vs-code-csharp.md), open the local.settings.json file in the project root folder, and 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`.
112
+
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).
113
+
114
+
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`.
111
115
112
116
1. In the local.settings.json file, add these settings values:
@@ -233,19 +234,15 @@ The code you add creates a `whois` HTTP function endpoint in your existing proje
233
234
234
235
## 7. Run the function
235
236
236
-
1. In a Terminal window, run the following command to start the Azurite storage emulator in a separate process:
237
-
238
-
```cmd
239
-
start azurite
240
-
```
237
+
1. In Visual Studio Code, Press F1 and in the command palette type `Azurite: Start` and press Enter to start the Azurite storage emulator.
241
238
242
239
1. Press <kbd>F5</kbd> to start the function app project and Core Tools in debug mode.
243
240
244
241
1. With the Core Tools running, send a GET request to the `whois` endpoint function, with a name in the path, like this URL:
245
242
246
243
`http://localhost:7071/api/whois/<NAME>`
247
244
248
-
Replace the `<NAME>` string with the value you want passed to the `"Who is {name}?"` prompt.
245
+
Replace the `<NAME>` string with the value you want passed to the `"Who is {name}?"` prompt. The `<NAME>` must be the URL-encoded name of a public figure, like `Abraham%20Lincoln`.
0 commit comments