-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.ts
More file actions
761 lines (707 loc) · 26.7 KB
/
run.ts
File metadata and controls
761 lines (707 loc) · 26.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/**
* Evaluation utils for the Humanloop SDK.
*
* This module provides a set of utilities to aid running Eval workflows on Humanloop
* where you are managing the runtime of your application in your code.
*
* Functions in this module should be accessed via the Humanloop client. They should
* not be called directly.
*/
import cliProgress from "cli-progress";
import { Humanloop, HumanloopClient } from "index";
import _ from "lodash";
import pMap from "p-map";
import {
BooleanEvaluatorStatsResponse,
CreateEvaluatorLogResponse,
CreateFlowLogResponse,
CreatePromptLogResponse,
CreateToolLogResponse,
DatapointResponse,
EvaluationResponse,
EvaluationStats,
EvaluatorResponse,
EvaluatorsRequest,
ExternalEvaluatorRequest,
FileType,
FlowLogRequest,
FlowRequest,
NumericEvaluatorStatsResponse,
PromptLogRequest,
PromptRequest,
RunStatsResponse,
ToolLogRequest,
ToolRequest,
} from "../api";
import { Flows } from "../api/resources/flows/client/Client";
import { Prompts } from "../api/resources/prompts/client/Client";
import { jsonifyIfNotString } from "../otel/helpers";
import { evaluationContext } from "./context";
import { Dataset, Evaluator, EvaluatorCheck, File, FileResponse } from "./types";
// ANSI escape codes for logging colors
const YELLOW = "\x1b[93m";
const CYAN = "\x1b[96m";
const GREEN = "\x1b[92m";
const RED = "\x1b[91m";
const RESET = "\x1b[0m";
type LogResponse =
| CreateFlowLogResponse
| CreatePromptLogResponse
| CreateToolLogResponse
| CreateEvaluatorLogResponse;
export function overloadLog<T extends Flows | Prompts>(client: T): T {
const originalLog = client.log.bind(client);
const _overloadedLog = async (
request: T extends Flows ? FlowLogRequest : PromptLogRequest,
options?: T extends Flows ? Flows.RequestOptions : Prompts.RequestOptions,
) => {
let response: LogResponse | undefined;
if (evaluationContext.isEvaluatedFile(request)) {
const state = evaluationContext.getState();
if (state === undefined) {
throw Error(
"Internal Error: EvaluationContext state used without being called set before.",
);
}
const { runId, sourceDatapointId, uploadCallback } =
evaluationContext.getDatapoint({
inputs: request.inputs,
messages: request.messages,
});
if (request.runId === undefined) {
request = {
...request,
runId,
};
}
if (request.sourceDatapointId === undefined) {
request = {
...request,
sourceDatapointId: sourceDatapointId,
};
}
if (client instanceof Flows) {
request = {
...request,
traceStatus: "complete",
};
}
if ("flow" in request) {
if (!_.isEqual(state.evaluatedVersion, request.flow)) {
response = await originalLog(
{
...request,
// @ts-ignore Log under the version expected by evaluation, not
// one determined by decorators. Otherwise the log will be found
// in the File's Log but not appear in the Evaluation, which can
// lead to confusion
flow: state?.evaluatedVersion,
output: undefined,
error: `The version of the evaluated Flow must match the version of the callable. Expected: ${JSON.stringify(state!.evaluatedVersion)}, got: ${JSON.stringify(request.flow)}`,
},
options,
);
}
}
if ("prompt" in request) {
if (!_.isEqual(state.evaluatedVersion, request.prompt)) {
response = await originalLog({
...request,
// @ts-ignore Log under the version expected by evaluation, not
// one determined by decorators. Otherwise the evaluation will stale
prompt: state?.evaluatedVersion,
output: undefined,
error: `The version of the evaluated Prompt must match the version of the callable. Expected: ${JSON.stringify(state!.evaluatedVersion)}, got: ${JSON.stringify(request.prompt)}`,
});
}
}
if (response === undefined) {
// Version validation passed, make a normal request
response = await originalLog(request, options);
}
uploadCallback(response.id);
} else {
// @ts-ignore
response = await originalLog(request, options);
}
return response;
};
// @ts-ignore _overloadedLog is a polymorphic function and
// linting complains about typing
client.log = _overloadedLog.bind(client);
return client;
}
export async function runEval(
client: HumanloopClient,
file: File,
dataset: Dataset,
name?: string,
evaluators: Evaluator[] = [],
concurrency: number = 8,
): Promise<EvaluatorCheck[]> {
// Get or create the file on Humanloop
if (!file.path && !file.id) {
throw new Error("You must provide a path or id in your `file`.");
}
if (concurrency > 32) {
console.log("Warning: Too many parallel workers, capping the number to 32.");
}
concurrency = Math.min(concurrency, 32);
if (file.callable && "path" in file.callable) {
if (file.path !== file.callable.path) {
throw new Error(
`The path of the evaluated \`file\` must match the path of your decorated \`callable\`. Expected path: ${file.path}, got: ${file.callable.path}`,
);
}
}
if (file.callable && "version" in file.callable) {
if (!_.isEqual(file.version, file.callable.version)) {
throw new Error(
`The version of the evaluated \`file\` must match the version of your decorated \`callable\`. Expected version: ${JSON.stringify(file.version)}, got: ${JSON.stringify(file.callable.version)}`,
);
}
}
let type: FileType;
if (file.type) {
type = file.type;
console.info(
`${CYAN}Evaluating your ${type} function corresponding to ${file.path} on Humanloop${RESET}\n\n`,
);
} else {
type = "flow";
console.warn("No file type specified, defaulting to flow.");
}
const function_ = file.callable;
if (!function_) {
if (type === "flow") {
throw new Error(
"You must provide a callable for your Flow file to run a local eval.",
);
} else {
console.info(
`No callable provided for your ${type} file - will attempt to generate logs on Humanloop.`,
);
}
}
const { callable, version, ...rest } = file;
let hlFile: FileResponse;
switch (type) {
case "flow": {
try {
// Be more lenient with Flow versions as they are arbitrary json
if (version && !version.attributes) {
version.attributes = version as Record<string, unknown>;
}
const updatedData = { ...rest, ...version } as FlowRequest;
hlFile = await client.flows.upsert(updatedData);
} catch (e) {
throw new Error(
`Error upserting the Flow associated with callable ${callable?.name}: ${e}`,
);
}
break;
}
case "prompt": {
try {
hlFile = await client.prompts.upsert({
...rest,
...version,
} as PromptRequest);
} catch (e) {
throw new Error(
`Error upserting the Prompt associated with callable ${callable?.name}: ${e}`,
);
}
break;
}
case "tool": {
try {
hlFile = await client.tools.upsert({
...rest,
...version,
} as ToolRequest);
} catch (e) {
throw new Error(
`Error upserting the Tool associated with callable ${callable?.name}: ${e}`,
);
}
break;
}
case "evaluator": {
try {
// @ts-ignore EvaluatorRequest is generated by Fern as 'unknown'
// Leading to a type error here
hlFile = await client.evaluators.upsert({
...rest,
...version,
} as EvaluatorsRequest);
} catch (e) {
throw new Error(
`Error upserting the Evaluator associated with callable ${callable?.name}: ${e}`,
);
}
break;
}
default:
throw new Error(`Unsupported File type: ${type}`);
}
// Upsert the dataset
if (dataset.action === undefined) {
dataset.action = "set";
}
if (dataset.datapoints === undefined) {
// Use `upsert` to get existing dataset ID if no datapoints provided, given we can't `get` on path.
dataset.datapoints = [];
dataset.action = "set";
}
let hlDataset = await client.datasets.upsert(dataset);
hlDataset = await client.datasets.get(hlDataset.id, {
versionId: hlDataset.versionId,
includeDatapoints: true,
});
// Upsert the local Evaluators; other Evaluators are just referenced by `path` or `id`
let localEvaluators: [EvaluatorResponse, Function][] = [];
if (evaluators) {
const evaluatorsWithCallable = evaluators.filter(
(e) => e.callable !== undefined,
);
if (evaluatorsWithCallable.length > 0 && function_ == null) {
throw new Error(
`Local Evaluators are only supported when generating Logs locally using your ${type}'s 'callable'. Please provide a 'callable' for your file in order to run Evaluators locally.`,
);
}
const upsertEvaluatorsPromises = evaluatorsWithCallable.map(
async (evaluator) => {
if (
evaluator.argsType === undefined ||
evaluator.returnType === undefined
) {
throw new Error(
`You must provide 'argsType', 'returnType' and for your local Evaluator: ${evaluator.path}`,
);
}
const spec: ExternalEvaluatorRequest = {
argumentsType: evaluator.argsType,
returnType: evaluator.returnType,
attributes: { code: evaluator.callable!.toString() },
evaluatorType: "external",
};
const evaluatorResponse = await client.evaluators.upsert({
id: evaluator.id,
path: evaluator.path,
spec,
});
localEvaluators.push([evaluatorResponse, evaluator.callable!]);
},
);
await Promise.all(upsertEvaluatorsPromises);
}
// Validate upfront that the local Evaluators and Dataset fit
const requiresTarget = localEvaluators.find(
([evaluator, _]) => evaluator.spec.argumentsType === "target_required",
);
if (requiresTarget) {
if (!hlDataset.datapoints) {
throw new Error("Datapoints are undefined.");
}
const missingTargets = hlDataset.datapoints.filter(
(datapoint) => !datapoint.target,
).length;
if (missingTargets > 0) {
localEvaluators.forEach(([evaluator, _]) => {
if (evaluator.spec.argumentsType === "target_required") {
throw new Error(
`${missingTargets} Datapoints have no target. A target is required for the Evaluator: ${evaluator.path}`,
);
}
});
}
}
// Get or create the Evaluation based on the name
let evaluation = null;
try {
evaluation = await client.evaluations.create({
name,
evaluators: evaluators.map(
(evaluator) => ({ path: evaluator.path }) as { path: string },
),
file: { id: hlFile.id },
});
} catch (error: any) {
// If the name exists, go and get it
// TODO: Update API GET to allow querying by name and file.
if (error.statusCode === 409) {
const evals = await client.evaluations.list({
fileId: hlFile.id,
size: 50,
});
for await (const e of evals) {
if (e.name === name) {
evaluation = e;
break;
}
}
}
if (!evaluation) {
throw new Error(`Evaluation with name ${name} not found.`);
}
}
// Create a new Run
const run = await client.evaluations.createRun(evaluation.id, {
dataset: { versionId: hlDataset.versionId },
version: { versionId: hlFile.versionId },
orchestrated: function_ ? false : true,
useExistingLogs: false,
});
const runId = run.id;
// Configure the progress bar
const progressBar = new cliProgress.SingleBar(
{
format:
"Progress |" +
"{bar}" +
"| {percentage}% || {value}/{total} Datapoints",
},
cliProgress.Presets.shades_classic,
);
// Set the Evaluation context
evaluationContext.setState({
fileId: hlFile.id,
path: hlFile.path,
uploadCallback: async (logId: string, datapoint: DatapointResponse) => {
await runLocalEvaluators(client, logId, datapoint, localEvaluators);
progressBar.increment();
},
evaluatedVersion: file.version,
});
async function processDatapoint(
datapoint: DatapointResponse,
runId: string,
): Promise<void> {
const start_time = new Date();
const logFunc = getLogFunction(
client,
type,
hlFile.id,
hlFile.versionId,
runId,
);
try {
evaluationContext.addDatapoint(datapoint, runId);
let output: string;
if (datapoint.inputs === undefined) {
throw new Error(`Datapoint 'inputs' attribute is undefined.`);
}
output = await function_!(
// @ts-ignore
datapoint.inputs,
datapoint.messages,
);
output = jsonifyIfNotString(function_!, output);
if (
evaluationContext.peekDatapoint({
inputs: datapoint.inputs,
messages: datapoint.messages,
})
) {
// function_ is a simple callable, so we create the log here
// if function_ was a utility wrapped function, the utility
// would have created the log in otel.HumanloopSpanExporter
// The log function will take care of the sourceDatapointId and runId from the context
// See overloadLog in this module for more details
await logFunc({
inputs: { ...datapoint.inputs },
messages: datapoint.messages,
output: output,
startTime: start_time,
endTime: new Date(),
});
}
} catch (e) {
const errorMessage = e instanceof Error ? e.message : String(e);
await logFunc({
inputs: { ...datapoint.inputs },
error: errorMessage,
sourceDatapointId: datapoint.id,
startTime: start_time,
endTime: new Date(),
});
// console.log(e);
console.warn(
`\nYour ${type}'s callable failed for Datapoint: ${datapoint.id}.\nError: ${errorMessage}`,
);
}
}
console.log(`\n${CYAN}Navigate to your Evaluation:${RESET}\n${evaluation.url}\n`);
console.log(
`${CYAN}${type.charAt(0).toUpperCase() + type.slice(1)} Version ID: ${
hlFile.versionId
}${RESET}`,
);
console.log(`${CYAN}Run ID: ${runId}${RESET}`);
// Generate locally if a function is provided
if (function_) {
console.log(
`${CYAN}\nRunning ${hlFile.name} over the Dataset ${hlDataset.name}${RESET}`,
);
const totalDatapoints = hlDataset.datapoints!.length;
progressBar.start(totalDatapoints, 0);
await pMap(
hlDataset.datapoints!,
async (datapoint) => {
await processDatapoint(datapoint, runId);
},
{ concurrency: concurrency },
);
progressBar.stop();
} else {
// TODO: trigger run when updated API is available
console.log(
`${CYAN}\nRunning ${hlFile.name} over the Dataset ${hlDataset.name}${RESET}`,
);
}
// Wait for the Evaluation to complete then print the results
let stats;
do {
stats = await client.evaluations.getStats(evaluation.id);
console.log(`\r${stats.progress}`);
if (stats.status !== "completed") {
await new Promise((resolve) => setTimeout(resolve, 5000));
}
} while (stats.status !== "completed");
console.log(stats.report);
const checks: EvaluatorCheck[] = [];
if (
evaluators.some((evaluator) => evaluator.threshold !== undefined) ||
stats.runStats.length > 1
) {
for (const evaluator of evaluators) {
const [_, score, delta] = checkEvaluationImprovement(
evaluation,
evaluator.path!,
stats,
runId,
);
let thresholdCheck = undefined;
if (evaluator.threshold !== undefined) {
thresholdCheck = score >= evaluator.threshold;
thresholdCheck = checkEvaluationThreshold(
evaluation,
stats,
evaluator.path!,
evaluator.threshold,
runId,
);
}
checks.push({
path: evaluator.path!,
// TODO: Add back in with number valence on Evaluators
// improvementCheck: improvementCheck,
score: score,
delta: delta,
threshold: evaluator.threshold,
thresholdCheck: thresholdCheck,
evaluationId: evaluation.id,
});
}
}
console.info(`\n${CYAN}View your Evaluation:${RESET}\n${evaluation.url}\n`);
return checks;
}
/**
* Returns the appropriate log function pre-filled with common parameters.
*
* @param client - The HumanloopClient instance used to make API calls.
* @param type - The type of file for which the log function is being generated. Can be "flow", "prompt", or "tool".
* @param fileId - The ID of the file.
* @param versionId - The version ID of the file.
* @param runId - The run ID associated with the log.
* @returns A function that logs data to the appropriate endpoint based on the file type.
* @throws {Error} If the provided file type is unsupported.
*/
function getLogFunction(
client: HumanloopClient,
type: FileType,
fileId: string,
versionId: string,
runId: string,
) {
const logRequest = {
// TODO: why does the Log `id` field refer to the file ID in the API?
// Why are both `id` and `version_id` needed in the API?
id: fileId,
versionId,
runId,
};
switch (type) {
case "flow":
return async (args: FlowLogRequest) =>
await client.flows.log({
...logRequest,
traceStatus: "complete",
...args,
});
case "prompt":
return async (args: PromptLogRequest) =>
await client.prompts.log({ ...logRequest, ...args });
// case "evaluator":
// return (args: CreateEvaluatorLogRequest) =>
// client.evaluators.log({ ...logRequest, ...args });
case "tool":
return async (args: ToolLogRequest) =>
await client.tools.log({ ...logRequest, ...args });
default:
throw new Error(`Unsupported File version: ${type}`);
}
}
async function runLocalEvaluators(
client: HumanloopClient,
logId: string,
datapoint: DatapointResponse | undefined,
localEvaluators: [EvaluatorResponse, Function][],
) {
const log = await client.logs.get(logId);
const promises = localEvaluators.map(async ([evaluator, evalFunction]) => {
const startTime = new Date();
let judgment: any | undefined;
try {
if (evaluator.spec.argumentsType === "target_required") {
judgment = await evalFunction(log, datapoint);
} else {
judgment = await evalFunction(log);
}
await client.evaluators.log({
path: evaluator.path,
versionId: evaluator.versionId,
parentId: logId,
judgment: judgment,
startTime: startTime,
endTime: new Date(),
});
} catch (e) {
await client.evaluators.log({
path: evaluator.path,
versionId: evaluator.versionId,
parentId: logId,
error: e instanceof Error ? e.message : String(e),
startTime: startTime,
endTime: new Date(),
});
console.warn(`\nEvaluator ${evaluator.path} failed with error ${e}`);
}
});
await Promise.all(promises);
}
function checkEvaluationImprovement(
evaluation: EvaluationResponse,
evaluatorPath: string,
stats: EvaluationStats,
runId: string,
): [boolean, number, number] {
const runStats = stats.runStats.find((run) => run.runId === runId);
if (!runStats) {
throw new Error(`Run ${runId} not found in Evaluation ${evaluation.id}`);
}
const latestEvaluatorStatsByPath = getEvaluatorStatsByPath(runStats, evaluation);
if (stats.runStats.length == 1) {
console.log(`${YELLOW}⚠️ No previous versions to compare with.${RESET}`);
return [true, 0, 0];
}
// Latest Run is at index 0, previous Run is at index 1
const previousEvaluatorStatsByPath = getEvaluatorStatsByPath(
stats.runStats[1],
evaluation,
);
if (
evaluatorPath in latestEvaluatorStatsByPath &&
evaluatorPath in previousEvaluatorStatsByPath
) {
const latestEvaluatorStats = latestEvaluatorStatsByPath[evaluatorPath];
const previousEvaluatorStats = previousEvaluatorStatsByPath[evaluatorPath];
const latestScore = getScoreFromEvaluatorStat(latestEvaluatorStats);
const previousScore = getScoreFromEvaluatorStat(previousEvaluatorStats);
if (latestScore === null || previousScore === null) {
throw new Error(`Could not find score for Evaluator ${evaluatorPath}`);
}
let diff = latestScore - previousScore;
// Round to 2 decimal places
diff = Math.round(diff * 100) / 100;
console.log(
`${CYAN}Change of [${diff}] for Evaluator ${evaluatorPath}${RESET}`,
);
return [diff >= 0, latestScore, diff];
} else {
throw Error(`Evaluator ${evaluatorPath} not found in the stats.`);
}
}
function getScoreFromEvaluatorStat(
stat: NumericEvaluatorStatsResponse | BooleanEvaluatorStatsResponse,
): number | null {
let score: number | null = null;
if ("numTrue" in stat) {
score =
((stat as BooleanEvaluatorStatsResponse).numTrue as number) /
(stat as BooleanEvaluatorStatsResponse).totalLogs;
// Round to 2 decimal places
score = Math.round(score * 100) / 100;
} else if ("mean" in stat && stat.mean !== undefined) {
// Round to 2 decimal places
score = Math.round(stat.mean * 100) / 100;
} else {
throw new Error(`Unexpected EvaluatorStats type: ${stat}`);
}
return score;
}
function getEvaluatorStatsByPath(
stats: RunStatsResponse,
evaluation: EvaluationResponse,
): { [key: string]: NumericEvaluatorStatsResponse | BooleanEvaluatorStatsResponse } {
const evaluatorsById = {} as {
[key: string]: Humanloop.EvaluationEvaluatorResponse;
};
for (const evaluator of evaluation.evaluators) {
evaluatorsById[evaluator.version.versionId] = evaluator;
}
const evaluatorStatsByPath = {} as {
[key: string]: NumericEvaluatorStatsResponse | BooleanEvaluatorStatsResponse;
};
for (const evaluatorStats of stats.evaluatorStats) {
const evaluator = evaluatorsById[evaluatorStats.evaluatorVersionId];
evaluatorStatsByPath[evaluator.version.path] = evaluatorStats as
| NumericEvaluatorStatsResponse
| BooleanEvaluatorStatsResponse;
}
return evaluatorStatsByPath;
}
function checkEvaluationThreshold(
evaluation: EvaluationResponse,
stats: EvaluationStats,
evaluatorPath: string,
threshold: number,
runId: string,
) {
const runStats = stats.runStats.find((run) => run.runId === runId);
if (!runStats) {
throw new Error(`Run ${runId} not found in Evaluation ${evaluation.id}`);
}
const evaluatorStatsByPath = getEvaluatorStatsByPath(runStats, evaluation);
if (evaluatorPath in evaluatorStatsByPath) {
const evaluatorStats = evaluatorStatsByPath[evaluatorPath];
const score = getScoreFromEvaluatorStat(evaluatorStats);
if (score === null) {
throw new Error(`Could not find score for Evaluator ${evaluatorPath}`);
}
if (score >= threshold) {
console.log(
`${GREEN}✅ Latest eval [${score}] above threshold [${threshold}] for Evaluator ${evaluatorPath}.${RESET}`,
);
} else {
console.log(
`${RED}❌ Latest eval [${score}] below threshold [${threshold}] for Evaluator ${evaluatorPath}.${RESET}`,
);
}
return score >= threshold;
} else {
throw new Error(`Evaluator ${evaluatorPath} not found in the stats.`);
}
}