Skip to content
This repository was archived by the owner on Jul 10, 2026. It is now read-only.

Commit 81a4995

Browse files
committed
Add independent config for AzureOpenAI embedding service
Separated embedding service configuration from chat service by introducing `Endpoint` and `ApiKey` properties in `AzureOpenAIEmbeddingSettings`. Updated `Program.cs`, `AISearchService.cs`, and `AIService.cs` to use these new properties for embedding-specific functionality. Added `Endpoint` and `ApiKey` to the `AzureOpenAIEmbedding` section in `appsettings.json` and updated `main.bicep` to support deployment of these properties. Updated `readme.md` to document the new embedding service configuration, clarifying that it can use the same or a different endpoint and API key as the chat service.
1 parent 19b653d commit 81a4995

7 files changed

Lines changed: 23 additions & 8 deletions

File tree

BlazorAIChat/Models/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class AzureOpenAIChatCompletionSettings
3838

3939
public class AzureOpenAIEmbeddingSettings
4040
{
41+
public string Endpoint { get; set; } = string.Empty;
42+
public string ApiKey { get; set; } = string.Empty;
4143
public string DeploymentName { get; set; } = string.Empty;
4244
public string Tokenizer { get; set; } = string.Empty;
4345
public int MaxInputTokens { get; set; } = 8192;

BlazorAIChat/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@
143143
httpClient: httpClient)
144144
.AddAzureOpenAIEmbeddingGenerator(
145145
appSettings.AzureOpenAIEmbedding.DeploymentName,
146-
appSettings.AzureOpenAIChatCompletion.Endpoint,
147-
appSettings.AzureOpenAIChatCompletion.ApiKey,
146+
appSettings.AzureOpenAIEmbedding.Endpoint,
147+
appSettings.AzureOpenAIEmbedding.ApiKey,
148148
httpClient: httpClient);
149149

150150
kernelBuilder.Services.AddLogging(services => services.AddConsole().SetMinimumLevel(LogLevel.Trace));

BlazorAIChat/Services/AISearchService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public async Task SetupAndRunIndexer()
109109
)
110110
{
111111
Context = "/document/pages/*",
112-
ResourceUri = new Uri(settings.AzureOpenAIChatCompletion.Endpoint),
113-
ApiKey = settings.AzureOpenAIChatCompletion.ApiKey,
112+
ResourceUri = new Uri(settings.AzureOpenAIEmbedding.Endpoint),
113+
ApiKey = settings.AzureOpenAIEmbedding.ApiKey,
114114
DeploymentName = settings.AzureOpenAIEmbedding.DeploymentName,
115115
ModelName = settings.AzureOpenAIEmbedding.DeploymentName
116116
}
@@ -204,8 +204,8 @@ private SearchIndex GetSampleIndex()
204204
{
205205
Parameters = new AzureOpenAIVectorizerParameters()
206206
{
207-
ResourceUri = new Uri(settings.AzureOpenAIChatCompletion.Endpoint),
208-
ApiKey = settings.AzureOpenAIChatCompletion.ApiKey,
207+
ResourceUri = new Uri(settings.AzureOpenAIEmbedding.Endpoint),
208+
ApiKey = settings.AzureOpenAIEmbedding.ApiKey,
209209
DeploymentName = settings.AzureOpenAIEmbedding.DeploymentName,
210210
ModelName = settings.AzureOpenAIEmbedding.DeploymentName
211211
}

BlazorAIChat/Services/AIService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ Analyze the question and respond with ONLY 'true' or 'false'.
223223
ArgumentNullException.ThrowIfNull(textEmbeddingGenerationService);
224224

225225
var kernelMemoryBuilder = new KernelMemoryBuilder()
226-
.WithAzureOpenAITextEmbeddingGeneration(new AzureOpenAIConfig() { Auth = AzureOpenAIConfig.AuthTypes.APIKey, APIKey = settings.AzureOpenAIChatCompletion.ApiKey, Deployment = settings.AzureOpenAIEmbedding.DeploymentName, Endpoint = settings.AzureOpenAIChatCompletion.Endpoint }, embeddingTokenizer, httpClient: httpClient)
226+
.WithAzureOpenAITextEmbeddingGeneration(new AzureOpenAIConfig() { Auth = AzureOpenAIConfig.AuthTypes.APIKey, APIKey = settings.AzureOpenAIEmbedding.ApiKey, Deployment = settings.AzureOpenAIEmbedding.DeploymentName, Endpoint = settings.AzureOpenAIEmbedding.Endpoint }, embeddingTokenizer, httpClient: httpClient)
227227
.WithAzureOpenAITextGeneration(new AzureOpenAIConfig() { Auth = AzureOpenAIConfig.AuthTypes.APIKey, APIKey = settings.AzureOpenAIChatCompletion.ApiKey, Deployment = settings.AzureOpenAIChatCompletion.DeploymentName, Endpoint = settings.AzureOpenAIChatCompletion.Endpoint }, chatCompletionTokenizer, httpClient);
228228

229229
if (settings.UsesAzureAISearch && settings.AzureAISearch.IndexPerChatSession)

BlazorAIChat/appsettings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"ResponseChunkSize": 40
1818
},
1919
"AzureOpenAIEmbedding": {
20+
"Endpoint": "",
21+
"ApiKey": "",
2022
"DeploymentName": "",
2123
"Tokenizer": "gpt-4o",
2224
"MaxInputTokens": 8192

Infra/main.bicep

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ resource appService 'Microsoft.Web/sites@2020-06-01' = {
6666
name: 'AzureOpenAIChatCompletion__SupportsImages'
6767
value: aiChatModelSupportsImages ? 'true' : 'false'
6868
}
69+
{
70+
name: 'AzureOpenAIEmbedding__Endpoint'
71+
value: openAiService.properties.endpoint
72+
}
73+
{
74+
name: 'AzureOpenAIEmbedding__ApiKey'
75+
value: openAiService.listKeys().key1
76+
}
6977
{
7078
name: 'AzureOpenAIEmbedding__DeploymentName'
7179
value: toLower('${aiEmbedModelName}')

readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ The appsettings.json file has a few configuration parameters that must be set fo
7272
"ResponseChunkSize": 40
7373
},
7474
"AzureOpenAIEmbedding": {
75+
"Endpoint": "",
76+
"ApiKey": "",
7577
"DeploymentName": "",
7678
"Tokenizer": "",
7779
"MaxInputTokens": 8192
@@ -167,10 +169,11 @@ The appsettings.json file has a few configuration parameters that must be set fo
167169
- `ResponseChunkSize` defines the number of response chunks from the Azure OpenAI service that need to be received before the UI is updated. The higher the number, the less UI updates are required, which improves the Blazor app performance.
168170

169171
- AzureOpenAIEmbedding Configuration:
172+
- Include your Azure OpenAI endpoint URL and API Key for the embedding service.
170173
- Specify the deployed embedding model you plan to use.
171174
- Specify the tokenizer to use. Generally this is the model name (not deployment name)
172175
- Specify the maximum input tokens the selected model supports
173-
- Both the chat and embedding models are assumed to be accessed through the same Azure OpenAI endpoint and API key.
176+
- The embedding model can use the same or a different Azure OpenAI endpoint and API key as the chat model.
174177

175178
- PostgreSQL (optional):
176179
- If you would like to use PostgreSQL in place of files for knowledge storage, you must manually deploy a PostgreSQL instance and configure the connection string. Note: You must enable the pgvector extension to use PostgreSQL.

0 commit comments

Comments
 (0)