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/app-service/deploy-intelligent-apps-dotnet-to-azure-sql.md
+10-10Lines changed: 10 additions & 10 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: 'Deploy a .NET Blazor app connected to Azure SQL and Azure OpenAI on Azure App Service'
3
3
description: Get started connecting Azure SQL to your OpenAI app
4
-
author: jefmarti
4
+
author: jeffwmartinez
5
5
ms.author: jefmarti
6
6
ms.date: 02/10/2025
7
7
ms.topic: article
@@ -15,13 +15,13 @@ When creating intelligent apps, you may want to ground the context of your app u
15
15
16
16
In this tutorial, you'll create a RAG sample application by setting up a Hybrid vector search against your Azure SQL database using a .NET 8 Blazor app. This example builds from the previous documentation to deploy a [.NET Blazor app with OpenAI](/azure/app-service/deploy-intelligent-apps?pivots=openai-dotnet).
17
17
18
-
####Prerequisites
18
+
## Prerequisites
19
19
20
20
- An [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/quickstart?pivots=programming-language-csharp&tabs=command-line%2Ckeyless%2Ctypescript-keyless%2Cpython#set-up) resource with deployed models
21
21
- A .NET 8 or 9 Blazor Web App deployed on App Service
22
22
- An Azure SQL database resource with vector embeddings.
23
23
24
-
###Set up Blazor web app
24
+
##1. Set up Blazor web app
25
25
26
26
For this example, we're creating a simple chat box to interact with. If you're using the prerequisite .NET Blazor app from the [previous article](/azure/app-service/deploy-intelligent-apps?pivots=openai-dotnet), you can skip the changes to the *OpenAI.razor* file as the content is the same. However, you need to make sure the following packages are installed:
27
27
@@ -61,7 +61,7 @@ Install the following packages to interact with Azure OpenAI and Azure SQL.
61
61
62
62
Using the Azure OpenAI resource requires the use of API keys and endpoint values. See the documentation in the previous article for setting up [Azure Key Vault references](/azure/app-service/deploy-intelligent-apps?pivots=openai-dotnet#api-keys-and-endpoints) to manage and handle your secrets with Azure OpenAI. Although not required, we do recommend using managed identity to secure your client without the need to manage API keys. See the previous [documentation](/azure/app-service/deploy-intelligent-apps?pivots=openai-dotnet#secure-your-app-with-managed-identity) to set up your Azure OpenAI client in the next step to use managed identity with Azure OpenAI.
63
63
64
-
###Add Azure OpenAI client
64
+
##2. Add Azure OpenAI client
65
65
66
66
After adding the chat interface, we can set up the Azure OpenAI client using Semantic Kernel. Add the following code to create the client that connects to your Azure OpenAI resource. You need to use your Azure OpenAI API keys and endpoint information that were set up and handled in the previous step.
67
67
@@ -129,19 +129,19 @@ After adding the chat interface, we can set up the Azure OpenAI client using Sem
129
129
130
130
Fromhere, youshouldhaveaworkingchatapplicationthatisconnectedtoOpenAI. Next, we'll set up our Azure SQL database to work with our chat application.
131
131
132
-
### Deploy Azure OpenAI models
132
+
## 3. Deploy Azure OpenAI models
133
133
134
-
InordertoprepareyourAzureSQLdatabaseforvectorsearch, youneedtomakeuseofanembeddingmodeltogenerateembeddingsusedforsearchinginadditiontoyourinitialdeployedchatmodel. Forthisexample, we're using the following models:
134
+
InordertoprepareyourAzureSQLdatabaseforvectorsearch, youneedtomakeuseofanembeddingmodeltogenerateembeddingsusedforsearchinginadditiontoyourinitialdeployedlanguagemodel. Forthisexample, we're using the following models:
Thesetwomodelsneedtobedeployedbeforecontinuingthenextstep. Visitthe [documentation](https://learn.microsoft.com/azure/ai-studio/how-to/deploy-models-openai) for deploying models with Azure OpenAI using Azure AI Foundry.
139
139
140
-
### Vectorize your SQL database
140
+
## 4. Vectorize your SQL database
141
141
142
142
ToperformahybridvectorsearchonyourAzureSQLdatabase, youfirstneedtohavetheappropriateembeddingsinyourdatabase. Therearemanywaysyoucanvectorizeyourdatabase. Oneoptionistousethefollowing [AzureSQLdatabasevectorizer](https://github.com/Azure-Samples/azure-sql-db-vectorizer) to generate embeddings for your SQL database. Vectorize your Azure SQL database before continuing.
143
143
144
-
### Create procedure to generate embeddings
144
+
## 5. Create procedure to generate embeddings
145
145
146
146
With [AzureSQLvectorsupport (preview)](https://devblogs.microsoft.com/azure-sql/announcing-eap-native-vector-support-in-azure-sql-database/), you can create a stored procedure that will use a Vector data type to store generated embeddings for search queries. The stored procedure invokes an external REST API endpoint to get the embeddings. See the [documentation](https://learn.microsoft.com/azure-data-studio/quickstart-sql-database) to use Azure Data Studio to connect to your database before running the query.
147
147
@@ -181,7 +181,7 @@ GO
181
181
182
182
Aftercreatingyourstoredprocedure, youshouldbeabletoviewitunderthe**StoredProcedures**folderfoundinthe**Programmability**folderofyourSQLdatabase. Oncecreated, youcanrunatest [similaritysearch](https://devblogs.microsoft.com/azure-sql/announcing-eap-native-vector-support-in-azure-sql-database/#similarity-search-in-azure-sql-db) within your SQL query editor using your text embedding model name. This uses your stored procedure to generate embeddings and use a vector distance function to calculate the vector distance and return results based on the text query.
Copy file name to clipboardExpand all lines: articles/app-service/includes/deploy-intelligent-apps/deploy-intelligent-apps-linux-dotnet-pivot.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,12 +10,12 @@ ms.author: jefmarti
10
10
11
11
You can use Azure App Service to work with popular AI frameworks like LangChain and Semantic Kernel connected to OpenAI for creating intelligent apps. In the following tutorial, we're adding an Azure OpenAI service using Semantic Kernel to a .NET 8 Blazor web application.
12
12
13
-
####Prerequisites
13
+
## Prerequisites
14
14
15
15
- An [Azure OpenAI resource](/azure/ai-services/openai/quickstart?pivots=programming-language-csharp&tabs=command-line%2Cpython#set-up) or an [OpenAI account](https://platform.openai.com/overview).
16
16
- A .NET 8 Blazor Web App. Create the application with a template [here](https://dotnet.microsoft.com/learn/aspnet/blazor-tutorial/intro).
17
17
18
-
###Setup Blazor web app
18
+
##1. Setup Blazor web app
19
19
20
20
For this Blazor web application, we're building off the Blazor [template](https://dotnet.microsoft.com/learn/aspnet/blazor-tutorial/intro) and creating a new razor page that can send and receive requests to an Azure OpenAI OR OpenAI service using Semantic Kernel.
21
21
@@ -128,7 +128,7 @@ For OpenAI:
128
128
}
129
129
```
130
130
131
-
### Semantic Kernel
131
+
## 2. Semantic Kernel
132
132
133
133
Semantic Kernel is an open-source SDK that enables you to easily develop AI agents to work with your existing code. You can use Semantic Kernel with Azure OpenAI and OpenAI models.
134
134
@@ -137,7 +137,7 @@ To create the OpenAI client, we'll first start by installing Semantic Kernel.
137
137
ToinstallSemanticKernel, browsetheNuGetpackagemanagerinVisualStudioandinstallthe **Microsoft.SemanticKernel** package. ForNuGetPackageManagerinstructions, see [here](/nuget/consume-packages/install-use-packages-visual-studio#find-and-install-a-package). ForCLIinstructions, see [here](/nuget/consume-packages/install-use-packages-dotnet-cli).
@@ -159,7 +159,7 @@ To initialize the Kernel, add the following code to the *OpenAI.razor* file.
159
159
160
160
Here we're adding the using statement and creating the Kernel in a method that we can use when we send the request to the service.
161
161
162
-
###Add your AI service
162
+
##4. Add your AI service
163
163
164
164
Once the Kernel is initialized, we can add our chosen AI service to the kernel. Here we define our model and pass in our key and endpoint information to be consumed by the chosen model. If you plan to use managed identity with Azure OpenAI, add the service using the example in the next section.
165
165
@@ -225,7 +225,7 @@ Once the credentials are added to the application, you'll then need to enable ma
225
225
226
226
Your web app is now added as a cognitive service OpenAI user and can communicate to your Azure OpenAI resource.
227
227
228
-
###Configure prompt and create semantic function
228
+
##5. Configure prompt and create semantic function
229
229
230
230
Now that our chosen OpenAI service client is created with the correct keys we can add a function to handle the prompt. With Semantic Kernel you can handle prompts by the use of a semantic function, which turn the prompt and the prompt configuration settings into a function the Kernel can execute. Learn more on configuring prompts [here](/semantic-kernel/prompts/configure-prompts?tabs=Csharp).
231
231
@@ -348,7 +348,7 @@ Here's the example in its completed form. In this example, use the Azure OpenAI
348
348
349
349
Now save the application and follow the next steps to deploy it to App Service. If you would like to test it locally first at this step, you can swap out the config values at with the literal string values of your OpenAI service. For example: string modelId = 'gpt-4-turbo';
350
350
351
-
###Deploy to App Service
351
+
##5. Deploy to App Service
352
352
353
353
If you have followed the steps above, you're ready to deploy to App Service. If you run into any issues remember that you need to have done the following: grant your app access to your Key Vault, add the app settings with key vault references as your values. App Service resolves the app settings in your application that match what you've added in the portal.
354
354
@@ -357,3 +357,9 @@ If you have followed the steps above, you're ready to deploy to App Service. If
357
357
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).
358
358
359
359
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.
360
+
361
+
## Next step
362
+
363
+
> [!div class="nextstepaction"]
364
+
> [Deploy a .NET Blazor app connected to Azure SQL and Azure OpenAI on Azure App Service](/azure/app-service/deploy-intelligent-apps-dotnet-to-azure-sql.md)
0 commit comments