Skip to content

Commit 893dfe3

Browse files
Merge pull request #45443 from dotnet/main
Merge main into live
2 parents aba3480 + 2cf1e6b commit 893dfe3

File tree

24 files changed

+173
-172
lines changed

24 files changed

+173
-172
lines changed

docfx.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@
686686
"_csharplang/proposals/csharp-13.0/overload-resolution-priority.md": "Overload resolution priority tiebreaker attribute",
687687
"_csharplang/proposals/field-keyword.md": "The `field` contextual keyword",
688688
"_csharplang/proposals/unbound-generic-types-in-nameof.md": "Unbound generic types in `nameof`",
689-
"_csharplang/proposals/first-class-span-types.md": "First-class span types",
689+
"_csharplang/proposals/first-class-span-types.md": "First-class span types",
690690
"_csharplang/proposals/simple-lambda-parameters-with-modifiers.md": "Simple lambda parameters with modifiers",
691691
"_csharplang/proposals/partial-events-and-constructors.md": "Partial events and constructors",
692692
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md": "C# compiler breaking changes since C# 10",
@@ -878,7 +878,6 @@
878878
"docs/standard/design-guidelines/**.md": false
879879
},
880880
"ms.custom": {
881-
"docs/ai/**/**.md": "build-2024-intelligent-apps",
882881
"docs/framework/**/*.md": "UpdateFrequency5",
883882
"docs/visual-basic/**/*.md": "UpdateFrequency5"
884883
},

docs/ai/conceptual/evaluation-libraries.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: The Microsoft.Extensions.AI.Evaluation libraries
33
description: Learn about the Microsoft.Extensions.AI.Evaluation libraries, which simplify the process of evaluating the quality and accuracy of responses generated by AI models in .NET intelligent apps.
44
ms.topic: concept-article
5-
ms.date: 02/19/2025
5+
ms.date: 03/18/2025
66
---
77
# The Microsoft.Extensions.AI.Evaluation libraries (Preview)
88

@@ -44,7 +44,7 @@ The library contains support for storing evaluation results and generating repor
4444

4545
:::image type="content" source="../media/ai-extensions/pipeline-report.jpg" lightbox="../media/ai-extensions/pipeline-report.jpg" alt-text="Screenshot of an AI evaluation report in an Azure DevOps pipeline.":::
4646

47-
The `dotnet aieval` tool, which ships as part of the `Microsoft.Extensions.AI.Evaluation.Console` package, also includes functionality for generating reports and managing the stored evaluation data and cached responses.
47+
The `dotnet aieval` tool, which ships as part of the `Microsoft.Extensions.AI.Evaluation.Console` package, includes functionality for generating reports and managing the stored evaluation data and cached responses. For more information, see [Generate a report](../tutorials/evaluate-with-reporting.md#generate-a-report).
4848

4949
## Configuration
5050

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.3" />
1414
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
1515
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
16-
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.10.0" />
16+
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.11.0" />
1717
</ItemGroup>
1818

1919
</Project>
Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,26 @@
11
---
22
title: Quickstart - Evaluate a model's response
33
description: Learn how to create an MSTest app to evaluate the AI chat response of a language model.
4-
ms.date: 02/25/2025
4+
ms.date: 03/18/2025
55
ms.topic: quickstart
66
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
77
---
88

99
# Evaluate a model's response
1010

11-
In this quickstart, you create an MSTest app to evaluate the chat response of a model. The test app uses the [Microsoft.Extensions.AI.Evaluation](https://www.nuget.org/packages/Microsoft.Extensions.AI.Evaluation) libraries.
11+
In this quickstart, you create an MSTest app to evaluate the chat response of an OpenAI model. The test app uses the [Microsoft.Extensions.AI.Evaluation](https://www.nuget.org/packages/Microsoft.Extensions.AI.Evaluation) libraries.
1212

1313
> [!NOTE]
1414
> This quickstart demonstrates the simplest usage of the evaluation API. Notably, it doesn't demonstrate use of the [response caching](../conceptual/evaluation-libraries.md#cached-responses) and [reporting](../conceptual/evaluation-libraries.md#reporting) functionality, which are important if you're authoring unit tests that run as part of an "offline" evaluation pipeline. The scenario shown in this quickstart is suitable in use cases such as "online" evaluation of AI responses within production code and logging scores to telemetry, where caching and reporting aren't relevant. For a tutorial that demonstrates the caching and reporting functionality, see [Tutorial: Evaluate a model's response with response caching and reporting](../tutorials/evaluate-with-reporting.md)
1515
1616
## Prerequisites
1717

18-
- [Install .NET 8.0](https://dotnet.microsoft.com/download) or a later version
19-
- [Install Ollama](https://ollama.com/) locally on your machine
18+
- [.NET 8 or a later version](https://dotnet.microsoft.com/download)
2019
- [Visual Studio Code](https://code.visualstudio.com/) (optional)
2120

22-
## Run the local AI model
21+
## Configure the AI service
2322

24-
Complete the following steps to configure and run a local AI model on your device. For this quickstart, you'll use the general purpose `phi3:mini` model, which is a small but capable generative AI created by Microsoft.
25-
26-
1. Open a terminal window and verify that Ollama is available on your device:
27-
28-
```bash
29-
ollama
30-
```
31-
32-
If Ollama is available, it displays a list of available commands.
33-
34-
1. Start Ollama:
35-
36-
```bash
37-
ollama serve
38-
```
39-
40-
If Ollama is running, it displays a list of available commands.
41-
42-
1. Pull the `phi3:mini` model from the Ollama registry and wait for it to download:
43-
44-
```bash
45-
ollama pull phi3:mini
46-
```
47-
48-
1. After the download completes, run the model:
49-
50-
```bash
51-
ollama run phi3:mini
52-
```
53-
54-
Ollama starts the `phi3:mini` model and provides a prompt for you to interact with it.
23+
To provision an Azure OpenAI service and model using the Azure portal, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource?pivots=web-portal) article. In the "Deploy a model" step, select the `gpt-4o` model.
5524

5625
## Create the test app
5726

@@ -66,21 +35,32 @@ Complete the following steps to create an MSTest project that connects to your l
6635
1. Navigate to the `TestAI` directory, and add the necessary packages to your app:
6736
6837
```dotnetcli
69-
dotnet add package Microsoft.Extensions.AI.Ollama --prerelease
38+
dotnet add package Azure.AI.OpenAI
39+
dotnet add package Azure.Identity
7040
dotnet add package Microsoft.Extensions.AI.Abstractions --prerelease
7141
dotnet add package Microsoft.Extensions.AI.Evaluation --prerelease
7242
dotnet add package Microsoft.Extensions.AI.Evaluation.Quality --prerelease
43+
dotnet add package Microsoft.Extensions.AI.OpenAI --prerelease
44+
dotnet add package Microsoft.Extensions.Configuration
45+
dotnet add package Microsoft.Extensions.Configuration.UserSecrets
7346
```
7447
75-
1. Open the new app in your editor of choice, such as Visual Studio Code.
48+
1. Run the following commands to add [app secrets](/aspnet/core/security/app-secrets) for your Azure OpenAI endpoint, model name, and tenant ID:
7649
77-
```dotnetcli
78-
code .
50+
```bash
51+
dotnet user-secrets init
52+
dotnet user-secrets set AZURE_OPENAI_ENDPOINT <your-azure-openai-endpoint>
53+
dotnet user-secrets set AZURE_OPENAI_GPT_NAME gpt-4o
54+
dotnet user-secrets set AZURE_TENANT_ID <your-tenant-id>
7955
```
8056
57+
(Depending on your environment, the tenant ID might not be needed. In that case, remove it from the code that instantiates the <xref:Azure.Identity.DefaultAzureCredential>.)
58+
59+
1. Open the new app in your editor of choice.
60+
8161
## Add the test app code
8262
83-
1. Rename the file *Test1.cs* to *MyTests.cs*, and then open the file and rename the class to `MyTests`.
63+
1. Rename the *Test1.cs* file to *MyTests.cs*, and then open the file and rename the class to `MyTests`.
8464
1. Add the private <xref:Microsoft.Extensions.AI.Evaluation.ChatConfiguration> and chat message and response members to the `MyTests` class. The `s_messages` field is a list that contains two <xref:Microsoft.Extensions.AI.ChatMessage> objects&mdash;one instructs the behavior of the chat bot, and the other is the question from the user.
8565
8666
:::code language="csharp" source="./snippets/evaluate-ai-responses/MyTests.cs" id="PrivateMembers":::
@@ -95,7 +75,7 @@ Complete the following steps to create an MSTest project that connects to your l
9575
- Sets the <xref:Microsoft.Extensions.AI.ChatOptions>, including the <xref:Microsoft.Extensions.AI.ChatOptions.Temperature> and the <xref:Microsoft.Extensions.AI.ChatOptions.ResponseFormat>.
9676
- Fetches the response to be evaluated by calling <xref:Microsoft.Extensions.AI.IChatClient.GetResponseAsync(System.Collections.Generic.IEnumerable{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatOptions,System.Threading.CancellationToken)>, and stores it in a static variable.
9777
98-
1. Add the `GetOllamaChatConfiguration` method, which creates the <xref:Microsoft.Extensions.AI.IChatClient> that the evaluator uses to communicate with the model.
78+
1. Add the `GetAzureOpenAIChatConfiguration` method, which creates the <xref:Microsoft.Extensions.AI.IChatClient> that the evaluator uses to communicate with the model.
9979
10080
:::code language="csharp" source="./snippets/evaluate-ai-responses/MyTests.cs" id="GetChatConfig":::
10181
@@ -116,4 +96,5 @@ Run the test using your preferred test workflow, for example, by using the CLI c
11696
11797
## Next steps
11898
119-
Next, try evaluating against different models to see if the results change. Then, check out the extensive examples in the [dotnet/ai-samples repo](https://github.com/dotnet/ai-samples/blob/main/src/microsoft-extensions-ai-evaluation/api/) to see how to invoke multiple evaluators, add additional context, invoke a custom evaluator, attach diagnostics, or change the default interpretation of metrics.
99+
- Evaluate the responses from different OpenAI models.
100+
- Add response caching and reporting to your evaluation code. For more information, see [Tutorial: Evaluate a model's response with response caching and reporting](../tutorials/evaluate-with-reporting.md).

docs/ai/quickstarts/snippets/chat-with-data/azure-openai/VectorDataAI.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -13,8 +13,8 @@
1313
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
1414
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25161.1" />
1515
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.41.0-preview" />
16-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.1.25080.5" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.1.25080.5" />
16+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.2.25163.2" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.2.25163.2" />
1818
</ItemGroup>
1919

2020
</Project>

docs/ai/quickstarts/snippets/chat-with-data/openai/VectorDataAI.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -11,8 +11,8 @@
1111
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
1212
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25161.1" />
1313
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.41.0-preview" />
14-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.1.25080.5" />
15-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.1.25080.5" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.2.25163.2" />
15+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.2.25163.2" />
1616
</ItemGroup>
1717

1818
</Project>

docs/ai/quickstarts/snippets/evaluate-ai-responses/MyTests.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using Microsoft.Extensions.AI;
1+
using Azure.AI.OpenAI;
2+
using Azure.Identity;
3+
using Microsoft.Extensions.AI;
24
using Microsoft.Extensions.AI.Evaluation;
35
using Microsoft.Extensions.AI.Evaluation.Quality;
6+
using Microsoft.Extensions.Configuration;
47

58
namespace TestAI;
69

@@ -30,7 +33,7 @@ public static async Task InitializeAsync(TestContext _)
3033
/// Set up the <see cref="ChatConfiguration"/>,
3134
/// which includes the <see cref="IChatClient"/> that the
3235
/// evaluator uses to communicate with the model.
33-
s_chatConfiguration = GetOllamaChatConfiguration();
36+
s_chatConfiguration = GetAzureOpenAIChatConfiguration();
3437

3538
var chatOptions =
3639
new ChatOptions
@@ -41,19 +44,25 @@ public static async Task InitializeAsync(TestContext _)
4144

4245
// Fetch the response to be evaluated
4346
// and store it in a static variable.
44-
ChatResponse response = await s_chatConfiguration.ChatClient.GetResponseAsync(s_messages, chatOptions);
45-
s_response = response;
47+
s_response = await s_chatConfiguration.ChatClient.GetResponseAsync(s_messages, chatOptions);
4648
}
4749
// </SnippetInitialize>
4850

4951
// <SnippetGetChatConfig>
50-
private static ChatConfiguration GetOllamaChatConfiguration()
52+
private static ChatConfiguration GetAzureOpenAIChatConfiguration()
5153
{
52-
// Get a chat client for the Ollama endpoint.
53-
IChatClient client =
54-
new OllamaChatClient(
55-
new Uri("http://localhost:11434"),
56-
modelId: "phi3:mini");
54+
IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets<MyTests>().Build();
55+
56+
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
57+
string model = config["AZURE_OPENAI_GPT_NAME"];
58+
string tenantId = config["AZURE_TENANT_ID"];
59+
60+
// Get a chat client for the Azure OpenAI endpoint.
61+
AzureOpenAIClient azureClient =
62+
new(
63+
new Uri(endpoint),
64+
new DefaultAzureCredential(new DefaultAzureCredentialOptions() { TenantId = tenantId }));
65+
IChatClient client = azureClient.AsChatClient(modelId: model);
5766

5867
return new ChatConfiguration(client);
5968
}

docs/ai/quickstarts/snippets/evaluate-ai-responses/TestAI.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@
55
<LangVersion>latest</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
<UserSecretsId>e224fe1d-640d-4b07-b04d-d7f2f82b7388</UserSecretsId>
89
</PropertyGroup>
910

1011
<ItemGroup>
12+
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
13+
<PackageReference Include="Azure.Identity" Version="1.13.2" />
1114
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25161.3" />
1215
<PackageReference Include="Microsoft.Extensions.AI.Evaluation" Version="9.3.0-preview.1.25164.6" />
1316
<PackageReference Include="Microsoft.Extensions.AI.Evaluation.Quality" Version="9.3.0-preview.1.25164.6" />
14-
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.3.0-preview.1.25161.3" />
17+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.3" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.3" />
1520
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0-preview-25107-01" />
16-
<PackageReference Include="MSTest" Version="3.8.2" />
21+
<PackageReference Include="MSTest" Version="3.8.3" />
1722
</ItemGroup>
1823

1924
<ItemGroup>

docs/ai/quickstarts/snippets/function-calling/openai/FunctionCallingAI.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -10,8 +10,8 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
1212
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
13-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.1.25080.5" />
14-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.1.25080.5" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.2.25163.2" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.2.25163.2" />
1515
</ItemGroup>
1616

1717
</Project>

docs/ai/tutorials/snippets/llm-eval/llm-eval.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.3" />
1414
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.3" />
15-
<PackageReference Include="Microsoft.SemanticKernel" Version="1.41.0" />
15+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.42.0" />
1616
</ItemGroup>
1717

1818
</Project>

0 commit comments

Comments
 (0)