Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@
"_csharplang/proposals/csharp-13.0/overload-resolution-priority.md": "Overload resolution priority tiebreaker attribute",
"_csharplang/proposals/field-keyword.md": "The `field` contextual keyword",
"_csharplang/proposals/unbound-generic-types-in-nameof.md": "Unbound generic types in `nameof`",
"_csharplang/proposals/first-class-span-types.md": "First-class span types",
"_csharplang/proposals/first-class-span-types.md": "First-class span types",
"_csharplang/proposals/simple-lambda-parameters-with-modifiers.md": "Simple lambda parameters with modifiers",
"_csharplang/proposals/partial-events-and-constructors.md": "Partial events and constructors",
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md": "C# compiler breaking changes since C# 10",
Expand Down Expand Up @@ -878,7 +878,6 @@
"docs/standard/design-guidelines/**.md": false
},
"ms.custom": {
"docs/ai/**/**.md": "build-2024-intelligent-apps",
"docs/framework/**/*.md": "UpdateFrequency5",
"docs/visual-basic/**/*.md": "UpdateFrequency5"
},
Expand Down
4 changes: 2 additions & 2 deletions docs/ai/conceptual/evaluation-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: The Microsoft.Extensions.AI.Evaluation libraries
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.
ms.topic: concept-article
ms.date: 02/19/2025
ms.date: 03/18/2025
---
# The Microsoft.Extensions.AI.Evaluation libraries (Preview)

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

:::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.":::

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.
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).

## Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.10.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.11.0" />
</ItemGroup>

</Project>
67 changes: 24 additions & 43 deletions docs/ai/quickstarts/evaluate-ai-response.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,26 @@
---
title: Quickstart - Evaluate a model's response
description: Learn how to create an MSTest app to evaluate the AI chat response of a language model.
ms.date: 02/25/2025
ms.date: 03/18/2025
ms.topic: quickstart
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
---

# Evaluate a model's response

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.
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.

> [!NOTE]
> 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)

## Prerequisites

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

## Run the local AI model
## Configure the AI service

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.

1. Open a terminal window and verify that Ollama is available on your device:

```bash
ollama
```

If Ollama is available, it displays a list of available commands.

1. Start Ollama:

```bash
ollama serve
```

If Ollama is running, it displays a list of available commands.

1. Pull the `phi3:mini` model from the Ollama registry and wait for it to download:

```bash
ollama pull phi3:mini
```

1. After the download completes, run the model:

```bash
ollama run phi3:mini
```

Ollama starts the `phi3:mini` model and provides a prompt for you to interact with it.
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.

## Create the test app

Expand All @@ -66,21 +35,32 @@ Complete the following steps to create an MSTest project that connects to your l
1. Navigate to the `TestAI` directory, and add the necessary packages to your app:

```dotnetcli
dotnet add package Microsoft.Extensions.AI.Ollama --prerelease
dotnet add package Azure.AI.OpenAI
dotnet add package Azure.Identity
dotnet add package Microsoft.Extensions.AI.Abstractions --prerelease
dotnet add package Microsoft.Extensions.AI.Evaluation --prerelease
dotnet add package Microsoft.Extensions.AI.Evaluation.Quality --prerelease
dotnet add package Microsoft.Extensions.AI.OpenAI --prerelease
dotnet add package Microsoft.Extensions.Configuration
dotnet add package Microsoft.Extensions.Configuration.UserSecrets
```

1. Open the new app in your editor of choice, such as Visual Studio Code.
1. Run the following commands to add [app secrets](/aspnet/core/security/app-secrets) for your Azure OpenAI endpoint, model name, and tenant ID:

```dotnetcli
code .
```bash
dotnet user-secrets init
dotnet user-secrets set AZURE_OPENAI_ENDPOINT <your-azure-openai-endpoint>
dotnet user-secrets set AZURE_OPENAI_GPT_NAME gpt-4o
dotnet user-secrets set AZURE_TENANT_ID <your-tenant-id>
```

(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>.)

1. Open the new app in your editor of choice.

## Add the test app code

1. Rename the file *Test1.cs* to *MyTests.cs*, and then open the file and rename the class to `MyTests`.
1. Rename the *Test1.cs* file to *MyTests.cs*, and then open the file and rename the class to `MyTests`.
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.

:::code language="csharp" source="./snippets/evaluate-ai-responses/MyTests.cs" id="PrivateMembers":::
Expand All @@ -95,7 +75,7 @@ Complete the following steps to create an MSTest project that connects to your l
- Sets the <xref:Microsoft.Extensions.AI.ChatOptions>, including the <xref:Microsoft.Extensions.AI.ChatOptions.Temperature> and the <xref:Microsoft.Extensions.AI.ChatOptions.ResponseFormat>.
- 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.

1. Add the `GetOllamaChatConfiguration` method, which creates the <xref:Microsoft.Extensions.AI.IChatClient> that the evaluator uses to communicate with the model.
1. Add the `GetAzureOpenAIChatConfiguration` method, which creates the <xref:Microsoft.Extensions.AI.IChatClient> that the evaluator uses to communicate with the model.

:::code language="csharp" source="./snippets/evaluate-ai-responses/MyTests.cs" id="GetChatConfig":::

Expand All @@ -116,4 +96,5 @@ Run the test using your preferred test workflow, for example, by using the CLI c

## Next steps

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.
- Evaluate the responses from different OpenAI models.
- 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).
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -13,8 +13,8 @@
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25161.1" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.41.0-preview" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.1.25080.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.1.25080.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.2.25163.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.2.25163.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -11,8 +11,8 @@
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25161.1" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.41.0-preview" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.1.25080.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.1.25080.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.2.25163.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.2.25163.2" />
</ItemGroup>

</Project>
29 changes: 19 additions & 10 deletions docs/ai/quickstarts/snippets/evaluate-ai-responses/MyTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Microsoft.Extensions.AI;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.Evaluation;
using Microsoft.Extensions.AI.Evaluation.Quality;
using Microsoft.Extensions.Configuration;

namespace TestAI;

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

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

// Fetch the response to be evaluated
// and store it in a static variable.
ChatResponse response = await s_chatConfiguration.ChatClient.GetResponseAsync(s_messages, chatOptions);
s_response = response;
s_response = await s_chatConfiguration.ChatClient.GetResponseAsync(s_messages, chatOptions);
}
// </SnippetInitialize>

// <SnippetGetChatConfig>
private static ChatConfiguration GetOllamaChatConfiguration()
private static ChatConfiguration GetAzureOpenAIChatConfiguration()
{
// Get a chat client for the Ollama endpoint.
IChatClient client =
new OllamaChatClient(
new Uri("http://localhost:11434"),
modelId: "phi3:mini");
IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets<MyTests>().Build();

string endpoint = config["AZURE_OPENAI_ENDPOINT"];
string model = config["AZURE_OPENAI_GPT_NAME"];
string tenantId = config["AZURE_TENANT_ID"];

// Get a chat client for the Azure OpenAI endpoint.
AzureOpenAIClient azureClient =
new(
new Uri(endpoint),
new DefaultAzureCredential(new DefaultAzureCredentialOptions() { TenantId = tenantId }));
IChatClient client = azureClient.AsChatClient(modelId: model);

return new ChatConfiguration(client);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>e224fe1d-640d-4b07-b04d-d7f2f82b7388</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Azure.Identity" Version="1.13.2" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.AI.Evaluation" Version="9.3.0-preview.1.25164.6" />
<PackageReference Include="Microsoft.Extensions.AI.Evaluation.Quality" Version="9.3.0-preview.1.25164.6" />
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0-preview-25107-01" />
<PackageReference Include="MSTest" Version="3.8.2" />
<PackageReference Include="MSTest" Version="3.8.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -10,8 +10,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.1.25080.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.1.25080.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.2.25163.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.2.25163.2" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion docs/ai/tutorials/snippets/llm-eval/llm-eval.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.3" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.41.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.42.0" />
</ItemGroup>

</Project>
8 changes: 2 additions & 6 deletions docs/azure/configure-visual-studio.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Configure Visual Studio for Azure Development with .NET
description: This article helps you configure Visual Studio for Azure development including getting the right workloads installed and connecting Visual Studio to your Azure account.
ms.topic: conceptual
ms.custom: devx-track-dotnet, engagement-fy23
ms.date: 8/15/2024
ms.date: 3/19/2025
author: alexwolfmsft
ms.author: alexwolf
---
Expand All @@ -27,11 +27,7 @@ Open Visual Studio Installer and validate that the workloads **Azure development

## Authenticate Visual Studio with Azure

When you debug apps through Visual Studio, Visual Studio can use your Azure account to authenticate and access Azure Resources. This account is also used when you publish apps directly from Visual Studio to Azure.

To authenticate your Azure account from Visual Studio, select the **Tools** > **Options** menu to launch the **Options** dialog. Navigate to the **Azure Service Authentication** options and sign in using your Azure account.

![Screenshot of the Visual Studio Options Dialog showing the Azure Login](./media/visual-studio-azure-login-dialog.png)
[!INCLUDE [auth-visual-studio](sdk/includes/auth-visual-studio.md)]

## Next steps

Expand Down
Loading
Loading