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
- A Node.js Express application. Create the sample app using our [quickstart](/azure/app-service/quickstart-nodejs?tabs=linux&pivots=development-environment-vscode).
17
17
18
18
### Set up web app
19
19
20
-
For this application, we’re building off the [quickstart](/azure/app-service/quickstart-nodejs?tabs=linux&pivots=development-environment-vscode) Express app and adding an extra feature to make a request to an Azure OpenAI or OpenAI service.
20
+
For this application, we're building off the [quickstart](/azure/app-service/quickstart-nodejs?tabs=linux&pivots=development-environment-vscode) Express app and adding an extra feature to make a request to an Azure OpenAI or OpenAI service.
21
21
22
22
First, copy and replace the `index.ejs` file with the following code:
23
23
@@ -48,7 +48,7 @@ The previous code will add an input box to our index page to submit requests to
48
48
49
49
First, you need to grab the keys and endpoint values from Azure OpenAI, or OpenAI and add them as secrets for use in your application. Retrieve and save the values for later use to build the client.
50
50
51
-
For Azure OpenAI, see[this documentation](/azure/ai-services/openai/quickstart?pivots=programming-language-csharp&tabs=command-line%2Cpython#retrieve-key-and-endpoint) to retrieve the key and endpoint values. If you’re planning to use managed identity to secure your app you’ll only need the `deploymentName` and `apiVersion` values.
51
+
For Azure OpenAI, see[this documentation](/azure/ai-services/openai/quickstart?pivots=programming-language-csharp&tabs=command-line%2Cpython#retrieve-key-and-endpoint) to retrieve the key and endpoint values. If you're planning to use managed identity to secure your app you'll only need the `deploymentName` and `apiVersion` values.
52
52
53
53
Otherwise, you need each of the following:
54
54
@@ -63,9 +63,9 @@ For OpenAI, see this documentation to retrieve the API keys. For our application
63
63
64
64
-`apiKey`
65
65
66
-
Since we're deploying to App Service, we can secure these secrets in **Azure Key Vault** for protection. Follow the[Quickstart](/azure/key-vault/secrets/quick-create-cli#create-a-key-vault) to set up your Key Vault and add the secrets you saved from earlier.
66
+
Since we're deploying to App Service, we can secure these secrets in **Azure Key Vault** for protection. Follow the[Quickstart](/azure/key-vault/secrets/quick-create-cli#create-a-key-vault) to set up your Key Vault and add the secrets you saved from earlier.
67
67
68
-
Next, we can use Key Vault references as app settings in our App Service resource to reference in our application. Follow the instructions in the[documentation](../../app-service-key-vault-references.md?source=recommendations&tabs=azure-cli) to grant your app access to your Key Vault and to set up Key Vault references.
68
+
Next, we can use Key Vault references as app settings in our App Service resource to reference in our application. Follow the instructions in the[documentation](../../app-service-key-vault-references.md?source=recommendations&tabs=azure-cli) to grant your app access to your Key Vault and to set up Key Vault references.
69
69
70
70
Then, go to the portal Environment Variables page in your resource and add the following app settings:
71
71
@@ -149,7 +149,7 @@ import OpenAI from 'openai';
149
149
150
150
### Secure your app with managed identity
151
151
152
-
Although optional, it's highly recommended to secure your application using[managed identity](../../overview-managed-identity.md) to authenticate your app to your Azure OpenAI resource. Skip this step if you are not using Azure OpenAI. This enables your application to access the Azure OpenAI resource without needing to manage API keys.
152
+
Although optional, it's highly recommended to secure your application using[managed identity](../../overview-managed-identity.md) to authenticate your app to your Azure OpenAI resource. Skip this step if you are not using Azure OpenAI. This enables your application to access the Azure OpenAI resource without needing to manage API keys.
153
153
154
154
Follow the steps below to secure your application:
155
155
@@ -177,14 +177,14 @@ Create the Azure OpenAI client with the token provider.
177
177
178
178
Once the credentials are added to the application, enable managed identity in your application and grant access to the resource:
179
179
180
-
1. In your web app resource, navigate to the **Identity** blade and turn on **System assigned** and select **Save**.
180
+
1. In your web app resource, navigate to the **Identity** blade and turn on **System assigned** and select **Save**.
181
181
2. Once System assigned identity is turned on, it will register the web app with Microsoft Entra ID and the web app can be granted permissions to access protected resources.
182
-
3. Go to your Azure OpenAI resource and navigate to the **Access control (IAM)** page on the left pane.
183
-
4. Find the **Grant access to this resource** card and select **Add role assignment**.
184
-
5. Search for the **Cognitive Services OpenAI User** role and select **Next**.
185
-
6. On the **Members** tab, find **Assign access to** and choose the **Managed identity** option.
186
-
7. Next, select **+Select Members** and find your web app.
187
-
8. Select **Review + assign**.
182
+
3. Go to your Azure OpenAI resource and navigate to the **Access control (IAM)** page on the left pane.
183
+
4. Find the **Grant access to this resource** card and select **Add role assignment**.
184
+
5. Search for the **Cognitive Services OpenAI User** role and select **Next**.
185
+
6. On the **Members** tab, find **Assign access to** and choose the **Managed identity** option.
186
+
7. Next, select **+Select Members** and find your web app.
187
+
8. Select **Review + assign**.
188
188
189
189
Your web app is now added as a cognitive service OpenAI user and can communicate to your Azure OpenAI resource.
This post function will create the OpenAI client and add the message being sent to OpenAI with a returned response.
238
238
239
-
Here’s the example in it’s complete form. In this example, use the Azure OpenAI chat completion service OR the OpenAI chat completion service, not both.
239
+
Here's the example in it's complete form. In this example, use the Azure OpenAI chat completion service OR the OpenAI chat completion service, not both.
240
240
241
241
```jsx
242
242
var createError =require('http-errors');
@@ -339,6 +339,6 @@ Once the app is deployed, you can visit your site URL and see the text that cont
339
339
340
340
### Authentication
341
341
342
-
Although optional, it's highly recommended that you also add authentication to your web app when using an Azure OpenAI or OpenAI service. This can add a level of security with no other code. Learn how to enable authentication for your web app[here](../../scenario-secure-app-authentication-app-service.md).
342
+
Although optional, it's highly recommended that you also add authentication to your web app when using an Azure OpenAI or OpenAI service. This can add a level of security with no other code. Learn how to enable authentication for your web app[here](../../scenario-secure-app-authentication-app-service.md).
343
343
344
-
Once deployed, browse to the web app and navigate to the OpenAI tab. Enter a query to the service and you should see a populated response from the server. The tutorial is now complete and you now know how to use OpenAI services to create intelligent applications.
344
+
Once deployed, browse to the web app and navigate to the OpenAI tab. Enter a query to the service and you should see a populated response from the server. The tutorial is now complete and you now know how to use OpenAI services to create intelligent applications.
0 commit comments