Skip to content

Commit 1a123c7

Browse files
authored
Final testing clean-up (JS)
1 parent 0166123 commit 1a123c7

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

articles/azure-functions/functions-add-openai-text-completion.md

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 'Tutorial: Connect to OpenAI from Azure Functions in Visual Studio Code'
33
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
55
ms.topic: tutorial
66
author: dbandaru
77
ms.author: dbandaru
@@ -51,7 +51,7 @@ This article shows you how to use Visual Studio Code to connect Azure OpenAI to
5151

5252
The following steps show how to create an Azure OpenAI data model in the Azure portal.
5353

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).
5555

5656
1. Select **Create a resource** and search for the **Azure OpenAI**. When you locate the service, select **Create**.
5757

@@ -60,7 +60,7 @@ The following steps show how to create an Azure OpenAI data model in the Azure p
6060
| Field | Description |
6161
|---|---|
6262
| **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. |
6464
| **Region** | Ideally, the same location as the function app. |
6565
| **Name** | A descriptive name for your Azure OpenAI Service resource, such as _mySampleOpenAI_. |
6666
| **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
7373

7474
1. Confirm your configuration settings, and select **Create**.
7575

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.
7781

7882
## 3. Deploy a model
7983

@@ -91,23 +95,23 @@ To deploy a model, follow these steps:
9195

9296
| Field | Description |
9397
|---|---|
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. |
9499
| **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. |
96100

97101
> [!IMPORTANT]
98102
> 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.
99103
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**.
101105

102106
The deployments table shows a new entry that corresponds to your newly created model.
103107

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.
107109

108110
## 4. Update application settings
109111

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`.
111115

112116
1. In the local.settings.json file, add these settings values:
113117

@@ -134,19 +138,16 @@ dotnet add package Microsoft.Azure.Functions.Worker.Extensions.OpenAI --prerelea
134138

135139
To access the preview Azure OpenAI bindings, you must use a preview version of the extension bundle that contains this extension.
136140

137-
Replace the contents of your current `host.json` file with this JSON:
141+
Replace the `extensionBundle` setting in your current `host.json` file with this JSON:
138142

139143
```json
140-
{
141-
"version": "2.0",
142-
"extensionBundle": {
143-
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
144-
"version": "[4.*, 5.0.0)"
145-
}
146-
}
144+
"extensionBundle": {
145+
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
146+
"version": "[4.*, 5.0.0)"
147+
}
147148
```
148149
:::zone-end
149-
Now, you can use the Azure OpenAI output binding to your project.
150+
Now, you can use the Azure OpenAI output binding in your project.
150151

151152
## 6. Return text completion from the model
152153

@@ -194,15 +195,15 @@ The code you add creates a `whois` HTTP function endpoint in your existing proje
194195

195196
:::zone-end
196197
:::zone pivot="programming-language-javascript"
197-
1. In Visual Studio Code, Press F1 and in the command palette type `Azure Functions: Create Function...`, select **HTTP trigger**, type the function name `whois`, select **Anonymous**, and press Enter.
198+
1. In Visual Studio Code, Press F1 and in the command palette type `Azure Functions: Create Function...`, select **HTTP trigger**, type the function name `whois`, and press Enter.
198199

199200
1. In the new `whois.js` code file, replace the contents of the file with this code:
200201

201202
:::code language="javascript" source="~/functions-openai-extension/samples/textcompletion/javascript/src/functions/whois.js" :::
202203

203204
:::zone-end
204205
:::zone pivot="programming-language-typescript"
205-
1. In Visual Studio Code, Press F1 and in the command palette type `Azure Functions: Create Function...`, select **HTTP trigger**, type the function name `whois`, select **Anonymous**, and press Enter.
206+
1. In Visual Studio Code, Press F1 and in the command palette type `Azure Functions: Create Function...`, select **HTTP trigger**, type the function name `whois`, and press Enter.
206207

207208
1. In the new `whois.ts` code file, replace the contents of the file with this code:
208209

@@ -233,19 +234,15 @@ The code you add creates a `whois` HTTP function endpoint in your existing proje
233234

234235
## 7. Run the function
235236

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.
241238

242239
1. Press <kbd>F5</kbd> to start the function app project and Core Tools in debug mode.
243240

244241
1. With the Core Tools running, send a GET request to the `whois` endpoint function, with a name in the path, like this URL:
245242

246243
`http://localhost:7071/api/whois/<NAME>`
247244

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`.
249246

250247
The response you see is the text completion response from your Azure OpenAI model.
251248

0 commit comments

Comments
 (0)