@anvia/core 0.26.0 → 1.0.0-rc.2
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/README.md +303 -94
- package/dist/agent/index.d.ts +36 -70
- package/dist/agent/index.js +25 -18
- package/dist/agent-yBG8e9Jj.d.ts +153 -0
- package/dist/chunk-4WI3VGZK.js +127 -0
- package/dist/chunk-4WI3VGZK.js.map +1 -0
- package/dist/chunk-77AIYARB.js +654 -0
- package/dist/chunk-77AIYARB.js.map +1 -0
- package/dist/chunk-AI5JMUW7.js +45 -0
- package/dist/chunk-AI5JMUW7.js.map +1 -0
- package/dist/chunk-BEYBU7VJ.js +53 -0
- package/dist/chunk-BEYBU7VJ.js.map +1 -0
- package/dist/chunk-CWM7B2OO.js +315 -0
- package/dist/chunk-CWM7B2OO.js.map +1 -0
- package/dist/chunk-D37WMSP6.js +131 -0
- package/dist/chunk-D37WMSP6.js.map +1 -0
- package/dist/chunk-DBSCKTUL.js +3793 -0
- package/dist/chunk-DBSCKTUL.js.map +1 -0
- package/dist/chunk-EINTGEGY.js +629 -0
- package/dist/chunk-EINTGEGY.js.map +1 -0
- package/dist/chunk-FMHLROPQ.js +351 -0
- package/dist/chunk-FMHLROPQ.js.map +1 -0
- package/dist/chunk-FN7HLLAZ.js +211 -0
- package/dist/chunk-FN7HLLAZ.js.map +1 -0
- package/dist/chunk-GKDERULJ.js +50 -0
- package/dist/chunk-GKDERULJ.js.map +1 -0
- package/dist/{chunk-CWUJUSOS.js → chunk-KIDGIJM7.js} +26 -5
- package/dist/chunk-KIDGIJM7.js.map +1 -0
- package/dist/chunk-KR3RCCHJ.js +500 -0
- package/dist/chunk-KR3RCCHJ.js.map +1 -0
- package/dist/chunk-MGNTXGTX.js +37 -0
- package/dist/chunk-MGNTXGTX.js.map +1 -0
- package/dist/{chunk-MRQLEK2B.js → chunk-OJH6HWHX.js} +63 -51
- package/dist/chunk-OJH6HWHX.js.map +1 -0
- package/dist/chunk-QOUPWOGW.js +29 -0
- package/dist/chunk-QOUPWOGW.js.map +1 -0
- package/dist/chunk-TIZYTPJO.js +208 -0
- package/dist/chunk-TIZYTPJO.js.map +1 -0
- package/dist/{chunk-NCPN4SJR.js → chunk-XKYYBABH.js} +13 -13
- package/dist/chunk-XKYYBABH.js.map +1 -0
- package/dist/client-B8DT1vUG.d.ts +83 -0
- package/dist/completion/index.d.ts +6 -36
- package/dist/completion/index.js +25 -29
- package/dist/dynamic-tools-KwEGRbHp.d.ts +45 -0
- package/dist/embeddings/index.d.ts +11 -9
- package/dist/embeddings/index.js +2 -4
- package/dist/evals/index.d.ts +47 -20
- package/dist/evals/index.js +104 -65
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +27 -42
- package/dist/extractor/index.js +7 -22
- package/dist/guardrails/index.d.ts +3 -2
- package/dist/guardrails/index.js +1 -1
- package/dist/image-generation/index.d.ts +23 -23
- package/dist/image-generation/index.js +5 -39
- package/dist/image-generation/index.js.map +1 -1
- package/dist/index.d.ts +25 -20
- package/dist/index.js +60 -63
- package/dist/internal/agent.d.ts +163 -9
- package/dist/internal/agent.js +25 -18
- package/dist/loaders/index.d.ts +6 -10
- package/dist/loaders/index.js.map +1 -1
- package/dist/mcp/index.d.ts +19 -13
- package/dist/mcp/index.js +13 -348
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory/index.d.ts +20 -6
- package/dist/memory/index.js +9 -10
- package/dist/message-schema-Cn7ezRfJ.d.ts +52 -0
- package/dist/middleware-C7PdmKF7.d.ts +56 -0
- package/dist/model-call-options-CZkSw_xN.d.ts +6 -0
- package/dist/model-listing/index.d.ts +3 -1
- package/dist/observability/index.d.ts +20 -3
- package/dist/observability/index.js +8 -5
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +114 -72
- package/dist/pipeline/index.js +478 -286
- package/dist/pipeline/index.js.map +1 -1
- package/dist/retry-CjvSlKGW.d.ts +16 -0
- package/dist/skills/index.d.ts +5 -4
- package/dist/skills/index.js +7 -8
- package/dist/speech-generation/index.d.ts +37 -0
- package/dist/speech-generation/index.js +8 -0
- package/dist/streaming/index.js +37 -3
- package/dist/streaming/index.js.map +1 -1
- package/dist/{think-tool-DfCMuO8e.d.ts → think-tool-6H2QNQzQ.d.ts} +5 -5
- package/dist/tool/index.d.ts +10 -6
- package/dist/tool/index.js +15 -21
- package/dist/tool--Mz4v1eL.d.ts +57 -0
- package/dist/transcription/index.d.ts +29 -22
- package/dist/transcription/index.js +5 -57
- package/dist/transcription/index.js.map +1 -1
- package/dist/type-utils-CtHVDRn_.d.ts +6 -0
- package/dist/types-3x3mOLHU.d.ts +379 -0
- package/dist/types-BVzM4RsC.d.ts +155 -0
- package/dist/types-CQ_ioXWK.d.ts +319 -0
- package/dist/types-Cr4uiYo5.d.ts +99 -0
- package/dist/{types-04LqWrmy.d.ts → types-DiJqJejp.d.ts} +1 -1
- package/dist/types-Dld1TpWj.d.ts +130 -0
- package/dist/vector-store/index.d.ts +33 -34
- package/dist/vector-store/index.js +6 -6
- package/package.json +6 -18
- package/dist/agent-x3YTyv5i.d.ts +0 -222
- package/dist/audio-generation/index.d.ts +0 -33
- package/dist/audio-generation/index.js +0 -42
- package/dist/audio-generation/index.js.map +0 -1
- package/dist/chunk-2ODTMRHP.js +0 -54
- package/dist/chunk-2ODTMRHP.js.map +0 -1
- package/dist/chunk-ADH7NNCS.js +0 -512
- package/dist/chunk-ADH7NNCS.js.map +0 -1
- package/dist/chunk-BALBBVI3.js +0 -2732
- package/dist/chunk-BALBBVI3.js.map +0 -1
- package/dist/chunk-CWUJUSOS.js.map +0 -1
- package/dist/chunk-DALYP4PX.js +0 -225
- package/dist/chunk-DALYP4PX.js.map +0 -1
- package/dist/chunk-HYUYZEAJ.js +0 -223
- package/dist/chunk-HYUYZEAJ.js.map +0 -1
- package/dist/chunk-I6XOQ4LK.js +0 -466
- package/dist/chunk-I6XOQ4LK.js.map +0 -1
- package/dist/chunk-JI5YZWNT.js +0 -220
- package/dist/chunk-JI5YZWNT.js.map +0 -1
- package/dist/chunk-MC3CCKEB.js +0 -221
- package/dist/chunk-MC3CCKEB.js.map +0 -1
- package/dist/chunk-MELYDKWQ.js +0 -337
- package/dist/chunk-MELYDKWQ.js.map +0 -1
- package/dist/chunk-MNWK2USR.js +0 -243
- package/dist/chunk-MNWK2USR.js.map +0 -1
- package/dist/chunk-MRQLEK2B.js.map +0 -1
- package/dist/chunk-NCPN4SJR.js.map +0 -1
- package/dist/chunk-OIMLU4SF.js +0 -20
- package/dist/chunk-OIMLU4SF.js.map +0 -1
- package/dist/chunk-Q25IWLBT.js +0 -138
- package/dist/chunk-Q25IWLBT.js.map +0 -1
- package/dist/chunk-UQX6EXWG.js +0 -33
- package/dist/chunk-UQX6EXWG.js.map +0 -1
- package/dist/chunk-WQKHFADH.js +0 -12
- package/dist/chunk-WQKHFADH.js.map +0 -1
- package/dist/chunk-XUUY2L2D.js +0 -42
- package/dist/chunk-XUUY2L2D.js.map +0 -1
- package/dist/chunk-XWUC7CIT.js +0 -1
- package/dist/chunk-XWUC7CIT.js.map +0 -1
- package/dist/chunk-YLMDBQO4.js +0 -141
- package/dist/chunk-YLMDBQO4.js.map +0 -1
- package/dist/errors-2moLDuuN.d.ts +0 -17
- package/dist/hooks/index.d.ts +0 -12
- package/dist/hooks/index.js +0 -17
- package/dist/index-BxSbmOMr.d.ts +0 -257
- package/dist/json-BVPssigK.d.ts +0 -39
- package/dist/middleware-Dp3d_pxi.d.ts +0 -90
- package/dist/request/index.d.ts +0 -28
- package/dist/request/index.js +0 -25
- package/dist/request/index.js.map +0 -1
- package/dist/tool-Cohdv5GC.d.ts +0 -65
- package/dist/types-BCTRUGex.d.ts +0 -47
- package/dist/types-BrLbKnEz.d.ts +0 -119
- package/dist/types-D9JpeAPF.d.ts +0 -114
- package/dist/types-G12i56s2.d.ts +0 -354
- package/dist/types-JJCxRnaZ.d.ts +0 -70
- package/dist/types-O-abTIin.d.ts +0 -79
- package/dist/ui/index.d.ts +0 -107
- package/dist/ui/index.js +0 -10
- package/dist/ui/index.js.map +0 -1
- /package/dist/{hooks → speech-generation}/index.js.map +0 -0
package/dist/evals/index.js
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import "../chunk-DALYP4PX.js";
|
|
6
|
-
import "../chunk-BALBBVI3.js";
|
|
2
|
+
AgentRunBlockedError,
|
|
3
|
+
cancelAgentApproval
|
|
4
|
+
} from "../chunk-DBSCKTUL.js";
|
|
7
5
|
import "../chunk-YK4WAAS4.js";
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-EINTGEGY.js";
|
|
7
|
+
import "../chunk-CQNNSZPG.js";
|
|
8
|
+
import "../chunk-D37WMSP6.js";
|
|
9
|
+
import "../chunk-77AIYARB.js";
|
|
10
|
+
import "../chunk-OJH6HWHX.js";
|
|
11
|
+
import "../chunk-CWM7B2OO.js";
|
|
14
12
|
import {
|
|
15
13
|
cosineSimilarity,
|
|
16
|
-
embedText
|
|
17
|
-
} from "../chunk-MNWK2USR.js";
|
|
18
|
-
import {
|
|
14
|
+
embedText,
|
|
19
15
|
mapWithConcurrency
|
|
20
|
-
} from "../chunk-
|
|
21
|
-
import
|
|
22
|
-
|
|
16
|
+
} from "../chunk-FMHLROPQ.js";
|
|
17
|
+
import {
|
|
18
|
+
extract
|
|
19
|
+
} from "../chunk-4WI3VGZK.js";
|
|
20
|
+
import "../chunk-MGNTXGTX.js";
|
|
23
21
|
import {
|
|
24
22
|
Usage
|
|
25
|
-
} from "../chunk-
|
|
26
|
-
import "../chunk-
|
|
27
|
-
import "../chunk-
|
|
23
|
+
} from "../chunk-KR3RCCHJ.js";
|
|
24
|
+
import "../chunk-TIZYTPJO.js";
|
|
25
|
+
import "../chunk-KIDGIJM7.js";
|
|
26
|
+
import "../chunk-FN7HLLAZ.js";
|
|
28
27
|
|
|
29
28
|
// src/evals/advanced-metrics.ts
|
|
30
29
|
import { z } from "zod";
|
|
31
30
|
|
|
32
31
|
// src/evals/format.ts
|
|
33
32
|
function defaultOutputValue(output) {
|
|
34
|
-
if (typeof output === "object" && output !== null && "output" in output
|
|
33
|
+
if (typeof output === "object" && output !== null && "output" in output) {
|
|
35
34
|
return output.output;
|
|
36
35
|
}
|
|
37
36
|
return output;
|
|
@@ -58,8 +57,15 @@ function errorMessage(error) {
|
|
|
58
57
|
|
|
59
58
|
// src/evals/judge.ts
|
|
60
59
|
async function runJudge(args) {
|
|
61
|
-
const result = await
|
|
62
|
-
|
|
60
|
+
const result = await extract({
|
|
61
|
+
model: args.model,
|
|
62
|
+
outputSchema: args.schema,
|
|
63
|
+
instructions: args.instructions,
|
|
64
|
+
text: args.prompt,
|
|
65
|
+
temperature: 0,
|
|
66
|
+
retries: args.retries <= 0 ? void 0 : { maxAttempts: Math.trunc(args.retries) + 1 }
|
|
67
|
+
});
|
|
68
|
+
return { data: result.output, usage: result.usage };
|
|
63
69
|
}
|
|
64
70
|
function addUsage(...values) {
|
|
65
71
|
return values.reduce((total, usage) => Usage.add(total, usage), Usage.empty());
|
|
@@ -1116,11 +1122,24 @@ function contentText(content) {
|
|
|
1116
1122
|
}
|
|
1117
1123
|
|
|
1118
1124
|
// src/evals/agent-target.ts
|
|
1119
|
-
|
|
1125
|
+
var AgentEvalApprovalError = class extends Error {
|
|
1126
|
+
constructor(result) {
|
|
1127
|
+
super("Agent eval targets cannot suspend for tool approval.");
|
|
1128
|
+
this.result = result;
|
|
1129
|
+
this.name = "AgentEvalApprovalError";
|
|
1130
|
+
}
|
|
1131
|
+
result;
|
|
1132
|
+
};
|
|
1133
|
+
function agentEvalTarget(options) {
|
|
1120
1134
|
return async (input, testCase) => {
|
|
1121
|
-
const
|
|
1122
|
-
const response = await agent.
|
|
1123
|
-
|
|
1135
|
+
const request = await options.request({ input, testCase });
|
|
1136
|
+
const response = await options.agent.generate(request);
|
|
1137
|
+
if (response.status === "approval_required") {
|
|
1138
|
+
await cancelAgentApproval(response, "Agent eval targets cannot suspend for tool approval.");
|
|
1139
|
+
throw new AgentEvalApprovalError(response);
|
|
1140
|
+
}
|
|
1141
|
+
if (response.status === "blocked") throw new AgentRunBlockedError(response);
|
|
1142
|
+
return options.output === void 0 ? response : await options.output({ response, testCase });
|
|
1124
1143
|
};
|
|
1125
1144
|
}
|
|
1126
1145
|
|
|
@@ -1185,6 +1204,7 @@ function traceFromCarrier(value) {
|
|
|
1185
1204
|
function traceFromMetadata(metadata) {
|
|
1186
1205
|
if (metadata === void 0) return void 0;
|
|
1187
1206
|
return readTraceRef({
|
|
1207
|
+
observer: metadata.traceObserver,
|
|
1188
1208
|
traceId: metadata.traceId,
|
|
1189
1209
|
observationId: metadata.observationId,
|
|
1190
1210
|
responseId: metadata.responseId
|
|
@@ -1194,9 +1214,11 @@ function readTraceRef(value) {
|
|
|
1194
1214
|
if (typeof value !== "object" || value === null) return void 0;
|
|
1195
1215
|
const traceId = value.traceId;
|
|
1196
1216
|
if (typeof traceId !== "string" || traceId.length === 0) return void 0;
|
|
1217
|
+
const observer = value.observer;
|
|
1197
1218
|
const observationId = value.observationId;
|
|
1198
1219
|
const responseId = value.responseId;
|
|
1199
1220
|
const trace = { traceId };
|
|
1221
|
+
if (typeof observer === "string" && observer.length > 0) trace.observer = observer;
|
|
1200
1222
|
if (typeof observationId === "string" && observationId.length > 0) {
|
|
1201
1223
|
trace.observationId = observationId;
|
|
1202
1224
|
}
|
|
@@ -1205,6 +1227,14 @@ function readTraceRef(value) {
|
|
|
1205
1227
|
}
|
|
1206
1228
|
|
|
1207
1229
|
// src/evals/runner.ts
|
|
1230
|
+
var EvalReporterDispatchError = class extends AggregateError {
|
|
1231
|
+
phase;
|
|
1232
|
+
constructor(phase, errors) {
|
|
1233
|
+
super(errors, `Evaluation reporter ${phase} failed ${errors.length} time(s).`);
|
|
1234
|
+
this.name = "EvalReporterDispatchError";
|
|
1235
|
+
this.phase = phase;
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1208
1238
|
async function runEvalSuite(options) {
|
|
1209
1239
|
validateSuiteOptions(options);
|
|
1210
1240
|
const startedAtMs = Date.now();
|
|
@@ -1221,7 +1251,7 @@ async function runEvalSuite(options) {
|
|
|
1221
1251
|
reporterErrors = await notifyRunStart(
|
|
1222
1252
|
reporters,
|
|
1223
1253
|
lifecycle,
|
|
1224
|
-
options.
|
|
1254
|
+
options.reporterErrorPolicy ?? "collect"
|
|
1225
1255
|
);
|
|
1226
1256
|
} catch (error) {
|
|
1227
1257
|
await notifyRunEnd(reporters, {
|
|
@@ -1273,7 +1303,7 @@ async function runEvalSuite(options) {
|
|
|
1273
1303
|
usage: result.usage,
|
|
1274
1304
|
...result.cost === void 0 ? {} : { cost: result.cost }
|
|
1275
1305
|
},
|
|
1276
|
-
options.
|
|
1306
|
+
options.reporterErrorPolicy ?? "collect"
|
|
1277
1307
|
)
|
|
1278
1308
|
);
|
|
1279
1309
|
return result;
|
|
@@ -1327,7 +1357,7 @@ async function runEvalCase(options, testCase, run) {
|
|
|
1327
1357
|
trace: traceResult.trace,
|
|
1328
1358
|
traceError: traceResult.error,
|
|
1329
1359
|
reporters: options.reporters ?? [],
|
|
1330
|
-
|
|
1360
|
+
reporterErrorPolicy: options.reporterErrorPolicy ?? "collect"
|
|
1331
1361
|
});
|
|
1332
1362
|
const metricResult = {
|
|
1333
1363
|
metricName: metric.name,
|
|
@@ -1380,9 +1410,7 @@ async function safeEvaluate(suiteName, testCase, output, metric) {
|
|
|
1380
1410
|
async function reportOutcome(args) {
|
|
1381
1411
|
const errors = [];
|
|
1382
1412
|
if (args.traceError !== void 0) {
|
|
1383
|
-
if (args.failOnReporterError) throw args.traceError;
|
|
1384
1413
|
errors.push(args.traceError);
|
|
1385
|
-
return errors;
|
|
1386
1414
|
}
|
|
1387
1415
|
for (const reporter of args.reporters) {
|
|
1388
1416
|
try {
|
|
@@ -1397,12 +1425,10 @@ async function reportOutcome(args) {
|
|
|
1397
1425
|
outcome: args.outcome
|
|
1398
1426
|
});
|
|
1399
1427
|
} catch (error) {
|
|
1400
|
-
if (args.failOnReporterError) {
|
|
1401
|
-
throw error;
|
|
1402
|
-
}
|
|
1403
1428
|
errors.push(error);
|
|
1404
1429
|
}
|
|
1405
1430
|
}
|
|
1431
|
+
throwReporterErrors("report", errors, args.reporterErrorPolicy);
|
|
1406
1432
|
return errors;
|
|
1407
1433
|
}
|
|
1408
1434
|
function resolveRun(options, startedAtMs) {
|
|
@@ -1426,32 +1452,37 @@ function resolveRun(options, startedAtMs) {
|
|
|
1426
1452
|
...options.run?.metadata === void 0 ? {} : { metadata: options.run.metadata }
|
|
1427
1453
|
};
|
|
1428
1454
|
}
|
|
1429
|
-
async function notifyRunStart(reporters, args,
|
|
1455
|
+
async function notifyRunStart(reporters, args, errorPolicy) {
|
|
1430
1456
|
const errors = [];
|
|
1431
1457
|
for (const reporter of reporters) {
|
|
1432
1458
|
if (reporter.onRunStart === void 0) continue;
|
|
1433
1459
|
try {
|
|
1434
1460
|
await reporter.onRunStart(args);
|
|
1435
1461
|
} catch (error) {
|
|
1436
|
-
if (failOnReporterError) throw error;
|
|
1437
1462
|
errors.push(error);
|
|
1438
1463
|
}
|
|
1439
1464
|
}
|
|
1465
|
+
throwReporterErrors("onRunStart", errors, errorPolicy);
|
|
1440
1466
|
return errors;
|
|
1441
1467
|
}
|
|
1442
|
-
async function notifyRunEnd(reporters, args,
|
|
1468
|
+
async function notifyRunEnd(reporters, args, errorPolicy = "collect") {
|
|
1443
1469
|
const errors = [];
|
|
1444
1470
|
for (const reporter of reporters) {
|
|
1445
1471
|
if (reporter.onRunEnd === void 0) continue;
|
|
1446
1472
|
try {
|
|
1447
1473
|
await reporter.onRunEnd(args);
|
|
1448
1474
|
} catch (error) {
|
|
1449
|
-
if (failOnReporterError) throw error;
|
|
1450
1475
|
errors.push(error);
|
|
1451
1476
|
}
|
|
1452
1477
|
}
|
|
1478
|
+
throwReporterErrors("onRunEnd", errors, errorPolicy);
|
|
1453
1479
|
return errors;
|
|
1454
1480
|
}
|
|
1481
|
+
function throwReporterErrors(phase, errors, errorPolicy) {
|
|
1482
|
+
if (errorPolicy === "throw" && errors.length > 0) {
|
|
1483
|
+
throw new EvalReporterDispatchError(phase, errors);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1455
1486
|
function countMetricOutcomes(results) {
|
|
1456
1487
|
const totals = emptyTotals();
|
|
1457
1488
|
for (const result of results) {
|
|
@@ -1996,9 +2027,9 @@ function semanticSimilarity(options) {
|
|
|
1996
2027
|
if (typeof expected !== "string") {
|
|
1997
2028
|
return EvalOutcome.invalid("Semantic similarity expected value must be a string.");
|
|
1998
2029
|
}
|
|
1999
|
-
const [actualEmbedding, expectedEmbedding] = await Promise.all([
|
|
2000
|
-
embedText(options.model, actual),
|
|
2001
|
-
embedText(options.model, expected)
|
|
2030
|
+
const [{ embedding: actualEmbedding }, { embedding: expectedEmbedding }] = await Promise.all([
|
|
2031
|
+
embedText({ model: options.model, text: actual }),
|
|
2032
|
+
embedText({ model: options.model, text: expected })
|
|
2002
2033
|
]);
|
|
2003
2034
|
const score = cosineSimilarity(actualEmbedding.vector, expectedEmbedding.vector);
|
|
2004
2035
|
return score >= options.threshold ? EvalOutcome.pass(score) : EvalOutcome.fail(score, { comment: `Similarity below threshold ${options.threshold}.` });
|
|
@@ -2006,18 +2037,19 @@ function semanticSimilarity(options) {
|
|
|
2006
2037
|
};
|
|
2007
2038
|
}
|
|
2008
2039
|
function llmJudge(options) {
|
|
2009
|
-
const extractor = new ExtractorBuilder(options.model, options.schema).instructions(
|
|
2010
|
-
options.instructions ?? "Judge the eval case by the requested schema. Submit the judgment using the schema."
|
|
2011
|
-
).retries(options.retries ?? 0).build();
|
|
2012
2040
|
return {
|
|
2013
2041
|
name: options.name ?? "llm_judge",
|
|
2014
2042
|
required: options.required ?? true,
|
|
2015
2043
|
async evaluate(args) {
|
|
2016
2044
|
try {
|
|
2017
|
-
const result = await
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2045
|
+
const result = await extract({
|
|
2046
|
+
model: options.model,
|
|
2047
|
+
outputSchema: options.schema,
|
|
2048
|
+
instructions: options.instructions ?? "Judge the eval case by the requested schema. Submit the judgment using the schema.",
|
|
2049
|
+
text: await resolveJudgePrompt(options.prompt, args),
|
|
2050
|
+
retries: evalExtractionRetries(options.retries)
|
|
2051
|
+
});
|
|
2052
|
+
return options.passes(result.output) ? EvalOutcome.pass(result.output, { usage: result.usage }) : EvalOutcome.fail(result.output, { usage: result.usage });
|
|
2021
2053
|
} catch (error) {
|
|
2022
2054
|
return EvalOutcome.invalid(errorMessage(error));
|
|
2023
2055
|
}
|
|
@@ -2026,18 +2058,6 @@ function llmJudge(options) {
|
|
|
2026
2058
|
}
|
|
2027
2059
|
function llmScore(options) {
|
|
2028
2060
|
const criteria = Array.isArray(options.criteria) ? options.criteria.join("\n") : options.criteria;
|
|
2029
|
-
const extractor = new ExtractorBuilder(
|
|
2030
|
-
options.model,
|
|
2031
|
-
z2.object({
|
|
2032
|
-
score: z2.number(),
|
|
2033
|
-
feedback: z2.string()
|
|
2034
|
-
})
|
|
2035
|
-
).instructions(
|
|
2036
|
-
options.instructions ?? `Score the eval case against these criteria:
|
|
2037
|
-
${criteria}
|
|
2038
|
-
|
|
2039
|
-
Return a score between 0 and 1 and brief feedback.`
|
|
2040
|
-
).retries(options.retries ?? 0).build();
|
|
2041
2061
|
return {
|
|
2042
2062
|
name: options.name ?? "llm_score",
|
|
2043
2063
|
required: options.required ?? true,
|
|
@@ -2047,10 +2067,20 @@ Return a score between 0 and 1 and brief feedback.`
|
|
|
2047
2067
|
threshold: options.threshold,
|
|
2048
2068
|
async evaluate(args) {
|
|
2049
2069
|
try {
|
|
2050
|
-
const result = await
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2070
|
+
const result = await extract({
|
|
2071
|
+
model: options.model,
|
|
2072
|
+
outputSchema: z2.object({
|
|
2073
|
+
score: z2.number(),
|
|
2074
|
+
feedback: z2.string()
|
|
2075
|
+
}),
|
|
2076
|
+
instructions: options.instructions ?? `Score the eval case against these criteria:
|
|
2077
|
+
${criteria}
|
|
2078
|
+
|
|
2079
|
+
Return a score between 0 and 1 and brief feedback.`,
|
|
2080
|
+
text: await resolveJudgePrompt(options.prompt, args),
|
|
2081
|
+
retries: evalExtractionRetries(options.retries)
|
|
2082
|
+
});
|
|
2083
|
+
const score = result.output;
|
|
2054
2084
|
if (score.score < 0 || score.score > 1) {
|
|
2055
2085
|
return EvalOutcome.invalid(`Score ${score.score} outside valid range [0, 1].`, {
|
|
2056
2086
|
score,
|
|
@@ -2064,6 +2094,13 @@ Return a score between 0 and 1 and brief feedback.`
|
|
|
2064
2094
|
}
|
|
2065
2095
|
};
|
|
2066
2096
|
}
|
|
2097
|
+
function evalExtractionRetries(retries) {
|
|
2098
|
+
const retryCount = Math.max(0, Math.trunc(retries ?? 0));
|
|
2099
|
+
if (retryCount === 0) {
|
|
2100
|
+
return void 0;
|
|
2101
|
+
}
|
|
2102
|
+
return { maxAttempts: retryCount + 1 };
|
|
2103
|
+
}
|
|
2067
2104
|
|
|
2068
2105
|
// src/evals/suite.ts
|
|
2069
2106
|
function defineEvalCases(cases) {
|
|
@@ -2078,8 +2115,10 @@ function defineEvalSuite(options) {
|
|
|
2078
2115
|
};
|
|
2079
2116
|
}
|
|
2080
2117
|
export {
|
|
2118
|
+
AgentEvalApprovalError,
|
|
2081
2119
|
EvalAssertionError,
|
|
2082
2120
|
EvalOutcome,
|
|
2121
|
+
EvalReporterDispatchError,
|
|
2083
2122
|
abstention,
|
|
2084
2123
|
agentEvalTarget,
|
|
2085
2124
|
answerRelevancy,
|