Skip to content

Commit e468239

Browse files
authored
Update MEAI versions in snippets (#45759)
1 parent 10db4ab commit e468239

File tree

33 files changed

+119
-122
lines changed

33 files changed

+119
-122
lines changed

docs/ai/how-to/snippets/content-filtering/AIContentFiltering.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<ItemGroup>
1111
<PackageReference Include="Azure.AI.OpenAI" />
1212
<PackageReference Include="Azure.Identity" Version="1.13.2" />
13-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
14-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
13+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.4.0-preview.1.25207.5" />
14+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.0-preview.1.25207.5" />
1515
</ItemGroup>
1616

1717
</Project>

docs/ai/how-to/snippets/content-filtering/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
IChatClient client =
66
new AzureOpenAIClient(
77
new Uri("YOUR_MODEL_ENDPOINT"),
8-
new DefaultAzureCredential()).AsChatClient("YOUR_MODEL_DEPLOYMENT_NAME");
8+
new DefaultAzureCredential()).GetChatClient("YOUR_MODEL_DEPLOYMENT_NAME").AsIChatClient();
99

1010
try
1111
{

docs/ai/how-to/snippets/hosted-app-auth/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
builder.Services.AddChatClient(
2828
new AzureOpenAIClient(new Uri(endpoint), credential)
29-
.AsChatClient(deployment));
29+
.GetChatClient(deployment)
30+
.AsIChatClient());
3031

3132
var app = builder.Build();
3233

docs/ai/how-to/snippets/hosted-app-auth/hosted-app-auth.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
1212
<PackageReference Include="Azure.Identity" Version="1.13.2" />
1313
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.4" />
14-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
15-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
14+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.4.0-preview.1.25207.5" />
15+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.0-preview.1.25207.5" />
1616
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.11.0" />
1717
</ItemGroup>
1818

docs/ai/quickstarts/ai-templates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ zone_pivot_groups: meai-targets
1111

1212
# Create a .NET AI app to chat with custom data using the AI app template extensions
1313

14-
In this quickstart, you learn how to create a .NET AI app to chat with custom data using the .NET AI app template. The template is designed to streamline the getting started experience for building AI apps with .NET by handling common setup tasks and configurations for you.
14+
In this quickstart, you learn how to create a .NET AI app to chat with custom data using the .NET AI app template. The template is designed to streamline the getting started experience for building AI apps with .NET by handling common setup tasks and configurations for you.
1515

1616
:::zone target="docs" pivot="github-models"
1717

docs/ai/quickstarts/snippets/build-chat-app/azure-openai/ChatAppAI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<ItemGroup>
1212
<PackageReference Include="Azure.Identity" Version="1.13.2" />
1313
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
14-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
14+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.0-preview.1.25207.5" />
1515
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.4" />
1616
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.4" />
1717

1818
</ItemGroup>
19-
19+
2020
</Project>

docs/ai/quickstarts/snippets/build-chat-app/azure-openai/Program.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
using Azure.AI.OpenAI;
44
using Azure.Identity;
55

6-
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
6+
IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
77
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
88
string deployment = config["AZURE_OPENAI_GPT_NAME"];
99

1010
IChatClient chatClient =
1111
new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
12-
.AsChatClient(deployment);
12+
.GetChatClient(deployment)
13+
.AsIChatClient();
1314

1415
// Start the conversation with context for the AI model
15-
List<ChatMessage> chatHistory = new()
16-
{
16+
List<ChatMessage> chatHistory =
17+
[
1718
new ChatMessage(ChatRole.System, """
1819
You are a friendly hiking enthusiast who helps people discover fun hikes in their area.
1920
You introduce yourself when first saying hello.
@@ -28,19 +29,19 @@ after you get that information. You will also share an interesting fact about
2829
the local nature on the hikes when making a recommendation. At the end of your
2930
response, ask if there is anything else you can help with.
3031
""")
31-
};
32+
];
3233

3334
while (true)
3435
{
3536
// Get user prompt and add to chat history
3637
Console.WriteLine("Your prompt:");
37-
var userPrompt = Console.ReadLine();
38+
string? userPrompt = Console.ReadLine();
3839
chatHistory.Add(new ChatMessage(ChatRole.User, userPrompt));
3940

4041
// Stream the AI response and add to chat history
4142
Console.WriteLine("AI Response:");
42-
var response = "";
43-
await foreach (var item in
43+
string response = "";
44+
await foreach (ChatResponseUpdate item in
4445
chatClient.GetStreamingResponseAsync(chatHistory))
4546
{
4647
Console.Write(item.Text);

docs/ai/quickstarts/snippets/build-chat-app/openai/ExtensionsOpenAI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
11+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.0-preview.1.25207.5" />
1212
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.4" />
1313
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.4" />
1414
</ItemGroup>
15-
15+
1616
</Project>

docs/ai/quickstarts/snippets/build-chat-app/openai/Program.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
// Create the IChatClient
1010
IChatClient chatClient =
11-
new OpenAIClient(key).AsChatClient(model);
11+
new OpenAIClient(key).GetChatClient(model).AsIChatClient();
1212

1313
// Start the conversation with context for the AI model
14-
List<ChatMessage> chatHistory = new()
15-
{
14+
List<ChatMessage> chatHistory =
15+
[
1616
new ChatMessage(ChatRole.System, """
1717
You are a friendly hiking enthusiast who helps people discover fun hikes in their area.
1818
You introduce yourself when first saying hello.
@@ -27,19 +27,19 @@ after you get that information. You will also share an interesting fact about
2727
the local nature on the hikes when making a recommendation. At the end of your
2828
response, ask if there is anything else you can help with.
2929
""")
30-
};
30+
];
3131

3232
while (true)
3333
{
3434
// Get user prompt and add to chat history
3535
Console.WriteLine("Your prompt:");
36-
var userPrompt = Console.ReadLine();
36+
string? userPrompt = Console.ReadLine();
3737
chatHistory.Add(new ChatMessage(ChatRole.User, userPrompt));
3838

3939
// Stream the AI response and add to chat history
4040
Console.WriteLine("AI Response:");
41-
var response = "";
42-
await foreach (var item in
41+
string response = "";
42+
await foreach (ChatResponseUpdate item in
4343
chatClient.GetStreamingResponseAsync(chatHistory))
4444
{
4545
Console.Write(item.Text);

docs/ai/quickstarts/snippets/chat-with-data/azure-openai/Program.cs

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,65 +7,59 @@
77
using VectorDataAI;
88

99
// <SnippetDataSet>
10-
var cloudServices = new List<CloudService>()
11-
{
12-
new CloudService
13-
{
14-
Key=0,
15-
Name="Azure App Service",
16-
Description="Host .NET, Java, Node.js, and Python web applications and APIs in a fully managed Azure service. You only need to deploy your code to Azure. Azure takes care of all the infrastructure management like high availability, load balancing, and autoscaling."
17-
},
18-
new CloudService
19-
{
20-
Key=1,
21-
Name="Azure Service Bus",
22-
Description="A fully managed enterprise message broker supporting both point to point and publish-subscribe integrations. It's ideal for building decoupled applications, queue-based load leveling, or facilitating communication between microservices."
23-
},
24-
new CloudService
25-
{
26-
Key=2,
27-
Name="Azure Blob Storage",
28-
Description="Azure Blob Storage allows your applications to store and retrieve files in the cloud. Azure Storage is highly scalable to store massive amounts of data and data is stored redundantly to ensure high availability."
29-
},
30-
new CloudService
31-
{
32-
Key=3,
33-
Name="Microsoft Entra ID",
34-
Description="Manage user identities and control access to your apps, data, and resources.."
35-
},
36-
new CloudService
37-
{
38-
Key=4,
39-
Name="Azure Key Vault",
40-
Description="Store and access application secrets like connection strings and API keys in an encrypted vault with restricted access to make sure your secrets and your application aren't compromised."
41-
},
42-
new CloudService
43-
{
44-
Key=5,
45-
Name="Azure AI Search",
46-
Description="Information retrieval at scale for traditional and conversational search applications, with security and options for AI enrichment and vectorization."
47-
}
48-
};
10+
List<CloudService> cloudServices =
11+
[
12+
new() {
13+
Key = 0,
14+
Name = "Azure App Service",
15+
Description = "Host .NET, Java, Node.js, and Python web applications and APIs in a fully managed Azure service. You only need to deploy your code to Azure. Azure takes care of all the infrastructure management like high availability, load balancing, and autoscaling."
16+
},
17+
new() {
18+
Key = 1,
19+
Name = "Azure Service Bus",
20+
Description = "A fully managed enterprise message broker supporting both point to point and publish-subscribe integrations. It's ideal for building decoupled applications, queue-based load leveling, or facilitating communication between microservices."
21+
},
22+
new() {
23+
Key = 2,
24+
Name = "Azure Blob Storage",
25+
Description = "Azure Blob Storage allows your applications to store and retrieve files in the cloud. Azure Storage is highly scalable to store massive amounts of data and data is stored redundantly to ensure high availability."
26+
},
27+
new() {
28+
Key = 3,
29+
Name = "Microsoft Entra ID",
30+
Description = "Manage user identities and control access to your apps, data, and resources."
31+
},
32+
new() {
33+
Key = 4,
34+
Name = "Azure Key Vault",
35+
Description = "Store and access application secrets like connection strings and API keys in an encrypted vault with restricted access to make sure your secrets and your application aren't compromised."
36+
},
37+
new() {
38+
Key = 5,
39+
Name = "Azure AI Search",
40+
Description = "Information retrieval at scale for traditional and conversational search applications, with security and options for AI enrichment and vectorization."
41+
}
42+
];
4943
// </SnippetDataSet>
5044

5145
// <SnippetEmbeddingGen>
5246
// Load the configuration values
53-
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
47+
IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
5448
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
5549
string model = config["AZURE_OPENAI_GPT_NAME"];
5650

5751
// Create the embedding generator
5852
IEmbeddingGenerator<string, Embedding<float>> generator =
59-
new AzureOpenAIClient(
60-
new Uri(endpoint),
61-
new DefaultAzureCredential())
62-
.AsEmbeddingGenerator(modelId: model);
53+
new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
54+
.GetEmbeddingClient(deploymentName: model)
55+
.AsIEmbeddingGenerator();
6356
// </SnippetEmbeddingGen>
6457

6558
// <SnippetVectorStore>
6659
// Create and populate the vector store
6760
var vectorStore = new InMemoryVectorStore();
68-
Microsoft.Extensions.VectorData.IVectorStoreRecordCollection<int, CloudService> cloudServicesStore = vectorStore.GetCollection<int, CloudService>("cloudServices");
61+
IVectorStoreRecordCollection<int, CloudService> cloudServicesStore =
62+
vectorStore.GetCollection<int, CloudService>("cloudServices");
6963
await cloudServicesStore.CreateCollectionIfNotExistsAsync();
7064

7165
foreach (CloudService service in cloudServices)
@@ -82,9 +76,9 @@
8276

8377
VectorSearchResults<CloudService> results =
8478
await cloudServicesStore.VectorizedSearchAsync(queryEmbedding, new VectorSearchOptions<CloudService>()
85-
{
86-
Top = 1
87-
});
79+
{
80+
Top = 1
81+
});
8882

8983
await foreach (VectorSearchResult<CloudService> result in results.Results)
9084
{

0 commit comments

Comments
 (0)