@mastra/evals 1.10.8-alpha.2 → 1.10.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{checks-B7c-zPoM.cjs → checks-BX_kIFwJ.cjs} +2 -2
- package/dist/checks-BX_kIFwJ.cjs.map +1 -0
- package/dist/checks.cjs +1 -1
- package/dist/checks.js +1 -2
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/scorers/prebuilt/index.cjs +70 -43
- package/dist/scorers/prebuilt/index.cjs.map +1 -1
- package/dist/scorers/prebuilt/index.js +69 -42
- package/dist/scorers/prebuilt/index.js.map +1 -1
- package/dist/scorers/utils.cjs +18 -15
- package/dist/scorers/utils.cjs.map +1 -1
- package/dist/scorers/utils.js +18 -15
- package/dist/scorers/utils.js.map +1 -1
- package/dist/vitest/index.cjs.map +1 -1
- package/dist/vitest/setup.cjs.map +1 -1
- package/package.json +8 -8
- package/dist/checks-B7c-zPoM.cjs.map +0 -1
|
@@ -226,7 +226,8 @@ function createAnswerRelevancyScorer({ model, options = DEFAULT_OPTIONS }) {
|
|
|
226
226
|
description: "Extract relevant statements from the LLM output",
|
|
227
227
|
outputSchema: extractOutputSchema$1,
|
|
228
228
|
createPrompt: ({ run }) => {
|
|
229
|
-
|
|
229
|
+
const assistantMessage = getAssistantMessageFromRunOutput(run.output) ?? "";
|
|
230
|
+
return createExtractPrompt$1(assistantMessage);
|
|
230
231
|
}
|
|
231
232
|
}).analyze({
|
|
232
233
|
description: "Score the relevance of the statements to the input",
|
|
@@ -256,7 +257,8 @@ function createAnswerRelevancyScorer({ model, options = DEFAULT_OPTIONS }) {
|
|
|
256
257
|
let relevancyCount = 0;
|
|
257
258
|
for (const { result } of results.analyzeStepResult.results) if (result.trim().toLowerCase() === "yes") relevancyCount++;
|
|
258
259
|
else if (result.trim().toLowerCase() === "unsure") relevancyCount += options.uncertaintyWeight;
|
|
259
|
-
|
|
260
|
+
const score = relevancyCount / numberOfResults;
|
|
261
|
+
return roundToTwoDecimals(score * options.scale);
|
|
260
262
|
}).generateReason({
|
|
261
263
|
description: "Reason about the results",
|
|
262
264
|
createPrompt: ({ run, results, score }) => {
|
|
@@ -498,18 +500,22 @@ function createAnswerSimilarityScorer({ model, options = ANSWER_SIMILARITY_DEFAU
|
|
|
498
500
|
groundTruth: ""
|
|
499
501
|
});
|
|
500
502
|
}
|
|
503
|
+
const output = getAssistantMessageFromRunOutput(run.output) ?? "";
|
|
504
|
+
const groundTruth = typeof run.groundTruth === "string" ? run.groundTruth : JSON.stringify(run.groundTruth);
|
|
501
505
|
return createExtractPrompt({
|
|
502
|
-
output
|
|
503
|
-
groundTruth
|
|
506
|
+
output,
|
|
507
|
+
groundTruth
|
|
504
508
|
});
|
|
505
509
|
}
|
|
506
510
|
}).analyze({
|
|
507
511
|
description: "Compare semantic units between output and ground truth",
|
|
508
512
|
outputSchema: analyzeOutputSchema$7,
|
|
509
513
|
createPrompt: ({ results }) => {
|
|
514
|
+
const outputUnits = results.preprocessStepResult?.outputUnits || [];
|
|
515
|
+
const groundTruthUnits = results.preprocessStepResult?.groundTruthUnits || [];
|
|
510
516
|
return createAnalyzePrompt$7({
|
|
511
|
-
outputUnits
|
|
512
|
-
groundTruthUnits
|
|
517
|
+
outputUnits,
|
|
518
|
+
groundTruthUnits
|
|
513
519
|
});
|
|
514
520
|
}
|
|
515
521
|
}).generateScore(({ run, results }) => {
|
|
@@ -529,9 +535,7 @@ function createAnswerSimilarityScorer({ model, options = ANSWER_SIMILARITY_DEFAU
|
|
|
529
535
|
case "partial":
|
|
530
536
|
score += mergedOptions.semanticThreshold * .5;
|
|
531
537
|
break;
|
|
532
|
-
case "missing":
|
|
533
|
-
score -= mergedOptions.missingPenalty;
|
|
534
|
-
break;
|
|
538
|
+
case "missing": score -= mergedOptions.missingPenalty;
|
|
535
539
|
}
|
|
536
540
|
const maxPossibleScore = totalUnits * (1 + mergedOptions.exactMatchBonus);
|
|
537
541
|
score = score / maxPossibleScore;
|
|
@@ -545,9 +549,11 @@ function createAnswerSimilarityScorer({ model, options = ANSWER_SIMILARITY_DEFAU
|
|
|
545
549
|
description: "Generate explanation of similarity score",
|
|
546
550
|
createPrompt: ({ run, results, score }) => {
|
|
547
551
|
if (!run.groundTruth) return "No ground truth was provided for comparison. Score is 0 by default.";
|
|
552
|
+
const output = getAssistantMessageFromRunOutput(run.output) ?? "";
|
|
553
|
+
const groundTruth = typeof run.groundTruth === "string" ? run.groundTruth : JSON.stringify(run.groundTruth);
|
|
548
554
|
return createReasonPrompt$5({
|
|
549
|
-
output
|
|
550
|
-
groundTruth
|
|
555
|
+
output,
|
|
556
|
+
groundTruth,
|
|
551
557
|
score,
|
|
552
558
|
analysis: results.analyzeStepResult,
|
|
553
559
|
scale: mergedOptions.scale
|
|
@@ -761,7 +767,8 @@ function createFaithfulnessScorer({ model, options }) {
|
|
|
761
767
|
const totalClaims = results.preprocessStepResult?.claims?.length || verdicts.length;
|
|
762
768
|
const supportedClaims = verdicts.filter((v) => v.verdict.toLowerCase().trim() === "yes").length;
|
|
763
769
|
if (totalClaims === 0) return 0;
|
|
764
|
-
|
|
770
|
+
const score = Math.min(1, supportedClaims / totalClaims) * (options?.scale || 1);
|
|
771
|
+
return roundToTwoDecimals(score);
|
|
765
772
|
}).generateReason({
|
|
766
773
|
description: "Reason about the results",
|
|
767
774
|
createPrompt: ({ run, results, score }) => {
|
|
@@ -931,7 +938,8 @@ function createBiasScorer({ model, options }) {
|
|
|
931
938
|
}
|
|
932
939
|
}).generateScore(({ results }) => {
|
|
933
940
|
if (!results.analyzeStepResult || results.analyzeStepResult.results.length === 0) return 0;
|
|
934
|
-
|
|
941
|
+
const score = results.analyzeStepResult.results.filter((v) => v.result.toLowerCase() === "yes").length / results.analyzeStepResult.results.length;
|
|
942
|
+
return roundToTwoDecimals(score * (options?.scale || 1));
|
|
935
943
|
}).generateReason({
|
|
936
944
|
description: "Reason about the results",
|
|
937
945
|
createPrompt: ({ score, results }) => {
|
|
@@ -1189,7 +1197,8 @@ function createHallucinationScorer({ model, options }) {
|
|
|
1189
1197
|
const totalStatements = results.preprocessStepResult?.claims?.length || verdicts.length;
|
|
1190
1198
|
const contradictedStatements = verdicts.filter((v) => v.verdict.toLowerCase().trim() === "yes").length;
|
|
1191
1199
|
if (totalStatements === 0) return 0;
|
|
1192
|
-
|
|
1200
|
+
const score = Math.min(1, contradictedStatements / totalStatements) * (options?.scale || 1);
|
|
1201
|
+
return roundToTwoDecimals(score);
|
|
1193
1202
|
}).generateReason({
|
|
1194
1203
|
description: "Reason about the results",
|
|
1195
1204
|
createPrompt: async ({ run, results, score }) => {
|
|
@@ -1337,7 +1346,8 @@ function createToxicityScorer({ model, options }) {
|
|
|
1337
1346
|
if (numberOfVerdicts === 0) return 1;
|
|
1338
1347
|
let toxicityCount = 0;
|
|
1339
1348
|
for (const { verdict } of results.analyzeStepResult.verdicts) if (verdict.trim().toLowerCase() === "yes") toxicityCount++;
|
|
1340
|
-
|
|
1349
|
+
const score = toxicityCount / numberOfVerdicts;
|
|
1350
|
+
return roundToTwoDecimals(score * (options?.scale || 1));
|
|
1341
1351
|
}).generateReason({
|
|
1342
1352
|
description: "Reason about the results",
|
|
1343
1353
|
createPrompt: ({ results, score }) => {
|
|
@@ -1485,10 +1495,13 @@ function createToolCallAccuracyScorerLLM({ model, availableTools }) {
|
|
|
1485
1495
|
description: "Analyze the appropriateness of tool selections",
|
|
1486
1496
|
outputSchema: analyzeOutputSchema$6,
|
|
1487
1497
|
createPrompt: ({ run, results }) => {
|
|
1498
|
+
const userInput = getUserMessageFromRunInput(run.input) ?? "";
|
|
1499
|
+
const agentResponse = getAssistantMessageFromRunOutput(run.output) ?? "";
|
|
1500
|
+
const toolsCalled = results.preprocessStepResult?.actualTools || [];
|
|
1488
1501
|
return createAnalyzePrompt$6({
|
|
1489
|
-
userInput
|
|
1490
|
-
agentResponse
|
|
1491
|
-
toolsCalled
|
|
1502
|
+
userInput,
|
|
1503
|
+
agentResponse,
|
|
1504
|
+
toolsCalled,
|
|
1492
1505
|
availableTools: toolDefinitions
|
|
1493
1506
|
});
|
|
1494
1507
|
}
|
|
@@ -1501,11 +1514,14 @@ function createToolCallAccuracyScorerLLM({ model, availableTools }) {
|
|
|
1501
1514
|
}).generateReason({
|
|
1502
1515
|
description: "Generate human-readable explanation of tool selection evaluation",
|
|
1503
1516
|
createPrompt: ({ run, results, score }) => {
|
|
1517
|
+
const userInput = getUserMessageFromRunInput(run.input) ?? "";
|
|
1518
|
+
const evaluations = results.analyzeStepResult?.evaluations || [];
|
|
1519
|
+
const missingTools = results.analyzeStepResult?.missingTools || [];
|
|
1504
1520
|
return createReasonPrompt$4({
|
|
1505
|
-
userInput
|
|
1521
|
+
userInput,
|
|
1506
1522
|
score,
|
|
1507
|
-
evaluations
|
|
1508
|
-
missingTools
|
|
1523
|
+
evaluations,
|
|
1524
|
+
missingTools
|
|
1509
1525
|
});
|
|
1510
1526
|
}
|
|
1511
1527
|
});
|
|
@@ -1767,7 +1783,8 @@ function createContextRelevanceScorerLLM({ model, options }) {
|
|
|
1767
1783
|
const usagePenalty = highRelevanceUnused * unusedPenaltyRate;
|
|
1768
1784
|
const missingContext = results.analyzeStepResult?.missingContext || [];
|
|
1769
1785
|
const missingContextPenalty = Math.min(missingContext.length * missingPenaltyRate, maxMissingPenalty);
|
|
1770
|
-
|
|
1786
|
+
const scaledScore = Math.max(0, relevanceScore - usagePenalty - missingContextPenalty) * (options.scale || 1);
|
|
1787
|
+
return roundToTwoDecimals(scaledScore);
|
|
1771
1788
|
}).generateReason({
|
|
1772
1789
|
description: "Generate human-readable explanation of context relevance evaluation",
|
|
1773
1790
|
createPrompt: ({ run, results, score }) => {
|
|
@@ -1964,7 +1981,8 @@ function createContextPrecisionScorer({ model, options }) {
|
|
|
1964
1981
|
sumPrecision += precisionAtI;
|
|
1965
1982
|
}
|
|
1966
1983
|
if (relevantCount === 0) return 0;
|
|
1967
|
-
|
|
1984
|
+
const score = sumPrecision / relevantCount * (options.scale || 1);
|
|
1985
|
+
return roundToTwoDecimals(score);
|
|
1968
1986
|
}).generateReason({
|
|
1969
1987
|
description: "Reason about the context precision results",
|
|
1970
1988
|
createPrompt: ({ run, results, score }) => {
|
|
@@ -2186,7 +2204,8 @@ function createContextRecallScorer({ model, options }) {
|
|
|
2186
2204
|
const totalClaims = results.preprocessStepResult?.claims?.length ?? 0;
|
|
2187
2205
|
if (totalClaims === 0) return 0;
|
|
2188
2206
|
const attributedClaims = (results.analyzeStepResult?.verdicts || []).filter((v) => v.verdict.toLowerCase().trim() === "yes").length;
|
|
2189
|
-
|
|
2207
|
+
const score = Math.min(1, attributedClaims / totalClaims) * (options.scale || 1);
|
|
2208
|
+
return roundToTwoDecimals(score);
|
|
2190
2209
|
}).generateReason({
|
|
2191
2210
|
description: "Explain the context recall evaluation results",
|
|
2192
2211
|
createPrompt: ({ run, results, score }) => {
|
|
@@ -3039,7 +3058,8 @@ function createPromptAlignmentScorerLLM({ model, options }) {
|
|
|
3039
3058
|
const systemScore = userScore;
|
|
3040
3059
|
weightedScore = userScore * SCORING_WEIGHTS.BOTH.USER_WEIGHT + systemScore * SCORING_WEIGHTS.BOTH.SYSTEM_WEIGHT;
|
|
3041
3060
|
}
|
|
3042
|
-
|
|
3061
|
+
const finalScore = weightedScore * scale;
|
|
3062
|
+
return roundToTwoDecimals(finalScore);
|
|
3043
3063
|
}).generateReason({
|
|
3044
3064
|
description: "Generate human-readable explanation of prompt alignment evaluation",
|
|
3045
3065
|
createPrompt: ({ run, results, score }) => {
|
|
@@ -3878,17 +3898,18 @@ function createTrajectoryAccuracyScorerLLM({ model, expectedTrajectory: staticEx
|
|
|
3878
3898
|
}).preprocess(async ({ run }) => {
|
|
3879
3899
|
const actualTrajectory = run.output;
|
|
3880
3900
|
let expectedSteps;
|
|
3881
|
-
if (staticExpectedTrajectory)
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
const
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3901
|
+
if (staticExpectedTrajectory) {
|
|
3902
|
+
if (Array.isArray(staticExpectedTrajectory)) expectedSteps = staticExpectedTrajectory;
|
|
3903
|
+
else {
|
|
3904
|
+
const toExpectedStep = (s) => {
|
|
3905
|
+
const { durationMs: _, metadata: _m, children, ...rest } = s;
|
|
3906
|
+
const result = rest;
|
|
3907
|
+
if (children && children.length > 0) result.children = { steps: children.map(toExpectedStep) };
|
|
3908
|
+
return result;
|
|
3909
|
+
};
|
|
3910
|
+
expectedSteps = staticExpectedTrajectory.steps.map(toExpectedStep);
|
|
3911
|
+
}
|
|
3912
|
+
} else if (run.expectedTrajectory) {
|
|
3892
3913
|
const expectation = run.expectedTrajectory;
|
|
3893
3914
|
expectedSteps = expectation.steps && expectation.steps.length > 0 ? expectation.steps : void 0;
|
|
3894
3915
|
}
|
|
@@ -3902,9 +3923,11 @@ function createTrajectoryAccuracyScorerLLM({ model, expectedTrajectory: staticEx
|
|
|
3902
3923
|
description: "Analyze the quality and appropriateness of the agent trajectory",
|
|
3903
3924
|
outputSchema: analyzeOutputSchema,
|
|
3904
3925
|
createPrompt: ({ run, results }) => {
|
|
3926
|
+
const userInput = getUserMessageFromRunInput(run.input) ?? "";
|
|
3927
|
+
const agentResponse = getAssistantMessageFromRunOutput(run.output.rawOutput) ?? "";
|
|
3905
3928
|
return createAnalyzePrompt({
|
|
3906
|
-
userInput
|
|
3907
|
-
agentResponse
|
|
3929
|
+
userInput,
|
|
3930
|
+
agentResponse,
|
|
3908
3931
|
actualTrajectory: results.preprocessStepResult?.actualTrajectoryFormatted ?? "No steps taken",
|
|
3909
3932
|
expectedTrajectory: results.preprocessStepResult?.expectedTrajectoryFormatted
|
|
3910
3933
|
});
|
|
@@ -3930,12 +3953,16 @@ function createTrajectoryAccuracyScorerLLM({ model, expectedTrajectory: staticEx
|
|
|
3930
3953
|
}).generateReason({
|
|
3931
3954
|
description: "Generate human-readable explanation of trajectory evaluation",
|
|
3932
3955
|
createPrompt: ({ run, results, score }) => {
|
|
3956
|
+
const userInput = getUserMessageFromRunInput(run.input) ?? "";
|
|
3957
|
+
const stepEvaluations = results.analyzeStepResult?.stepEvaluations || [];
|
|
3958
|
+
const missingSteps = results.analyzeStepResult?.missingSteps || [];
|
|
3959
|
+
const extraSteps = results.analyzeStepResult?.extraSteps || [];
|
|
3933
3960
|
return createReasonPrompt({
|
|
3934
|
-
userInput
|
|
3961
|
+
userInput,
|
|
3935
3962
|
score,
|
|
3936
|
-
stepEvaluations
|
|
3937
|
-
missingSteps
|
|
3938
|
-
extraSteps
|
|
3963
|
+
stepEvaluations,
|
|
3964
|
+
missingSteps,
|
|
3965
|
+
extraSteps
|
|
3939
3966
|
});
|
|
3940
3967
|
}
|
|
3941
3968
|
});
|