Skip to content

Commit d2b1aeb

Browse files
authored
Dheeraj tech review updates
1 parent de9171c commit d2b1aeb

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

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

Lines changed: 35 additions & 29 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: 5/30/2024
4+
ms.date: 07/02/2024
55
ms.topic: tutorial
66
author: dbandaru
77
ms.author: dbandaru
@@ -22,7 +22,7 @@ This article shows you how to use Visual Studio Code to connect Azure OpenAI to
2222
> * Enable your function app to connect to OpenAI.
2323
> * Add OpenAI bindings to your HTTP triggered function.
2424
25-
## Prerequisites
25+
## 0. Prerequisites
2626
:::zone pivot="programming-language-csharp"
2727
* Complete the steps in [part 1 of the Visual Studio Code quickstart](create-first-function-vs-code-csharp.md).
2828
:::zone-end
@@ -44,7 +44,9 @@ This article shows you how to use Visual Studio Code to connect Azure OpenAI to
4444
* 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.
4545
:::zone pivot="programming-language-csharp"
4646
* Install [.NET Core CLI tools](/dotnet/core/tools/?tabs=netcore2x).
47-
:::zone-end
47+
:::zone-end
48+
* 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.
49+
4850
## 1. Create your Azure OpenAI resources
4951

5052
The following steps show how to create an Azure OpenAI data model in the Azure portal.
@@ -101,16 +103,17 @@ To deploy a model, follow these steps:
101103

102104
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.
103105

104-
## 3. Update application settings
105-
106106
Now that you have the credentials to connect to your model in Azure OpenAI, you need to set these access credentials in application settings.
107107

108-
1. In Visual Studio Code, open the code project you created when you completed the [previous article](./create-first-function-vs-code-csharp.md) and add these values to the local.settings.json file:
108+
## 3. Update application settings
109+
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`.
109111

112+
1. In the local.settings.json file, add these settings values:
110113

111114
+ **`AZURE_OPENAI_ENDPOINT`**: required by the binding extension. Set this value to the endpoint of the Azure OpenAI resource you created earlier.
112115
+ **`AZURE_OPENAI_KEY`**: required by the binding extension. Set this value to the key for the Azure OpenAI resource.
113-
+ **`CHAT_MODEL_DEPLOYMENT_NAME`**: used to define the input binding. Set this value to `gpt-3.5-turbo`, unless you used a different name for your model deployment.
116+
+ **`CHAT_MODEL_DEPLOYMENT_NAME`**: used to define the input binding. Set this value to the name you chose for your model deployment.
114117

115118
1. Save the file. When you deploy to Azure, you must also add these settings to your function app.
116119

@@ -196,24 +199,24 @@ The code you add creates a `whois` HTTP function endpoint in your existing proje
196199
1. In the new `whois.js` code file, replace the contents of the file with this code:
197200

198201
```javascript
199-
const { app } = require('@azure/functions');
200-
201-
const openAICompletionInput = app.generic({
202-
prompt: 'Who is {name}?',
203-
maxTokens: '100',
204-
type: 'textCompletion',
205-
model: '%CHAT_MODEL_DEPLOYMENT_NAME%'
206-
});
207-
app.http('whois', {
208-
methods: ['GET'],
209-
route: 'whois/{name}',
210-
authLevel: 'anonymous',
211-
extraInputs: [openAICompletionInput],
212-
handler: async (request, context) => {
213-
var response = context.extraInputs.get(openAICompletionInput);
214-
return { body: response.content.trim() };
215-
}
216-
});
202+
const { app, input } = require("@azure/functions");
203+
204+
const openAICompletionInput = input.generic({
205+
prompt: 'Who is {name}?',
206+
maxTokens: '100',
207+
type: 'textCompletion',
208+
model: '%CHAT_MODEL_DEPLOYMENT_NAME%'
209+
});
210+
app.http('whois', {
211+
methods: ['GET'],
212+
route: 'whois/{name}',
213+
authLevel: 'anonymous',
214+
extraInputs: [openAICompletionInput],
215+
handler: async (request, context) => {
216+
var response = context.extraInputs.get(openAICompletionInput);
217+
return { body: response.content.trim() };
218+
}
219+
});
217220
```
218221

219222
:::zone-end
@@ -249,10 +252,13 @@ The code you add creates a `whois` HTTP function endpoint in your existing proje
249252

250253
## 6. Run the function
251254

252-
<!--- 1. Install and start Azurite for local development storage. For instructions on how to work with Azurite: https://learn.microsoft.com/azure/storage/common/storage-use-azurite
253-
-->
255+
1. In a Terminal window, run the following command to start the Azurite storage emulator in a separate process:
256+
257+
```cmd
258+
start azurite
259+
```
254260

255-
1. As in the previous article, press <kbd>F5</kbd> to start the function app project and Core Tools.
261+
1. Press <kbd>F5</kbd> to start the function app project and Core Tools in debug mode.
256262

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

@@ -272,7 +278,7 @@ The code you add creates a `whois` HTTP function endpoint in your existing proje
272278
## 9. Deploy to Azure
273279
-->
274280

275-
## Clean up resources
281+
## 7. Clean up resources
276282

277283
In Azure, *resources* refer to function apps, functions, storage accounts, and so forth. They're grouped into *resource groups*, and you can delete everything in a group by deleting the group.
278284

0 commit comments

Comments
 (0)