[Agent的评估-06]如何改进MAF针对MEAI评估系统的适配方案?
在Agent的评估-04:利用MeaiEvaluatorAdapter适配MEAI评估系统中,我们对MAF的Agent评估系统利用MeaiEvaluatorAdapter适配MEAI评估系统的实现原理进行了详细介绍,但是在Agent的评估-05:MEAI用来评估LLM响应质量的9种评估器我们却说这种适配方案不够好。那么究竟问题在哪里?又该如何解决呢?
1. 评估上下文的缺失
MEAI的评估体系以如下所示的这个表示评估器的IEvaluator接口为核心,
public interface IEvaluator
{
IReadOnlyCollection<string> EvaluationMetricNames { get; }
ValueTask<EvaluationResult> EvaluateAsync(
IEnumerable<ChatMessage> messages,
ChatResponse modelResponse,
ChatConfiguration? chatConfiguration = null,
IEnumerable<EvaluationContext>? additionalContext = null,
CancellationToken cancellationToken = default);
}
public sealed class ChatConfiguration
{
public IChatClient ChatClient { get; }
}
public abstract class EvaluationContext
{
public string Name { get; set; }
public IList<AIContent> Contents { get; set; }
}
用来实施评估的EvaluateAsync方法的参数说明如下:
- messages:完整对话历史(包含用户请求与模型响应)。
- modelResponse:被评估的模型输出。
- chatConfiguration:如果评估器内部需要借助LLM的力量,则可以利用此
ChatConfiguration提供的IChatClient对象来调用LLM。 - additionalContext:提供的EvaluationContext对象以AIContent对象的形式为评估工作提供必要的上下文。
作为适配器的MeaiEvaluatorAdapter定义如下,在实现的EvaluateAsync方法中,它会利用IEvaluator对象对每个EvalItem实施评估,并生成以评估指标为核心内容的EvaluationResult对象。这些EvaluationResult用来生成作为Agent评估结果的AgentEvaluationResults对象。
internal sealed class MeaiEvaluatorAdapter : IAgentEvaluator
{
private readonly IEvaluator _evaluator;
private readonly ChatConfiguration _chatConfiguration;
public string Name => _evaluator.GetType().Name;
public MeaiEvaluatorAdapter(IEvaluator evaluator, ChatConfiguration chatConfiguration)
{
_evaluator = evaluator;
_chatConfiguration = chatConfiguration;
}
public async Task<AgentEvaluationResults> EvaluateAsync(
IReadOnlyList<EvalItem> items,
string evalName = "MEAI Eval",
CancellationToken cancellationToken = default)
{
List<EvaluationResult> results = new List<EvaluationResult>(items.Count);
foreach (EvalItem item in items)
{
cancellationToken.ThrowIfCancellationRequested();
IReadOnlyList<ChatMessage> queryMessages = item.Split().QueryMessages;
List<ChatMessage> messages = queryMessages.ToList();
ChatResponse chatResponse = item.RawResponse
?? new ChatResponse(new ChatMessage(ChatRole.Assistant, item.Response));
results.Add(await _evaluator
.EvaluateAsync(messages, chatResponse, _chatConfiguration, null, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false));
}
return new AgentEvaluationResults(Name, results, items);
}
}
在针对具体EvalItem对象实施评估时,会调用Split方法借助提供的IConversationSplitter对象将整个对话历史分割成作为查询和响应的ChatMessage列表。如果EvalItem没有利用RawResponse属性提供用来评估的ChatResponse,则根据分割生成的响应消息列表生成一个新的ChatResponse对象。查询消息列表、ChatResponse和调用构造函数提供的ChatConfiguration将作为参数调用IEvaluator的EvaluateAsync实施评估,并返回作为评估结果的EvaluationResult对象。我们可以清晰地看到:调用IEvaluator的EvaluateAsync方法将作为评估上下文的additionalContext参数设置为null。
2. 对评估结果的影响
对于大部分MEAI的评估器,它们大都利用ChatConfiguration提供的IChatClient对象调用LLM来实施评估。根据具体的评估指标的差异,它们对评估上下文的依赖可分为如下三种:
- 不需要评估上下文:不会对评估结果造成任何影响;
- 评估上下文为可选:可以进行正常的评估,但是评估结果准确度存疑;
- 评估上下文为必须:评估失败。
我们知道所谓的评估基本就是用来检验LLM响应的结果与指定的评估基准(比如Ground Truth)之间差异程度,而评估的基准就是评估上下文提供的核心内容。可想而知,连评估基准都没有了,评估结果还值得相信吗。
很多IEvaluator的实现在进行评估的时候明确要求指定的评估上下文不为null,在这种情况下,我们调用AIAgent的EvaluateAsync扩展方法时会导致评估失败。以如下这个程序为例,我们在调用EvalueateAsync方法使用到了BLEUEvaluator这个评估器,其目的在于使用BLEU评估翻译文本的质量。BLEU(Bilingual Evaluation Understudy,双语评估辅助工具)是机器翻译领域最经典、最常用的自动评测指标。它的核心思想非常简单:机器翻译的结果与人工标准答案(参考译文)越接近,翻译质量就越好。毫无疑问,要执行这个BLEUEvaluator对象,参考译文肯定是必须的。
using Azure.AI.Projects;
using Azure.Identity;
using DotNetEnv;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.Evaluation;
using Microsoft.Extensions.AI.Evaluation.NLP;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
Env.Load();
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
var projectUrl = Environment.GetEnvironmentVariable("PROJECT_URL")!;
var evalChatClient = new AIProjectClient(new Uri(projectUrl), new AzureCliCredential())
.ProjectOpenAIClient
.GetProjectResponsesClient()
.AsIChatClient("DeepSeek-V4-Pro");
var agent = new AIProjectClient(new Uri(projectUrl), new AzureCliCredential())
.ProjectOpenAIClient
.GetProjectResponsesClient()
.AsIChatClient("gpt-5.4-mini")
.AsAIAgent();
var query = """
将下面这句话翻译成英文:
道生一,一生二,二生三,三生万物。
只返回译文。
""";
var evalResults = await agent.EvaluateAsync(
queries: [query],
evaluator: new BLEUEvaluator(),
chatConfiguration: new ChatConfiguration(evalChatClient)
);
var serializerOptions = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
serializerOptions.Converters.Add(new JsonStringEnumConverter());
Console.WriteLine(JsonSerializer.Serialize(
evalResults.Items.Single().Metrics, serializerOptions));
输出:
{
"BLEU": {
"$type": "numeric",
"Value": null,
"Name": "BLEU",
"Reason": null,
"Interpretation": null,
"Context": null,
"Diagnostics": [
{
"Severity": "Error",
"Message": "A value of type 'BLEUEvaluatorContext' was not found in the 'additionalContext' collection."
}
],
"Metadata": {
"built-in-eval": "True"
}
}
}
从输出可以清楚地看到,作为承载评估结果核心内容的指标数据包含一个诊断信息,明确告知:作为评估上下文的BLEUEvaluatorContext对象并未在additionalContext参数中找到。
Agent的评估-05:MEAI用来评估LLM响应质量的9种评估器中介绍的9中评估器大多都是需要这个上下文的。以常用的用于评估完整性的CompletenessEvaluator为例。如下所示的提交给LLM的评估提示词的内容:
# Definition
**Completeness** refers to how accurately and thoroughly a response represents the information provided in the ground truth. It considers both the inclusion of all relevant statements and the correctness of those statements. Each statement in the ground truth should be evaluated individually to determine if it is accurately reflected in the response without missing any key information. The scale ranges from 1 to 5, with higher numbers indicating greater completeness.
# Ratings
## [Completeness: 1] (Fully Incomplete)
**Definition:** A response that does not contain any of the necessary and relevant information with respect to the ground truth. It completely misses all the information, especially claims and statements, established in the ground truth.
**Examples:**
**Response:** "Flu shot cannot cure cancer. Stay healthy requires sleeping exactly 8 hours a day. A few hours of exercise per week will have little benefits for physical and mental health. Physical and mental health benefits are separate topics. Scientists have not studied any of them."
**Ground Truth:** "Flu shot can prevent flu-related illnesses. Staying healthy requires proper hydration and moderate exercise. Even a few hours of exercise per week can have long-term benefits for physical and mental health. This is because physical and mental health benefits have intricate relationships through behavioral changes. Scientists are starting to discover them through rigorous studies."
## [Completeness: 2] (Barely Complete)
**Definition:** A response that contains only a small percentage of all the necessary and relevant information with respect to the ground truth. It misses almost all the information, especially claims and statements, established in the ground truth.
**Examples:**
**Response:** "Flu shot can prevent flu-related illnesses. Staying healthy requires 2 meals a day. Exercise per week makes no difference to physical and mental health. This is because physical and mental health benefits have low correlation through scientific studies. Scientists are making this observation in studies."
**Ground Truth:** "Flu shot can prevent flu-related illnesses. Stay healthy by proper hydration and moderate exercise. Even a few hours of exercise per week can have long-term benefits for physical and mental health. This is because physical and mental health benefits have intricate relationships through behavioral changes. Scientists are starting to discover them through rigorous studies."
## [Completeness: 3] (Moderately Complete)
**Definition:** A response that contains half of the necessary and relevant information with respect to the ground truth. It misses half of the information, especially claims and statements, established in the ground truth.
**Examples:**
**Response:** "Flu shot can prevent flu-related illnesses. Staying healthy requires a few dollars of investments a day. Even a few dollars of investments per week will not make an impact on physical and mental health. This is because physical and mental health benefits have intricate relationships through behavioral changes. Fiction writers are starting to discover them through their works."
**Ground Truth:** "Flu shot can prevent flu-related illnesses. Stay healthy by proper hydration and moderate exercise. Even a few hours of exercise per week can have long-term benefits for physical and mental health. This is because physical and mental health benefits have intricate relationships through behavioral changes. Scientists are starting to discover them through rigorous studies."
## [Completeness: 4] (Mostly Complete)
**Definition:** A response that contains most of the necessary and relevant information with respect to the ground truth. It misses some minor information, especially claims and statements, established in the ground truth.
**Examples:**
**Response:** "Flu shot can prevent flu-related illnesses. Staying healthy requires keto diet and rigorous athletic training. Even a few hours of exercise per week can have long-term benefits for physical and mental health. This is because physical and mental health benefits have intricate relationships through behavioral changes. Scientists are starting to discover them through rigorous studies."
**Ground Truth:** "Flu shot can prevent flu-related illnesses. Stay healthy by proper hydration and moderate exercise. Even a few hours of exercise per week can have long-term benefits for physical and mental health. This is because physical and mental health benefits have intricate relationships through behavioral changes. Scientists are starting to discover them through rigorous studies."
## [Completeness: 5] (Fully Complete)
**Definition:** A response that perfectly contains all the necessary and relevant information with respect to the ground truth. It does not miss any information from statements and claims in the ground truth.
**Examples:**
**Response:** "Flu shot can prevent flu-related illnesses. Stay healthy by proper hydration and moderate exercise. Even a few hours of exercise per week can have long-term benefits for physical and mental health. This is because physical and mental health benefits have intricate relationships through behavioral changes. Scientists are starting to discover them through rigorous studies."
**Ground Truth:** "Flu shot can prevent flu-related illnesses. Stay healthy by proper hydration and moderate exercise. Even a few hours of exercise per week can have long-term benefits for physical and mental health. This is because physical and mental health benefits have intricate relationships through behavioral changes. Scientists are starting to discover them through rigorous studies."
# Data
Response: {{renderedModelResponse}}
Ground Truth: {{groundTruth}}
# Tasks
## Please provide your assessment Score for the previous RESPONSE in relation to the GROUND TRUTH based on the Definitions above. Your output should include the following information:
- **ThoughtChain**: To improve the reasoning process, think step by step and include a step-by-step explanation of your thought process as you analyze the data based on the definitions. Keep it brief and start your ThoughtChain with "Let's think step by step:".
- **Explanation**: a very short explanation of why you think the input data should get that Score.
- **Score**: based on your previous analysis, provide your Score. The Score you give MUST be an integer score (i.e., "1", "2"...) based on the levels of the definitions.
## Please provide your answers between the tags: <S0>your chain of thoughts</S0>, <S1>your explanation</S1>, <S2>your score</S2>.
# Output
提示词中包含一个{{groundTruth}}占位符来指定作为评估基准的内容。通过阅读这篇提示词的内容,我们可以这部分内容对评估是非常重要的,而且首句就明确说了:Completeness refers to how accurately and thoroughly a response represents the information provided in the **ground truth**。虽然CompletenessEvaluator也要求CompletenessEvaluatorContext上下文的存在。假设某些类似的评估继续使用这种不完整的提示词实施评估,只能全靠LLM脑补正确的标准是什么。如果这个标准来源于私域知识库呢,可想而知生成的评估标准还有什么可行度。
3. 如何动态提供评估上下文?
要解决这个问题的方案很明确,就是需要在调用IEvaluator的EvaluateAsync方法时提供必要的评估上下文。但是这个上下文由不能写死,必须根据当前的评估场景动态提供,为此我对MeaiEvaluatorAdapter略加改动,变成如下的形式。
internal sealed class MeaiEvaluatorAdapter : IAgentEvaluator
{
private readonly IEvaluator _evaluator;
private readonly Func<EvalItem, ValueTask<IEnumerable<EvaluationContext>>>? _evalContextAccessor;
private readonly ChatConfiguration _chatConfiguration;
public string Name => _evaluator.GetType().Name;
public MeaiEvaluatorAdapter(
IEvaluator evaluator,
IChatClient? evalChatClient = null,
Func<EvalItem, ValueTask<IEnumerable<EvaluationContext>>>? evalContextAccessor = null)
{
_evaluator = evaluator;
_evalContextAccessor = evalContextAccessor;
_chatConfiguration = new ChatConfiguration(evalChatClient!);
}
public async Task<AgentEvaluationResults> EvaluateAsync(
IReadOnlyList<EvalItem> items,
string evalName = "MEAI Eval",
CancellationToken cancellationToken = default)
{
List<EvaluationResult> results = new(items.Count);
foreach (EvalItem item in items)
{
cancellationToken.ThrowIfCancellationRequested();
IReadOnlyList<ChatMessage> queryMessages = item.Split().QueryMessages;
List<ChatMessage> messages = [.. queryMessages];
var chatResponse = item.RawResponse
?? new ChatResponse(new ChatMessage(ChatRole.Assistant, item.Response));
var evalContext = _evalContextAccessor is null ? null: await _evalContextAccessor(item);
results.Add(await _evaluator
.EvaluateAsync(messages, chatResponse, _chatConfiguration, evalContext, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false));
}
return new AgentEvaluationResults(Name, results, items);
}
}
如代码片段所示,我们在构造MeaiEvaluatorAdapter对象的时候除了提供用来调用LLM的IChatClient之外,还提供了一个Func<EvalItem, ValueTask<IEnumerable<EvaluationContext>>>类型的委托,意味着我们可以利用它根据描述当前评估工作的EvalItem来动态提供作为评估上下文的EvaluationContext列表。在实现的EvaluateAsync方法中,我们会利用此委托来创建评估上下文,并传入IEvaluator的EvaluateAsync方法中。为了方便调用,我们还针对AIAgent定义了如下两个扩展方法。
public static async Task<AgentEvaluationResults> EvaluateAsync(
this AIAgent agent,
IEnumerable<string> queries,
IEvaluator evaluator,
IChatClient? evalChatClient = null,
Func<EvalItem, ValueTask<IEnumerable<EvaluationContext>>>? evalContextAccessor = null,
string evalName = "AgentFrameworkEval",
IEnumerable<string>? expectedOutput = null,
IEnumerable<IEnumerable<ExpectedToolCall>>? expectedToolCalls = null,
IConversationSplitter? splitter = null,
int numRepetitions = 1,
CancellationToken cancellationToken = default)
{
var wrapped = new MeaiEvaluatorAdapter(evaluator, evalChatClient, evalContextAccessor);
return await agent.EvaluateAsync(queries, wrapped, evalName, expectedOutput, expectedToolCalls, splitter, numRepetitions, cancellationToken).ConfigureAwait(false);
}
public static async Task<AgentEvaluationResults> EvaluateAsync(
this AIAgent agent,
IEnumerable<string> queries,
IEvaluator evaluator,
IChatClient? evalChatClient = null,
Func<EvalItem, IEnumerable<EvaluationContext>>? evalContextAccessor = null,
string evalName = "AgentFrameworkEval",
IEnumerable<string>? expectedOutput = null,
IEnumerable<IEnumerable<ExpectedToolCall>>? expectedToolCalls = null,
IConversationSplitter? splitter = null,
int numRepetitions = 1,
CancellationToken cancellationToken = default)
{
var wrapped = evalContextAccessor is null
? new MeaiEvaluatorAdapter(evaluator, evalChatClient)
: new MeaiEvaluatorAdapter(evaluator, evalChatClient, item => ValueTask.FromResult(evalContextAccessor(item)));
return await agent
.EvaluateAsync(queries, wrapped, evalName, expectedOutput, expectedToolCalls, splitter, numRepetitions, cancellationToken)
.ConfigureAwait(false);
}
public static async Task<AgentEvaluationResults> EvaluateAsync(
this AIAgent agent,
IEnumerable<AgentResponse> responses,
IEnumerable<string> queries,
IEvaluator evaluator,
IChatClient? evalChatClient = null,
Func<EvalItem, ValueTask<IEnumerable<EvaluationContext>>>? evalContextAccessor = null,
string evalName = "AgentFrameworkEval",
IEnumerable<string>? expectedOutput = null,
IEnumerable<IEnumerable<ExpectedToolCall>>? expectedToolCalls = null,
CancellationToken cancellationToken = default)
{
var wrapped = new MeaiEvaluatorAdapter(evaluator, evalChatClient, evalContextAccessor);
return await agent.EvaluateAsync(responses, queries, wrapped, evalName, expectedOutput, expectedToolCalls, cancellationToken).ConfigureAwait(false);
}
public static async Task<AgentEvaluationResults> EvaluateAsync(
this AIAgent agent,
IEnumerable<AgentResponse> responses,
IEnumerable<string> queries,
IEvaluator evaluator,
IChatClient? evalChatClient = null,
Func<EvalItem, IEnumerable<EvaluationContext>>? evalContextAccessor = null,
string evalName = "AgentFrameworkEval",
IEnumerable<string>? expectedOutput = null,
IEnumerable<IEnumerable<ExpectedToolCall>>? expectedToolCalls = null,
CancellationToken cancellationToken = default)
{
var wrapped = evalContextAccessor is null
? new MeaiEvaluatorAdapter(evaluator, evalChatClient)
: new MeaiEvaluatorAdapter(evaluator, evalChatClient, item=> ValueTask.FromResult(evalContextAccessor(item)));
return await agent
.EvaluateAsync(responses, queries, wrapped, evalName, expectedOutput, expectedToolCalls, cancellationToken)
.ConfigureAwait(false);
}
我们使用上面定义的第二个EvaluateAsync方法来解决上面演示的翻译质量评估问题。如代码所示,我们指定了BLEUEvaluator作为评估器,并利用evalContextAccessor参数指定了一个作为标准译文的文本。
using Azure.AI.Projects;
using Azure.Identity;
using DotNetEnv;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.Evaluation.NLP;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
Env.Load();
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
var projectUrl = Environment.GetEnvironmentVariable("PROJECT_URL")!;
var evalChatClient = new AIProjectClient(new Uri(projectUrl), new AzureCliCredential())
.ProjectOpenAIClient
.GetProjectResponsesClient()
.AsIChatClient("DeepSeek-V4-Pro");
var agent = new AIProjectClient(new Uri(projectUrl), new AzureCliCredential())
.ProjectOpenAIClient
.GetProjectResponsesClient()
.AsIChatClient("gpt-5.4-mini")
.AsAIAgent();
var query = """
将下面这句话翻译成英文:
道生一,一生二,二生三,三生万物。
只返回译文。
""";
var evalResults = await agent.EvaluateAsync(
queries: [query],
evaluator: new BLEUEvaluator(),
evalChatClient: evalChatClient,
evalContextAccessor: _ => [new BLEUEvaluatorContext(["The Dao produces One; One produces Two; Two produce Three; Three produce everything."])]
);
var serializerOptions = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
serializerOptions.Converters.Add(new JsonStringEnumConverter());
Console.WriteLine(JsonSerializer.Serialize(evalResults.Items.Single().Metrics, serializerOptions));
输出:
{
"BLEU": {
"$type": "numeric",
"Value": 0.09940649174805037,
"Name": "BLEU",
"Reason": null,
"Interpretation": {
"Rating": "Unacceptable",
"Failed": true,
"Reason": "BLEU is less than 0.5."
},
"Context": {
"References (BLEU)": {
"Name": "References (BLEU)",
"Contents": [
{
"$type": "text",
"Text": "The Dao produces One; One produces Two; Two produce Three; Three produce everything.",
"Annotations": null,
"AdditionalProperties": null
}
]
}
},
"Diagnostics": null,
"Metadata": {
"built-in-eval": "True",
"eval-duration-ms": "9.88"
}
}
}
4. 有无评估上下文差别有多大
接下来我们利用一个具体的实例来演示是否提供评估上下文对最终的评估结果的影响。我们使用上面提到的用于完整性评估的CompletenessEvaluator。如下面的代码片段所示,我们演示的是针对指定的响应内容进行评估,具体的问题是:高血压患者平时有什么注意事项。
using Azure.AI.Projects;
using Azure.Identity;
using DotNetEnv;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.Evaluation;
using Microsoft.Extensions.AI.Evaluation.Quality;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
Env.Load();
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
var projectUrl = Environment.GetEnvironmentVariable("PROJECT_URL")!;
var evalChatClient = new AIProjectClient(new Uri(projectUrl), new AzureCliCredential())
.ProjectOpenAIClient
.GetProjectResponsesClient()
.AsIChatClient("DeepSeek-V4-Pro");
var agent = new AIProjectClient(new Uri(projectUrl), new AzureCliCredential())
.ProjectOpenAIClient
.GetProjectResponsesClient()
.AsIChatClient("gpt-5.4-mini")
.AsAIAgent();
var query = "高血压患者平时有什么注意事项";
var reply = """
高血压患者平时一定要少吃盐,每天盐的摄入量控制在5克以内。
饮食要清淡,多吃蔬菜和水果。平时还要注意戒烟和限酒。
""";
var groundTruth = """
高血压患者在饮食上需要严格控制钠盐摄入,每日不超过5克。
同时应减少高脂肪和高胆固醇食物,多吃富含钾和镁的蔬菜水果。
此外,保持适量运动和戒烟限酒也是控制血压的关键。
""";
var response = new AgentResponse(new ChatMessage(ChatRole.Assistant, reply));
// 没有提供评估上下文
var results = await agent.EvaluateAsync(
responses: [response],
queries: [query],
evaluator: new CompletenessEvaluator(),
chatConfiguration: new ChatConfiguration(evalChatClient));
var serializerOptions = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
serializerOptions.Converters.Add(new JsonStringEnumConverter());
Console.WriteLine(JsonSerializer.Serialize(results.Items.Single().Metrics, serializerOptions));
// 提供评估上下文
results = await agent.EvaluateAsync(
responses: [response],
queries: [query],
evaluator: new CompletenessEvaluator(),
evalChatClient: evalChatClient,
evalContextAccessor: _ => [new CompletenessEvaluatorContext(groundTruth)]);
Console.WriteLine(JsonSerializer.Serialize(results.Items.Single().Metrics, serializerOptions));
我们针对相同的响应文本创建了对应的AgentResponse,并对它实施评估。第一次评估调用的是原生的EvaluateAsync方法,第二次调用的是我们自定义的EvaluateAsync,我们利用evalContextAccessor参数指定了正确答案。从输出可以看出,第一次评估失败,第二次则根据指定的标准答案做出了正确的评估(4分)。
没有提供评估上下文(评估失败):
{
"Completeness": {
"$type": "numeric",
"Value": null,
"Name": "Completeness",
"Reason": null,
"Interpretation": null,
"Context": null,
"Diagnostics": [
{
"Severity": "Error",
"Message": "A value of type CompletenessEvaluatorContext was not found in the additionalContext collection."
}
],
"Metadata": {
"built-in-eval": "True"
}
}
}
提供评估上下文:
{
"Completeness": {
"$type": "numeric",
"Value": 4,
"Name": "Completeness",
"Reason": "The response includes the salt limit, vegetables/fruits, and smoking/alcohol advice, but omits the need to reduce high-fat/cholesterol foods, the specific nutrients (potassium, magnesium), and the recommendation for moderate exercise. These are minor but relevant details from the ground truth.",
"Interpretation": {
"Rating": "Good",
"Failed": false,
"Reason": null
},
"Context": {
"Ground Truth (Completeness)": {
"Name": "Ground Truth (Completeness)",
"Contents": [
{
"$type": "text",
"Text": "高血压患者在饮食上需要严格控制钠盐摄入,每日不超过5克。\r\n同时应减少高脂肪和高胆固醇食物,多吃富含钾和镁的蔬菜水果。\r\n此外,保持适量运动和戒烟限酒也是控制血压的关键。",
"Annotations": null,
"AdditionalProperties": null
}
]
}
},
"Diagnostics": [
{
"Severity": "Informational",
"Message": "Model's evaluation chain of thought: Let's think step by step: The ground truth contains three main points: (1) strict control of sodium intake, no more than 5g per day; (2) reduce high-fat and high-cholesterol foods, eat more vegetables and fruits rich in potassium and magnesium; (3) maintain moderate exercise and quit smoking and limit alcohol. The response mentions controlling salt intake to within 5g, eating more vegetables and fruits, and quitting smoking and limiting alcohol. It misses the reduction of high-fat and high-cholesterol foods, the mention of potassium and magnesium, and the importance of moderate exercise. So it covers part of the information but misses some key elements. This is more than half but not all, so it fits \"Mostly Complete\" (4) because it contains most of the necessary information but misses some minor details like exercise and specific dietary restrictions."
}
],
"Metadata": {
"built-in-eval": "True",
"eval-model": "DeepSeek-V4-Pro",
"eval-input-tokens": "1533",
"eval-output-tokens": "251",
"eval-total-tokens": "1784",
"eval-duration-ms": "53982.13"
}
}
}
更多推荐




所有评论(0)