@outputai/core 0.15.1-next.e254388.0 → 0.15.1-next.e576c02.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.
- package/dist/evals/aggregate.d.ts +2 -0
- package/dist/evals/aggregate.js +11 -0
- package/dist/evals/eval_workflow.d.ts +20 -0
- package/dist/evals/eval_workflow.js +98 -0
- package/dist/evals/index.d.ts +7 -0
- package/dist/evals/index.js +4 -0
- package/dist/evals/interpret.d.ts +3 -0
- package/dist/evals/interpret.js +40 -0
- package/dist/evals/schemas.d.ts +96 -0
- package/dist/evals/schemas.js +60 -0
- package/dist/evals/verdict.d.ts +27 -0
- package/dist/evals/verdict.js +109 -0
- package/dist/evals/verify.d.ts +41 -0
- package/dist/evals/verify.js +19 -0
- package/package.json +55 -13
- package/src/consts.d.ts +2 -0
- package/src/helpers/path.js +34 -0
- package/src/llm/agent.js +147 -0
- package/src/llm/ai_provider.js +131 -0
- package/src/llm/ai_sdk_options.js +126 -0
- package/src/llm/consts.js +6 -0
- package/src/llm/deprecated_provider_aliases.js +8 -0
- package/src/llm/generate.js +98 -0
- package/src/llm/index.d.ts +691 -0
- package/src/llm/index.js +6 -0
- package/src/llm/judge.js +48 -0
- package/src/llm/prompt/content.js +70 -0
- package/src/llm/prompt/interpolations.js +58 -0
- package/src/llm/prompt/loader.js +67 -0
- package/src/llm/prompt/markup/attributes.js +52 -0
- package/src/llm/prompt/markup/nodes.js +71 -0
- package/src/llm/prompt/markup/tokenizer.js +3 -0
- package/src/llm/prompt/markup/tokens.js +26 -0
- package/src/llm/prompt/validations.js +129 -0
- package/src/llm/utils/cost.js +267 -0
- package/src/llm/utils/error_handler.js +53 -0
- package/src/llm/utils/file.js +42 -0
- package/src/llm/utils/google_vertex_auth.js +31 -0
- package/src/llm/utils/image.js +37 -0
- package/src/llm/utils/legacy_cost_attribute.js +75 -0
- package/src/llm/utils/metering.js +139 -0
- package/src/llm/utils/models.js +15 -0
- package/src/llm/utils/models_pricing.js +96 -0
- package/src/llm/utils/models_pricing_snapshot.json +4711 -0
- package/src/llm/utils/skills.js +74 -0
- package/src/llm/utils/sources.js +73 -0
- package/src/llm/utils/stream.js +75 -0
- package/src/llm/utils/tools.js +62 -0
- package/src/llm/utils/usage.js +155 -0
- package/src/llm/utils/usage_tools.js +23 -0
- package/src/llm/utils/web_search.js +155 -0
- package/src/llm/utils/wrap.js +279 -0
- package/src/llm/validations.js +234 -0
- package/src/worker/bundler_options.js +1 -9
- package/src/worker/configs.js +23 -4
- package/src/worker/index.js +16 -47
- package/src/worker/interceptors/activity.js +0 -1
- package/src/worker/interceptors/workflow.js +0 -1
- package/src/worker/telemetry.js +122 -2
- package/src/worker/webpack_loaders/workflow_rewriter/index.mjs +3 -7
- package/src/worker/webpack_loaders/workflow_rewriter/rewrite_activity_calls.js +27 -7
- package/src/worker/webpack_loaders/workflow_validator/npm_workflow_export_resolve.js +5 -6
- package/src/worker/worker_options.js +43 -0
- package/src/sdk/README.md +0 -47
- package/src/sdk/helpers/component_metadata.d.ts +0 -17
- package/src/sdk/helpers/component_metadata.js +0 -6
- package/src/sdk/helpers/index.d.ts +0 -12
- package/src/sdk/helpers/index.js +0 -3
- package/src/sdk/helpers/objects.d.ts +0 -56
- package/src/sdk/helpers/objects.js +0 -8
- package/src/sdk/helpers/path.d.ts +0 -11
- package/src/sdk/helpers/path.js +0 -32
- package/src/sdk/runtime/context.d.ts +0 -30
- package/src/sdk/runtime/context.js +0 -15
- package/src/sdk/runtime/events.d.ts +0 -13
- package/src/sdk/runtime/events.js +0 -5
- package/src/sdk/runtime/index.d.ts +0 -12
- package/src/sdk/runtime/index.js +0 -3
- package/src/sdk/runtime/tracing.d.ts +0 -48
- package/src/sdk/runtime/tracing.js +0 -11
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { VERDICT, CRITICALITY } from './schemas.js';
|
|
2
|
+
export function aggregateCaseVerdict(evaluatorResults) {
|
|
3
|
+
const required = evaluatorResults.filter(r => r.criticality === CRITICALITY.REQUIRED);
|
|
4
|
+
if (required.some(r => r.verdict === VERDICT.FAIL)) {
|
|
5
|
+
return VERDICT.FAIL;
|
|
6
|
+
}
|
|
7
|
+
if (required.some(r => r.verdict === VERDICT.PARTIAL)) {
|
|
8
|
+
return VERDICT.PARTIAL;
|
|
9
|
+
}
|
|
10
|
+
return VERDICT.PASS;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { InterpretConfig, EvalOutput, Dataset, Criticality } from './schemas.js';
|
|
2
|
+
export interface EvalDefinition {
|
|
3
|
+
evaluator: Function;
|
|
4
|
+
criticality?: Criticality;
|
|
5
|
+
interpret: InterpretConfig;
|
|
6
|
+
}
|
|
7
|
+
export interface EvalWorkflowConfig {
|
|
8
|
+
concurrency?: number;
|
|
9
|
+
}
|
|
10
|
+
export type EvalWorkflowInput = {
|
|
11
|
+
datasets: Dataset[];
|
|
12
|
+
};
|
|
13
|
+
export type EvalWorkflowFn = (input: EvalWorkflowInput, context: unknown) => Promise<EvalOutput>;
|
|
14
|
+
export interface EvalWorkflowOptions {
|
|
15
|
+
name: string;
|
|
16
|
+
evals: EvalDefinition[];
|
|
17
|
+
fn?: EvalWorkflowFn;
|
|
18
|
+
config?: EvalWorkflowConfig;
|
|
19
|
+
}
|
|
20
|
+
export declare function evalWorkflow({ name, evals, fn, config }: EvalWorkflowOptions): unknown;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { workflow } from '#interface/workflow';
|
|
3
|
+
import { executeInParallel } from '#interface/workflow_utils';
|
|
4
|
+
import { INVOKE_ACTIVITY_SYMBOL, METADATA_ACCESS_SYMBOL } from '#consts';
|
|
5
|
+
import { VERDICT, CRITICALITY, DatasetSchema, EvalOutputSchema } from './schemas.js';
|
|
6
|
+
import { interpretResult } from './interpret.js';
|
|
7
|
+
import { aggregateCaseVerdict } from './aggregate.js';
|
|
8
|
+
// Inside the workflow bundle, the rewriter replaces evaluator imports with their activity names.
|
|
9
|
+
const resolveEvaluatorName = (evaluator) => {
|
|
10
|
+
if (typeof evaluator === 'string') {
|
|
11
|
+
return evaluator;
|
|
12
|
+
}
|
|
13
|
+
const metadata = evaluator[METADATA_ACCESS_SYMBOL];
|
|
14
|
+
if (!metadata) {
|
|
15
|
+
throw new Error('Evaluator passed to evalWorkflow was not created with evaluator().');
|
|
16
|
+
}
|
|
17
|
+
if (!metadata.name) {
|
|
18
|
+
throw new Error('Evaluator component doesn\'t have a name.');
|
|
19
|
+
}
|
|
20
|
+
return metadata.name;
|
|
21
|
+
};
|
|
22
|
+
export function evalWorkflow({ name, evals, fn, config = {} }) {
|
|
23
|
+
const concurrency = config.concurrency ?? 10;
|
|
24
|
+
const evalDefs = evals.map(def => ({
|
|
25
|
+
name: resolveEvaluatorName(def.evaluator),
|
|
26
|
+
criticality: def.criticality ?? CRITICALITY.REQUIRED,
|
|
27
|
+
interpret: def.interpret
|
|
28
|
+
}));
|
|
29
|
+
const defaultFn = async function (input) {
|
|
30
|
+
const invoke = globalThis[INVOKE_ACTIVITY_SYMBOL];
|
|
31
|
+
const jobs = input.datasets.map((dataset) => async () => {
|
|
32
|
+
const evaluatorResults = [];
|
|
33
|
+
for (const evalDef of evalDefs) {
|
|
34
|
+
const { evals: perEvalTruth, ...globalTruth } = dataset.ground_truth ?? {};
|
|
35
|
+
const evalTruth = perEvalTruth?.[evalDef.name] ?? {};
|
|
36
|
+
const mergedTruth = { ...globalTruth, ...evalTruth };
|
|
37
|
+
const result = await invoke(evalDef.name, {
|
|
38
|
+
input: dataset.input,
|
|
39
|
+
output: dataset.last_output?.output,
|
|
40
|
+
ground_truth: mergedTruth
|
|
41
|
+
});
|
|
42
|
+
const verdict = interpretResult(result, evalDef.interpret);
|
|
43
|
+
evaluatorResults.push({
|
|
44
|
+
name: evalDef.name,
|
|
45
|
+
verdict,
|
|
46
|
+
criticality: evalDef.criticality,
|
|
47
|
+
confidence: result.confidence,
|
|
48
|
+
reasoning: result.reasoning,
|
|
49
|
+
feedback: result.feedback?.length ? result.feedback : undefined
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const caseVerdict = aggregateCaseVerdict(evaluatorResults);
|
|
53
|
+
return {
|
|
54
|
+
datasetName: dataset.name,
|
|
55
|
+
verdict: caseVerdict,
|
|
56
|
+
evaluators: evaluatorResults
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
const results = await executeInParallel({ jobs, concurrency });
|
|
60
|
+
const cases = results.map((r, i) => {
|
|
61
|
+
if (r.ok) {
|
|
62
|
+
return r.result;
|
|
63
|
+
}
|
|
64
|
+
const datasetName = input.datasets[i]?.name ?? `dataset_${i}`;
|
|
65
|
+
return {
|
|
66
|
+
datasetName,
|
|
67
|
+
verdict: VERDICT.FAIL,
|
|
68
|
+
evaluators: [{
|
|
69
|
+
name: '_error',
|
|
70
|
+
verdict: VERDICT.FAIL,
|
|
71
|
+
criticality: CRITICALITY.REQUIRED,
|
|
72
|
+
reasoning: r.error instanceof Error ? r.error.message : String(r.error)
|
|
73
|
+
}]
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
const passed = cases.filter(c => c.verdict === VERDICT.PASS).length;
|
|
77
|
+
const partial = cases.filter(c => c.verdict === VERDICT.PARTIAL).length;
|
|
78
|
+
const failed = cases.filter(c => c.verdict === VERDICT.FAIL).length;
|
|
79
|
+
const total = cases.length;
|
|
80
|
+
return {
|
|
81
|
+
cases,
|
|
82
|
+
summary: {
|
|
83
|
+
total,
|
|
84
|
+
passed,
|
|
85
|
+
partial,
|
|
86
|
+
failed,
|
|
87
|
+
acceptableRate: total > 0 ? (passed + partial) / total : 0
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
return workflow({
|
|
92
|
+
name,
|
|
93
|
+
description: `Eval workflow for ${name}`,
|
|
94
|
+
inputSchema: z.object({ datasets: z.array(DatasetSchema) }),
|
|
95
|
+
outputSchema: EvalOutputSchema,
|
|
96
|
+
fn: fn ?? defaultFn
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { evalWorkflow } from './eval_workflow.js';
|
|
2
|
+
export type { EvalDefinition, EvalWorkflowConfig, EvalWorkflowInput, EvalWorkflowFn, EvalWorkflowOptions } from './eval_workflow.js';
|
|
3
|
+
export { Verdict } from './verdict.js';
|
|
4
|
+
export { verify } from './verify.js';
|
|
5
|
+
export type { CheckContext } from './verify.js';
|
|
6
|
+
export { VERDICT, CRITICALITY, EvalOutputSchema, DatasetSchema } from './schemas.js';
|
|
7
|
+
export type { Verdict as VerdictType, Criticality, InterpretConfig, EvaluatorResult, EvalCase, EvalSummary, EvalOutput, GroundTruth, LastOutput, LastEval, Dataset } from './schemas.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { VERDICT, VerdictSchema } from './schemas.js';
|
|
2
|
+
const VALID_VERDICTS = new Set(VerdictSchema.options);
|
|
3
|
+
const interpretVerdict = (value) => VALID_VERDICTS.has(value) ? value : VERDICT.FAIL;
|
|
4
|
+
const interpretBoolean = (value) => value === true ? VERDICT.PASS : VERDICT.FAIL;
|
|
5
|
+
const interpretNumber = (value, config) => {
|
|
6
|
+
if (typeof value !== 'number' || Number.isNaN(value)) {
|
|
7
|
+
return VERDICT.FAIL;
|
|
8
|
+
}
|
|
9
|
+
if (value >= config.pass) {
|
|
10
|
+
return VERDICT.PASS;
|
|
11
|
+
}
|
|
12
|
+
if (config.partial !== undefined && config.partial !== null && value >= config.partial) {
|
|
13
|
+
return VERDICT.PARTIAL;
|
|
14
|
+
}
|
|
15
|
+
return VERDICT.FAIL;
|
|
16
|
+
};
|
|
17
|
+
const interpretString = (value, config) => {
|
|
18
|
+
if (config.pass.includes(value)) {
|
|
19
|
+
return VERDICT.PASS;
|
|
20
|
+
}
|
|
21
|
+
if (config.partial?.includes(value)) {
|
|
22
|
+
return VERDICT.PARTIAL;
|
|
23
|
+
}
|
|
24
|
+
return VERDICT.FAIL;
|
|
25
|
+
};
|
|
26
|
+
export const interpretResult = (result, config) => {
|
|
27
|
+
const { value } = result;
|
|
28
|
+
switch (config.type) {
|
|
29
|
+
case 'verdict':
|
|
30
|
+
return interpretVerdict(value);
|
|
31
|
+
case 'boolean':
|
|
32
|
+
return interpretBoolean(value);
|
|
33
|
+
case 'number':
|
|
34
|
+
return interpretNumber(value, config);
|
|
35
|
+
case 'string':
|
|
36
|
+
return interpretString(value, config);
|
|
37
|
+
default:
|
|
38
|
+
return VERDICT.FAIL;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const VERDICT: {
|
|
3
|
+
readonly PASS: "pass";
|
|
4
|
+
readonly PARTIAL: "partial";
|
|
5
|
+
readonly FAIL: "fail";
|
|
6
|
+
};
|
|
7
|
+
export declare const CRITICALITY: {
|
|
8
|
+
readonly REQUIRED: "required";
|
|
9
|
+
readonly INFORMATIONAL: "informational";
|
|
10
|
+
};
|
|
11
|
+
export declare const VerdictSchema: z.ZodEnum<{
|
|
12
|
+
pass: "pass";
|
|
13
|
+
partial: "partial";
|
|
14
|
+
fail: "fail";
|
|
15
|
+
}>;
|
|
16
|
+
export type Verdict = typeof VERDICT[keyof typeof VERDICT];
|
|
17
|
+
export declare const CriticalitySchema: z.ZodEnum<{
|
|
18
|
+
required: "required";
|
|
19
|
+
informational: "informational";
|
|
20
|
+
}>;
|
|
21
|
+
export type Criticality = typeof CRITICALITY[keyof typeof CRITICALITY];
|
|
22
|
+
export type InterpretConfig = {
|
|
23
|
+
type: 'verdict';
|
|
24
|
+
} | {
|
|
25
|
+
type: 'boolean';
|
|
26
|
+
} | {
|
|
27
|
+
type: 'number';
|
|
28
|
+
pass: number;
|
|
29
|
+
partial?: number;
|
|
30
|
+
} | {
|
|
31
|
+
type: 'string';
|
|
32
|
+
pass: string[];
|
|
33
|
+
partial?: string[];
|
|
34
|
+
};
|
|
35
|
+
export declare const InterpretConfigSchema: z.ZodType<InterpretConfig>;
|
|
36
|
+
export interface EvaluatorResult {
|
|
37
|
+
name: string;
|
|
38
|
+
verdict: Verdict;
|
|
39
|
+
criticality: Criticality;
|
|
40
|
+
confidence?: number;
|
|
41
|
+
reasoning?: string;
|
|
42
|
+
feedback?: unknown[];
|
|
43
|
+
}
|
|
44
|
+
export declare const EvaluatorResultSchema: z.ZodType<EvaluatorResult>;
|
|
45
|
+
export interface EvalCase {
|
|
46
|
+
datasetName: string;
|
|
47
|
+
verdict: Verdict;
|
|
48
|
+
evaluators: EvaluatorResult[];
|
|
49
|
+
}
|
|
50
|
+
export declare const EvalCaseSchema: z.ZodType<EvalCase>;
|
|
51
|
+
export interface EvalSummary {
|
|
52
|
+
total: number;
|
|
53
|
+
passed: number;
|
|
54
|
+
partial: number;
|
|
55
|
+
failed: number;
|
|
56
|
+
acceptableRate: number;
|
|
57
|
+
}
|
|
58
|
+
export interface EvalOutput {
|
|
59
|
+
cases: EvalCase[];
|
|
60
|
+
summary: EvalSummary;
|
|
61
|
+
}
|
|
62
|
+
export declare const EvalOutputSchema: z.ZodType<EvalOutput>;
|
|
63
|
+
export interface GroundTruth {
|
|
64
|
+
evals?: Record<string, Record<string, unknown>>;
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
}
|
|
67
|
+
export interface LastOutput {
|
|
68
|
+
output: unknown;
|
|
69
|
+
executionTimeMs?: number;
|
|
70
|
+
date: string;
|
|
71
|
+
}
|
|
72
|
+
export interface LastEval {
|
|
73
|
+
output: EvalCase;
|
|
74
|
+
executionTimeMs?: number;
|
|
75
|
+
date: string;
|
|
76
|
+
}
|
|
77
|
+
export declare const LastOutputSchema: z.ZodType<LastOutput>;
|
|
78
|
+
export declare const LastEvalSchema: z.ZodType<LastEval>;
|
|
79
|
+
export interface Dataset {
|
|
80
|
+
name: string;
|
|
81
|
+
input: Record<string, unknown>;
|
|
82
|
+
ground_truth?: GroundTruth;
|
|
83
|
+
last_output?: LastOutput;
|
|
84
|
+
last_eval?: LastEval;
|
|
85
|
+
_source?: string;
|
|
86
|
+
[key: string]: unknown;
|
|
87
|
+
}
|
|
88
|
+
export declare const DatasetSchema: z.ZodObject<{
|
|
89
|
+
name: z.ZodString;
|
|
90
|
+
input: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
91
|
+
ground_truth: z.ZodOptional<z.ZodObject<{
|
|
92
|
+
evals: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
93
|
+
}, z.core.$loose>>;
|
|
94
|
+
last_output: z.ZodOptional<z.ZodType<LastOutput, unknown, z.core.$ZodTypeInternals<LastOutput, unknown>>>;
|
|
95
|
+
last_eval: z.ZodOptional<z.ZodType<LastEval, unknown, z.core.$ZodTypeInternals<LastEval, unknown>>>;
|
|
96
|
+
}, z.core.$loose>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const VERDICT = {
|
|
3
|
+
PASS: 'pass',
|
|
4
|
+
PARTIAL: 'partial',
|
|
5
|
+
FAIL: 'fail'
|
|
6
|
+
};
|
|
7
|
+
export const CRITICALITY = {
|
|
8
|
+
REQUIRED: 'required',
|
|
9
|
+
INFORMATIONAL: 'informational'
|
|
10
|
+
};
|
|
11
|
+
export const VerdictSchema = z.enum([VERDICT.PASS, VERDICT.PARTIAL, VERDICT.FAIL]);
|
|
12
|
+
export const CriticalitySchema = z.enum([CRITICALITY.REQUIRED, CRITICALITY.INFORMATIONAL]);
|
|
13
|
+
export const InterpretConfigSchema = z.discriminatedUnion('type', [
|
|
14
|
+
z.object({ type: z.literal('verdict') }),
|
|
15
|
+
z.object({ type: z.literal('boolean') }),
|
|
16
|
+
z.object({ type: z.literal('number'), pass: z.number(), partial: z.number().optional() }),
|
|
17
|
+
z.object({ type: z.literal('string'), pass: z.array(z.string()), partial: z.array(z.string()).optional() })
|
|
18
|
+
]);
|
|
19
|
+
export const EvaluatorResultSchema = z.object({
|
|
20
|
+
name: z.string(),
|
|
21
|
+
verdict: VerdictSchema,
|
|
22
|
+
criticality: CriticalitySchema,
|
|
23
|
+
confidence: z.number().optional(),
|
|
24
|
+
reasoning: z.string().optional(),
|
|
25
|
+
feedback: z.array(z.any()).optional()
|
|
26
|
+
});
|
|
27
|
+
export const EvalCaseSchema = z.object({
|
|
28
|
+
datasetName: z.string(),
|
|
29
|
+
verdict: VerdictSchema,
|
|
30
|
+
evaluators: z.array(EvaluatorResultSchema)
|
|
31
|
+
});
|
|
32
|
+
export const EvalOutputSchema = z.object({
|
|
33
|
+
cases: z.array(EvalCaseSchema),
|
|
34
|
+
summary: z.object({
|
|
35
|
+
total: z.number(),
|
|
36
|
+
passed: z.number(),
|
|
37
|
+
partial: z.number(),
|
|
38
|
+
failed: z.number(),
|
|
39
|
+
acceptableRate: z.number()
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
export const LastOutputSchema = z.object({
|
|
43
|
+
output: z.any(),
|
|
44
|
+
executionTimeMs: z.number().optional(),
|
|
45
|
+
date: z.string()
|
|
46
|
+
});
|
|
47
|
+
export const LastEvalSchema = z.object({
|
|
48
|
+
output: EvalCaseSchema,
|
|
49
|
+
executionTimeMs: z.number().optional(),
|
|
50
|
+
date: z.string()
|
|
51
|
+
});
|
|
52
|
+
export const DatasetSchema = z.object({
|
|
53
|
+
name: z.string(),
|
|
54
|
+
input: z.record(z.string(), z.any()),
|
|
55
|
+
ground_truth: z.object({
|
|
56
|
+
evals: z.record(z.string(), z.record(z.string(), z.any())).optional()
|
|
57
|
+
}).passthrough().optional(),
|
|
58
|
+
last_output: LastOutputSchema.optional(),
|
|
59
|
+
last_eval: LastEvalSchema.optional()
|
|
60
|
+
}).passthrough();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EvaluationVerdictResult, EvaluationBooleanResult, EvaluationNumberResult, EvaluationStringResult, EvaluationFeedback } from '#interface/evaluation_result';
|
|
2
|
+
type FeedbackArg = ConstructorParameters<typeof EvaluationFeedback>[0];
|
|
3
|
+
export declare const Verdict: {
|
|
4
|
+
pass(reasoning?: string): EvaluationVerdictResult;
|
|
5
|
+
partial(confidence: number, reasoning?: string, feedback?: FeedbackArg[]): EvaluationVerdictResult;
|
|
6
|
+
fail(reasoning: string, feedback?: FeedbackArg[]): EvaluationVerdictResult;
|
|
7
|
+
equals(actual: unknown, expected: unknown): EvaluationBooleanResult;
|
|
8
|
+
closeTo(actual: number, expected: number, tolerance: number): EvaluationBooleanResult;
|
|
9
|
+
gt(actual: number, threshold: number): EvaluationBooleanResult;
|
|
10
|
+
gte(actual: number, threshold: number): EvaluationBooleanResult;
|
|
11
|
+
lt(actual: number, threshold: number): EvaluationBooleanResult;
|
|
12
|
+
lte(actual: number, threshold: number): EvaluationBooleanResult;
|
|
13
|
+
inRange(actual: number, min: number, max: number): EvaluationBooleanResult;
|
|
14
|
+
contains(haystack: string, needle: string): EvaluationBooleanResult;
|
|
15
|
+
matches(value: string, pattern: RegExp): EvaluationBooleanResult;
|
|
16
|
+
includesAll(actual: unknown[], expected: unknown[]): EvaluationBooleanResult;
|
|
17
|
+
includesAny(actual: unknown[], expected: unknown[]): EvaluationBooleanResult;
|
|
18
|
+
isTrue(value: boolean): EvaluationBooleanResult;
|
|
19
|
+
isFalse(value: boolean): EvaluationBooleanResult;
|
|
20
|
+
fromJudge({ verdict, reasoning }: {
|
|
21
|
+
verdict: "pass" | "partial" | "fail";
|
|
22
|
+
reasoning: string;
|
|
23
|
+
}): EvaluationVerdictResult;
|
|
24
|
+
score(value: number, reasoning?: string): EvaluationNumberResult;
|
|
25
|
+
label(value: string, reasoning?: string): EvaluationStringResult;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { EvaluationVerdictResult, EvaluationBooleanResult, EvaluationNumberResult, EvaluationStringResult, EvaluationFeedback } from '#interface/evaluation_result';
|
|
2
|
+
const boolResult = (value, reasoning) => new EvaluationBooleanResult({ value, confidence: 1.0, reasoning });
|
|
3
|
+
export const Verdict = {
|
|
4
|
+
// --- Original helpers ---
|
|
5
|
+
pass(reasoning) {
|
|
6
|
+
return new EvaluationVerdictResult({ value: 'pass', confidence: 1.0, reasoning });
|
|
7
|
+
},
|
|
8
|
+
partial(confidence, reasoning, feedback) {
|
|
9
|
+
return new EvaluationVerdictResult({
|
|
10
|
+
value: 'partial',
|
|
11
|
+
confidence,
|
|
12
|
+
reasoning,
|
|
13
|
+
feedback: feedback ? feedback.map(f => new EvaluationFeedback(f)) : undefined
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
fail(reasoning, feedback) {
|
|
17
|
+
return new EvaluationVerdictResult({
|
|
18
|
+
value: 'fail',
|
|
19
|
+
confidence: 0.0,
|
|
20
|
+
reasoning,
|
|
21
|
+
feedback: feedback ? feedback.map(f => new EvaluationFeedback(f)) : undefined
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
// --- Deterministic assertions (confidence 1.0 for both pass and fail) ---
|
|
25
|
+
equals(actual, expected) {
|
|
26
|
+
const passed = actual === expected;
|
|
27
|
+
return boolResult(passed, passed ?
|
|
28
|
+
`Value equals expected: ${JSON.stringify(expected)}` :
|
|
29
|
+
`Expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
30
|
+
},
|
|
31
|
+
closeTo(actual, expected, tolerance) {
|
|
32
|
+
const passed = Math.abs(actual - expected) <= tolerance;
|
|
33
|
+
return boolResult(passed, passed ?
|
|
34
|
+
`${actual} is within ${tolerance} of ${expected}` :
|
|
35
|
+
`${actual} is not within ${tolerance} of ${expected} (diff: ${Math.abs(actual - expected)})`);
|
|
36
|
+
},
|
|
37
|
+
gt(actual, threshold) {
|
|
38
|
+
const passed = actual > threshold;
|
|
39
|
+
return boolResult(passed, passed ?
|
|
40
|
+
`${actual} > ${threshold}` :
|
|
41
|
+
`${actual} is not greater than ${threshold}`);
|
|
42
|
+
},
|
|
43
|
+
gte(actual, threshold) {
|
|
44
|
+
const passed = actual >= threshold;
|
|
45
|
+
return boolResult(passed, passed ?
|
|
46
|
+
`${actual} >= ${threshold}` :
|
|
47
|
+
`${actual} is not greater than or equal to ${threshold}`);
|
|
48
|
+
},
|
|
49
|
+
lt(actual, threshold) {
|
|
50
|
+
const passed = actual < threshold;
|
|
51
|
+
return boolResult(passed, passed ?
|
|
52
|
+
`${actual} < ${threshold}` :
|
|
53
|
+
`${actual} is not less than ${threshold}`);
|
|
54
|
+
},
|
|
55
|
+
lte(actual, threshold) {
|
|
56
|
+
const passed = actual <= threshold;
|
|
57
|
+
return boolResult(passed, passed ?
|
|
58
|
+
`${actual} <= ${threshold}` :
|
|
59
|
+
`${actual} is not less than or equal to ${threshold}`);
|
|
60
|
+
},
|
|
61
|
+
inRange(actual, min, max) {
|
|
62
|
+
const passed = actual >= min && actual <= max;
|
|
63
|
+
return boolResult(passed, passed ?
|
|
64
|
+
`${actual} is in range [${min}, ${max}]` :
|
|
65
|
+
`${actual} is not in range [${min}, ${max}]`);
|
|
66
|
+
},
|
|
67
|
+
contains(haystack, needle) {
|
|
68
|
+
const passed = haystack.includes(needle);
|
|
69
|
+
return boolResult(passed, passed ?
|
|
70
|
+
`String contains "${needle}"` :
|
|
71
|
+
`String does not contain "${needle}"`);
|
|
72
|
+
},
|
|
73
|
+
matches(value, pattern) {
|
|
74
|
+
const passed = pattern.test(value);
|
|
75
|
+
return boolResult(passed, passed ?
|
|
76
|
+
`Value matches ${pattern}` :
|
|
77
|
+
`Value does not match ${pattern}`);
|
|
78
|
+
},
|
|
79
|
+
includesAll(actual, expected) {
|
|
80
|
+
const missing = expected.filter(e => !actual.includes(e));
|
|
81
|
+
const passed = missing.length === 0;
|
|
82
|
+
return boolResult(passed, passed ?
|
|
83
|
+
'Array includes all expected values' :
|
|
84
|
+
`Array is missing: ${JSON.stringify(missing)}`);
|
|
85
|
+
},
|
|
86
|
+
includesAny(actual, expected) {
|
|
87
|
+
const found = expected.filter(e => actual.includes(e));
|
|
88
|
+
const passed = found.length > 0;
|
|
89
|
+
return boolResult(passed, passed ?
|
|
90
|
+
`Array includes: ${JSON.stringify(found)}` :
|
|
91
|
+
`Array includes none of: ${JSON.stringify(expected)}`);
|
|
92
|
+
},
|
|
93
|
+
isTrue(value) {
|
|
94
|
+
return boolResult(value === true, value === true ? 'Value is true' : `Expected true, got ${value}`);
|
|
95
|
+
},
|
|
96
|
+
isFalse(value) {
|
|
97
|
+
return boolResult(value === false, value === false ? 'Value is false' : `Expected false, got ${value}`);
|
|
98
|
+
},
|
|
99
|
+
// --- LLM judge helpers ---
|
|
100
|
+
fromJudge({ verdict, reasoning }) {
|
|
101
|
+
return new EvaluationVerdictResult({ value: verdict, confidence: 0.9, reasoning });
|
|
102
|
+
},
|
|
103
|
+
score(value, reasoning) {
|
|
104
|
+
return new EvaluationNumberResult({ value, confidence: 0.9, reasoning });
|
|
105
|
+
},
|
|
106
|
+
label(value, reasoning) {
|
|
107
|
+
return new EvaluationStringResult({ value, confidence: 0.9, reasoning });
|
|
108
|
+
}
|
|
109
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { EvaluationResult } from '#interface/evaluation_result';
|
|
3
|
+
export type CheckContext<TInput = unknown, TOutput = unknown> = {
|
|
4
|
+
input: TInput;
|
|
5
|
+
output: TOutput;
|
|
6
|
+
context: {
|
|
7
|
+
ground_truth: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
type CheckFn<TInput, TOutput> = (ctx: CheckContext<TInput, TOutput>) => EvaluationResult | Promise<EvaluationResult>;
|
|
11
|
+
type VerifyOptions<I extends z.ZodType = z.ZodType<unknown>, O extends z.ZodType = z.ZodType<unknown>> = {
|
|
12
|
+
name: string;
|
|
13
|
+
input?: I;
|
|
14
|
+
output?: O;
|
|
15
|
+
};
|
|
16
|
+
export declare const verify: <I extends z.ZodType, O extends z.ZodType>(options: VerifyOptions<I, O>, fn: CheckFn<z.infer<I>, z.infer<O>>) => (input: ({
|
|
17
|
+
input: z.ZodAny | I;
|
|
18
|
+
output: z.ZodAny | O;
|
|
19
|
+
ground_truth: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
20
|
+
} extends infer T_1 extends z.core.$ZodLooseShape ? { -readonly [k in keyof T_1 as {
|
|
21
|
+
input: z.ZodAny | I;
|
|
22
|
+
output: z.ZodAny | O;
|
|
23
|
+
ground_truth: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
24
|
+
}[k] extends {
|
|
25
|
+
_zod: {
|
|
26
|
+
optin: "optional" | "defaulted";
|
|
27
|
+
};
|
|
28
|
+
} ? never : k]: T_1[k]["_zod"]["input"]; } : never) & ({
|
|
29
|
+
input: z.ZodAny | I;
|
|
30
|
+
output: z.ZodAny | O;
|
|
31
|
+
ground_truth: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
32
|
+
} extends infer T_2 extends z.core.$ZodLooseShape ? { -readonly [k_1 in keyof T_2 as {
|
|
33
|
+
input: z.ZodAny | I;
|
|
34
|
+
output: z.ZodAny | O;
|
|
35
|
+
ground_truth: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
36
|
+
}[k_1] extends {
|
|
37
|
+
_zod: {
|
|
38
|
+
optin: "optional" | "defaulted";
|
|
39
|
+
};
|
|
40
|
+
} ? k_1 : never]?: T_2[k_1]["_zod"]["input"] | undefined; } : never) extends infer T ? { [K in keyof T]: T[K]; } : never) => Promise<EvaluationResult>;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { evaluator } from '#interface/evaluator';
|
|
3
|
+
export const verify = (options, fn) => {
|
|
4
|
+
const inputSchema = z.object({
|
|
5
|
+
input: options.input ?? z.any(),
|
|
6
|
+
output: options.output ?? z.any(),
|
|
7
|
+
ground_truth: z.record(z.string(), z.unknown()).optional()
|
|
8
|
+
});
|
|
9
|
+
const wrappedFn = async (data) => {
|
|
10
|
+
const groundTruth = data.ground_truth ?? {};
|
|
11
|
+
return fn({ input: data.input, output: data.output, context: { ground_truth: groundTruth } });
|
|
12
|
+
};
|
|
13
|
+
return evaluator({
|
|
14
|
+
name: options.name,
|
|
15
|
+
description: options.name,
|
|
16
|
+
inputSchema,
|
|
17
|
+
fn: wrappedFn
|
|
18
|
+
});
|
|
19
|
+
};
|