@mastra/evals 1.0.1 → 1.1.0

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.
@@ -1,4 +1,4 @@
1
- import { getAssistantMessageFromRunOutput, getUserMessageFromRunInput, roundToTwoDecimals, extractToolCalls, getCombinedSystemPrompt, getTextContentFromMastraDBMessage } from '../../chunk-6EA6D7JG.js';
1
+ import { getAssistantMessageFromRunOutput, getUserMessageFromRunInput, roundToTwoDecimals, extractToolCalls, getCombinedSystemPrompt, getTextContentFromMastraDBMessage } from '../../chunk-OEOE7ZHN.js';
2
2
  import { createScorer } from '@mastra/core/evals';
3
3
  import { z } from 'zod';
4
4
  import nlp from 'compromise';
@@ -1114,10 +1114,16 @@ function createHallucinationScorer({
1114
1114
  outputSchema: z.object({
1115
1115
  verdicts: z.array(z.object({ statement: z.string(), verdict: z.string(), reason: z.string() }))
1116
1116
  }),
1117
- createPrompt: ({ results }) => {
1117
+ createPrompt: async ({ run, results }) => {
1118
+ let context;
1119
+ if (options?.getContext) {
1120
+ context = await options.getContext({ run, results, step: "analyze" });
1121
+ } else {
1122
+ context = options?.context ?? [];
1123
+ }
1118
1124
  const prompt = createHallucinationAnalyzePrompt({
1119
1125
  claims: results.preprocessStepResult.claims,
1120
- context: options?.context || []
1126
+ context
1121
1127
  });
1122
1128
  return prompt;
1123
1129
  }
@@ -1131,11 +1137,17 @@ function createHallucinationScorer({
1131
1137
  return roundToTwoDecimals(score);
1132
1138
  }).generateReason({
1133
1139
  description: "Reason about the results",
1134
- createPrompt: ({ run, results, score }) => {
1140
+ createPrompt: async ({ run, results, score }) => {
1141
+ let context;
1142
+ if (options?.getContext) {
1143
+ context = await options.getContext({ run, results, score, step: "generateReason" });
1144
+ } else {
1145
+ context = options?.context ?? [];
1146
+ }
1135
1147
  const prompt = createHallucinationReasonPrompt({
1136
1148
  input: getUserMessageFromRunInput(run.input) ?? "",
1137
1149
  output: getAssistantMessageFromRunOutput(run.output) ?? "",
1138
- context: options?.context || [],
1150
+ context,
1139
1151
  score,
1140
1152
  scale: options?.scale || 1,
1141
1153
  verdicts: results.analyzeStepResult?.verdicts || []