Skip to content

Commit

Permalink
Update Azure AI Search and OpenAI client configuration for resource r…
Browse files Browse the repository at this point in the history
…euse
  • Loading branch information
elbruno committed Dec 17, 2024
1 parent 68b3d6e commit cdce087
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ You can also open the Azure AI Search resource in the Azure portal, and check th
![Azure AI Search resource in the Azure portal, and check the created index **products** with the data and fields](./images/48AzureAISearchIndex.png)
### Local development using an existing services
In order to use existing Azure AI Search services and existing Azure OpenAI models: gpt-4o-mini and text-embedding-ada-002, you need to make changes in 2 projects:
In order to use existing **Azure AI Search Services** and existing **Azure OpenAI models**, like gpt-4o-mini and text-embedding-ada-002, you need to make changes in 2 projects:
#### Aspire AppHost
Expand All @@ -217,29 +216,27 @@ dotnet user-secrets set "ConnectionStrings:openaidev" "Endpoint=https://<endpoin
dotnet user-secrets set "ConnectionStrings:azureaisearchdev" "Endpoint=https://<endpoint>.search.windows.net/;Key=<Azure AI Search key>;"
```
In Debug mode, the `Products` project by default uses the User Secrets connections strings to connect to Azure AI Search and to Azure OpenAI Models. The connection strings names are `azureaisearchdev` and `openaidev`.
If you want to use the services provided by the `AppHost`, open the the `program.cs`, and change this:
Update the code to use connection strings which names are `azureaisearchdev` and `openaidev`. Change this:
```csharp
// Add Azure AI Search client
var azureAiSearchName = builder.Environment.IsDevelopment() ? "azureaisearchdev" : "azureaisearch";
// To reuse existing Azure AI Search resources, this to "azureaisearchdev", and check the documentation on how to reuse the resources
var azureAiSearchName = "azureaisearch";
builder.AddAzureSearchClient(azureAiSearchName);
// Add Azure OpenAI client
var azureOpenAiClientName = builder.Environment.IsDevelopment() ? "openaidev" : "openai";
// To reuse existing Azure OpenAI resources, this to "openaidev", and check the documentation on how to reuse the resources
var azureOpenAiClientName = "openai";
builder.AddAzureOpenAIClient(azureOpenAiClientName);
```
to this:
```csharp
// Add Azure AI Search client
var azureAiSearchName = "azureaisearch";
// To reuse existing Azure AI Search resources, this to "azureaisearchdev", and check the documentation on how to reuse the resources
var azureAiSearchName = "azureaisearchdev";
builder.AddAzureSearchClient(azureAiSearchName);
// Add Azure OpenAI client
var azureOpenAiClientName = "openai";
// To reuse existing Azure OpenAI resources, this to "openaidev", and check the documentation on how to reuse the resources
var azureOpenAiClientName = "openaidev";
builder.AddAzureOpenAIClient(azureOpenAiClientName);
```
Expand Down Expand Up @@ -296,4 +293,7 @@ You may want to consider additional security measures, such as:
### Video Recordings
- Coming soon!
**Coming Soon >>**
[Run eShopLite Semantic Search - Azure AI Search in Minutes with .NET Aspire & GitHub Codespaces 🚀](https://youtu.be/T9HwjVIDPAE)
[![Run eShopLite Semantic Search in Minutes with .NET Aspire & GitHub Codespaces 🚀](./images/90ytrunfromcodespaces.png)](https://youtu.be/T9HwjVIDPAE)
Binary file added images/90ytrunfromcodespaces.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/Products/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
// Add DbContext service
builder.AddSqlServerDbContext<Context>("sqldb");

// Add Azure AI Search client
var azureAiSearchName = builder.Environment.IsDevelopment() ? "azureaisearchdev" : "azureaisearch";
// To reuse existing Azure AI Search resources, this to "azureaisearchdev", and check the documentation on how to reuse the resources
var azureAiSearchName = "azureaisearch";
builder.AddAzureSearchClient(azureAiSearchName);

// Add Azure OpenAI client
var azureOpenAiClientName = builder.Environment.IsDevelopment() ? "openaidev" : "openai";
// To reuse existing Azure OpenAI resources, this to "openaidev", and check the documentation on how to reuse the resources
var azureOpenAiClientName = "openai";
builder.AddAzureOpenAIClient(azureOpenAiClientName);

// get azure openai client and create Chat client from aspire hosting configuration
Expand Down

0 comments on commit cdce087

Please sign in to comment.