@fabricorg/experiments-evals 0.2.0 → 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.
- package/README.md +43 -0
- package/dist/databricks.cjs +216 -0
- package/dist/databricks.cjs.map +1 -1
- package/dist/databricks.d.cts +45 -185
- package/dist/databricks.d.ts +45 -185
- package/dist/databricks.js +215 -1
- package/dist/databricks.js.map +1 -1
- package/dist/index.d.cts +3 -134
- package/dist/index.d.ts +3 -134
- package/dist/runner-Kga7ABQA.d.cts +359 -0
- package/dist/runner-Kga7ABQA.d.ts +359 -0
- package/package.json +6 -6
- package/templates/databricks/mlflow_evaluate_records.py +200 -0
- package/dist/model-client-B7yk_i1s.d.cts +0 -601
- package/dist/model-client-B7yk_i1s.d.ts +0 -601
package/dist/index.d.ts
CHANGED
|
@@ -1,64 +1,7 @@
|
|
|
1
|
-
import { E as
|
|
2
|
-
export {
|
|
1
|
+
import { E as Evaluator, a as EvalScore, C as ChatMessage, b as EvalInput, M as ModelClient, R as RunItem } from './runner-Kga7ABQA.js';
|
|
2
|
+
export { c as EvalContext, d as EvalRun, e as EvalRunSpec, f as EvalRunStatus, g as EvalRunTarget, h as EvaluatorKind, i as ExecuteOptions, j as ExecuteResult, G as GenerationSignal, k as GenerationSignalItem, I as ITEM_CONTENT_TOKEN_ALLOWANCE, J as JUDGE_COMPLETION_TOKEN_CAP, l as JudgeTemplate, m as ModelCompletionOptions, n as ModelResponse, S as ScoredItem, o as StaticModelClient, T as TokenUsage, p as codeEvaluator, q as deriveReserveTokensPerCall, r as executeEvalRun, s as llmJudge, t as maxCompletionTokenUsage, u as parseJudgeResponse, v as render } from './runner-Kga7ABQA.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
|
|
5
|
-
/** What an evaluator sees: the example under test plus the produced output. */
|
|
6
|
-
interface EvalInput {
|
|
7
|
-
input: unknown;
|
|
8
|
-
output: unknown;
|
|
9
|
-
expectedOutput?: unknown;
|
|
10
|
-
/** Retrieved context for RAG-style judges (documents, tool results). */
|
|
11
|
-
context?: unknown;
|
|
12
|
-
metadata?: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
|
-
interface EvalContext {
|
|
15
|
-
model: ModelClient;
|
|
16
|
-
nowMs: () => number;
|
|
17
|
-
}
|
|
18
|
-
interface Evaluator {
|
|
19
|
-
readonly kind: EvaluatorKind;
|
|
20
|
-
readonly name: string;
|
|
21
|
-
readonly version: string;
|
|
22
|
-
/** Worst-case judge usage reserved before IO; absent for token-free evaluators. */
|
|
23
|
-
maxJudgeTokens?(input: EvalInput): number;
|
|
24
|
-
/**
|
|
25
|
-
* The judge's prompt template, when the evaluator is an LLM judge. Exposed
|
|
26
|
-
* so budget derivation (deriveReserveTokensPerCall) can size worst-case
|
|
27
|
-
* per-call token reservations from the actual prompt text.
|
|
28
|
-
*/
|
|
29
|
-
readonly promptTemplate?: Pick<JudgeTemplate, 'system' | 'user'>;
|
|
30
|
-
evaluate(input: EvalInput, ctx: EvalContext): Promise<EvalScore>;
|
|
31
|
-
}
|
|
32
|
-
interface JudgeTemplate {
|
|
33
|
-
name: string;
|
|
34
|
-
version: string;
|
|
35
|
-
/** Labels the judge may answer with, mapped to normalized scores. */
|
|
36
|
-
labels: Record<string, number>;
|
|
37
|
-
system: string;
|
|
38
|
-
/** Rendered with {{input}}, {{output}}, {{expectedOutput}}, {{context}}. */
|
|
39
|
-
user: string;
|
|
40
|
-
/** Deterministic provider-enforced response ceiling. Default: 256. */
|
|
41
|
-
maxOutputTokens?: number;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Build an LLM-judge evaluator from a template. Response contract: the model
|
|
45
|
-
* answers `LABEL: <label>` on the first line, free-form explanation after —
|
|
46
|
-
* a portable explanation-bearing format that remains easy to import/export.
|
|
47
|
-
*/
|
|
48
|
-
declare function llmJudge(template: JudgeTemplate): Evaluator;
|
|
49
|
-
/** Build a deterministic code evaluator from a pure function. */
|
|
50
|
-
declare function codeEvaluator(name: string, version: string, fn: (input: EvalInput) => {
|
|
51
|
-
label?: string;
|
|
52
|
-
score: number | null;
|
|
53
|
-
explanation?: string;
|
|
54
|
-
}): Evaluator;
|
|
55
|
-
declare function render(template: string, input: EvalInput): string;
|
|
56
|
-
declare function parseJudgeResponse(text: string, labels: Record<string, number>): {
|
|
57
|
-
label?: string;
|
|
58
|
-
score: number | null;
|
|
59
|
-
explanation?: string;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
5
|
/**
|
|
63
6
|
* Built-in judge library. Prompts use a portable binary-label + explanation
|
|
64
7
|
* contract and are versioned independently — bump the version on ANY prompt
|
|
@@ -101,80 +44,6 @@ interface EvaluatorAggregate {
|
|
|
101
44
|
/** Pure aggregation over a run's scores, grouped by evaluator name+version. */
|
|
102
45
|
declare function aggregateScores(scores: readonly EvalScore[]): EvaluatorAggregate[];
|
|
103
46
|
|
|
104
|
-
interface RunItem {
|
|
105
|
-
/** Dataset exampleId or span id — opaque to the runner. */
|
|
106
|
-
itemId: string;
|
|
107
|
-
input: EvalInput;
|
|
108
|
-
}
|
|
109
|
-
interface ScoredItem {
|
|
110
|
-
itemId: string;
|
|
111
|
-
score: EvalScore;
|
|
112
|
-
}
|
|
113
|
-
interface ExecuteOptions {
|
|
114
|
-
evaluators: readonly Evaluator[];
|
|
115
|
-
items: readonly RunItem[];
|
|
116
|
-
ctx: EvalContext;
|
|
117
|
-
/**
|
|
118
|
-
* Hard token budget (governance: eval-cost-controls). Enforced by
|
|
119
|
-
* reservation: a judge call only starts if `spent + reserved +
|
|
120
|
-
* reserveTokensPerCall` still fits, so concurrent workers can never
|
|
121
|
-
* collectively overshoot by racing the check.
|
|
122
|
-
*/
|
|
123
|
-
maxJudgeTokens?: number;
|
|
124
|
-
/**
|
|
125
|
-
* Optional minimum reservation per judge call. The runner always takes the
|
|
126
|
-
* larger of this value and the evaluator's input-specific worst-case bound.
|
|
127
|
-
* Code and heuristic evaluators reserve zero tokens and continue after a
|
|
128
|
-
* judge budget is exhausted.
|
|
129
|
-
*/
|
|
130
|
-
reserveTokensPerCall?: number;
|
|
131
|
-
concurrency?: number;
|
|
132
|
-
/** Called after each item completes — the agent checkpoints here. */
|
|
133
|
-
onProgress?: (done: number, total: number, tokensSpent: number) => void;
|
|
134
|
-
}
|
|
135
|
-
interface ExecuteResult {
|
|
136
|
-
scores: ScoredItem[];
|
|
137
|
-
tokensSpent: number;
|
|
138
|
-
/** Items fully or partially skipped because the token budget was exhausted. */
|
|
139
|
-
skippedForBudget: number;
|
|
140
|
-
/** Individual judge evaluations skipped because their reservation did not fit. */
|
|
141
|
-
skippedEvaluationsForBudget: number;
|
|
142
|
-
/** Per-item evaluator failures (item kept; other evaluators still ran). */
|
|
143
|
-
failures: Array<{
|
|
144
|
-
itemId: string;
|
|
145
|
-
evaluatorName: string;
|
|
146
|
-
message: string;
|
|
147
|
-
}>;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Completion cap assumed per judge call when sizing reservations. Judges
|
|
151
|
-
* answer `LABEL: <label>` plus a brief explanation — 512 tokens is a generous
|
|
152
|
-
* ceiling for that contract.
|
|
153
|
-
*/
|
|
154
|
-
declare const JUDGE_COMPLETION_TOKEN_CAP = 512;
|
|
155
|
-
/**
|
|
156
|
-
* Prompt-token allowance for the item content rendered into the template
|
|
157
|
-
* ({{input}}/{{output}}/{{expectedOutput}}/{{context}}). A worst-case bound
|
|
158
|
-
* for typical dataset examples; oversized examples only weaken the guarantee
|
|
159
|
-
* to "caps the number of calls started" (see reserveTokensPerCall docs).
|
|
160
|
-
*/
|
|
161
|
-
declare const ITEM_CONTENT_TOKEN_ALLOWANCE = 1024;
|
|
162
|
-
/**
|
|
163
|
-
* Worst-case tokens one judge call may consume, derived from the largest
|
|
164
|
-
* prompt template among the run's evaluators (chars/4 heuristic) plus the
|
|
165
|
-
* item-content allowance and the completion cap. Threaded from run creation
|
|
166
|
-
* into ExecuteOptions.reserveTokensPerCall so the hard budget is enforced by
|
|
167
|
-
* reservation rather than after-the-fact accounting.
|
|
168
|
-
*/
|
|
169
|
-
declare function deriveReserveTokensPerCall(evaluators: readonly Evaluator[]): number;
|
|
170
|
-
/**
|
|
171
|
-
* Pure orchestration: evaluate every item with every evaluator under a hard
|
|
172
|
-
* token budget, bounded concurrency, and per-evaluator error isolation. IO
|
|
173
|
-
* happens only through the injected ModelClient; persistence is the caller's
|
|
174
|
-
* job (the eval-runner agent writes to the warehouse between batches).
|
|
175
|
-
*/
|
|
176
|
-
declare function executeEvalRun(opts: ExecuteOptions): Promise<ExecuteResult>;
|
|
177
|
-
|
|
178
47
|
/**
|
|
179
48
|
* Generation phase for playground-replay eval runs (review fix: replay must
|
|
180
49
|
* not call the model inside the API request lifecycle). The run executor —
|
|
@@ -254,4 +123,4 @@ interface GenerationPhaseResult {
|
|
|
254
123
|
*/
|
|
255
124
|
declare function executeGenerationPhase(opts: GenerationPhaseOptions): Promise<GenerationPhaseResult>;
|
|
256
125
|
|
|
257
|
-
export { BUILT_IN_EVALUATORS, ChatMessage,
|
|
126
|
+
export { BUILT_IN_EVALUATORS, ChatMessage, EvalInput, EvalScore, Evaluator, type EvaluatorAggregate, GENERATION_COMPLETION_TOKEN_CAP, type GenerationItem, type GenerationPhaseOptions, type GenerationPhaseResult, ModelClient, NO_REFERENCE_MARKER, RunItem, aggregateScores, deriveReserveTokensPerGeneration, executeGenerationPhase, getEvaluator, hallucinationJudge, qaCorrectnessJudge, qaCorrectnessReferenceJudge, relevanceJudge, summarizationJudge, toxicityJudge, trajectoryCoherenceJudge };
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const EvaluatorKind: z.ZodEnum<{
|
|
4
|
+
"llm-judge": "llm-judge";
|
|
5
|
+
code: "code";
|
|
6
|
+
heuristic: "heuristic";
|
|
7
|
+
}>;
|
|
8
|
+
type EvaluatorKind = z.infer<typeof EvaluatorKind>;
|
|
9
|
+
declare const TokenUsage: z.ZodObject<{
|
|
10
|
+
inputTokens: z.ZodNumber;
|
|
11
|
+
outputTokens: z.ZodNumber;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
type TokenUsage = z.infer<typeof TokenUsage>;
|
|
14
|
+
/**
|
|
15
|
+
* One evaluator's verdict on one example (or, later, one span). `score` is
|
|
16
|
+
* normalized to [0, 1] where defined; `label` carries the categorical verdict
|
|
17
|
+
* ("hallucinated", "correct", …). Provenance fields are mandatory — every
|
|
18
|
+
* score must be traceable to evaluator name+version and, for judges, the
|
|
19
|
+
* prompt hash and model endpoint (governance: evals-judge-provenance).
|
|
20
|
+
*/
|
|
21
|
+
declare const EvalScore: z.ZodObject<{
|
|
22
|
+
evaluatorName: z.ZodString;
|
|
23
|
+
evaluatorVersion: z.ZodString;
|
|
24
|
+
label: z.ZodOptional<z.ZodString>;
|
|
25
|
+
score: z.ZodNullable<z.ZodNumber>;
|
|
26
|
+
explanation: z.ZodOptional<z.ZodString>;
|
|
27
|
+
promptHash: z.ZodOptional<z.ZodString>;
|
|
28
|
+
modelEndpoint: z.ZodOptional<z.ZodString>;
|
|
29
|
+
tokens: z.ZodOptional<z.ZodObject<{
|
|
30
|
+
inputTokens: z.ZodNumber;
|
|
31
|
+
outputTokens: z.ZodNumber;
|
|
32
|
+
}, z.core.$strip>>;
|
|
33
|
+
latencyMs: z.ZodNumber;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
type EvalScore = z.infer<typeof EvalScore>;
|
|
36
|
+
declare const EvalRunStatus: z.ZodEnum<{
|
|
37
|
+
pending: "pending";
|
|
38
|
+
running: "running";
|
|
39
|
+
succeeded: "succeeded";
|
|
40
|
+
failed: "failed";
|
|
41
|
+
cancelled: "cancelled";
|
|
42
|
+
}>;
|
|
43
|
+
type EvalRunStatus = z.infer<typeof EvalRunStatus>;
|
|
44
|
+
/** Target of a run: a frozen dataset version, or a live experiment's variants. */
|
|
45
|
+
declare const EvalRunTarget: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
46
|
+
kind: z.ZodLiteral<"dataset">;
|
|
47
|
+
datasetId: z.ZodString;
|
|
48
|
+
version: z.ZodNumber;
|
|
49
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
50
|
+
kind: z.ZodLiteral<"experiment">;
|
|
51
|
+
experimentId: z.ZodString;
|
|
52
|
+
metricEventName: z.ZodOptional<z.ZodString>;
|
|
53
|
+
}, z.core.$strip>], "kind">;
|
|
54
|
+
type EvalRunTarget = z.infer<typeof EvalRunTarget>;
|
|
55
|
+
/** One rendered conversation the generation phase completes through the model. */
|
|
56
|
+
declare const GenerationSignalItem: z.ZodObject<{
|
|
57
|
+
itemId: z.ZodString;
|
|
58
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
59
|
+
role: z.ZodEnum<{
|
|
60
|
+
system: "system";
|
|
61
|
+
user: "user";
|
|
62
|
+
assistant: "assistant";
|
|
63
|
+
}>;
|
|
64
|
+
content: z.ZodString;
|
|
65
|
+
}, z.core.$strip>>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
type GenerationSignalItem = z.infer<typeof GenerationSignalItem>;
|
|
68
|
+
/**
|
|
69
|
+
* Generation phase of a playground-replay run (rendered prompt version per
|
|
70
|
+
* example). Rendering happens at dispatch time (pure); the model calls
|
|
71
|
+
* happen in the durable executor, and their tokens count inside
|
|
72
|
+
* `maxJudgeTokens` — the run's SHARED budget (review fix: generation must
|
|
73
|
+
* not occur outside the budget or the request-side lifecycle).
|
|
74
|
+
*/
|
|
75
|
+
declare const GenerationSignal: z.ZodObject<{
|
|
76
|
+
promptId: z.ZodString;
|
|
77
|
+
promptVersion: z.ZodNumber;
|
|
78
|
+
reserveTokensPerCall: z.ZodNumber;
|
|
79
|
+
maxOutputTokens: z.ZodNumber;
|
|
80
|
+
temperature: z.ZodNumber;
|
|
81
|
+
items: z.ZodArray<z.ZodObject<{
|
|
82
|
+
itemId: z.ZodString;
|
|
83
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
84
|
+
role: z.ZodEnum<{
|
|
85
|
+
system: "system";
|
|
86
|
+
user: "user";
|
|
87
|
+
assistant: "assistant";
|
|
88
|
+
}>;
|
|
89
|
+
content: z.ZodString;
|
|
90
|
+
}, z.core.$strip>>;
|
|
91
|
+
}, z.core.$strip>>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
type GenerationSignal = z.infer<typeof GenerationSignal>;
|
|
94
|
+
declare const EvalRunSpec: z.ZodObject<{
|
|
95
|
+
runId: z.ZodString;
|
|
96
|
+
tenantId: z.ZodString;
|
|
97
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
98
|
+
kind: z.ZodLiteral<"dataset">;
|
|
99
|
+
datasetId: z.ZodString;
|
|
100
|
+
version: z.ZodNumber;
|
|
101
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
102
|
+
kind: z.ZodLiteral<"experiment">;
|
|
103
|
+
experimentId: z.ZodString;
|
|
104
|
+
metricEventName: z.ZodOptional<z.ZodString>;
|
|
105
|
+
}, z.core.$strip>], "kind">;
|
|
106
|
+
generation: z.ZodOptional<z.ZodObject<{
|
|
107
|
+
promptId: z.ZodString;
|
|
108
|
+
promptVersion: z.ZodNumber;
|
|
109
|
+
reserveTokensPerCall: z.ZodNumber;
|
|
110
|
+
maxOutputTokens: z.ZodNumber;
|
|
111
|
+
temperature: z.ZodNumber;
|
|
112
|
+
items: z.ZodArray<z.ZodObject<{
|
|
113
|
+
itemId: z.ZodString;
|
|
114
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
115
|
+
role: z.ZodEnum<{
|
|
116
|
+
system: "system";
|
|
117
|
+
user: "user";
|
|
118
|
+
assistant: "assistant";
|
|
119
|
+
}>;
|
|
120
|
+
content: z.ZodString;
|
|
121
|
+
}, z.core.$strip>>;
|
|
122
|
+
}, z.core.$strip>>;
|
|
123
|
+
}, z.core.$strip>>;
|
|
124
|
+
evaluatorNames: z.ZodArray<z.ZodString>;
|
|
125
|
+
maxJudgeTokens: z.ZodOptional<z.ZodNumber>;
|
|
126
|
+
reserveTokensPerCall: z.ZodOptional<z.ZodNumber>;
|
|
127
|
+
createdAtIso: z.ZodString;
|
|
128
|
+
}, z.core.$strip>;
|
|
129
|
+
type EvalRunSpec = z.infer<typeof EvalRunSpec>;
|
|
130
|
+
declare const EvalRun: z.ZodObject<{
|
|
131
|
+
runId: z.ZodString;
|
|
132
|
+
tenantId: z.ZodString;
|
|
133
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
134
|
+
kind: z.ZodLiteral<"dataset">;
|
|
135
|
+
datasetId: z.ZodString;
|
|
136
|
+
version: z.ZodNumber;
|
|
137
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
138
|
+
kind: z.ZodLiteral<"experiment">;
|
|
139
|
+
experimentId: z.ZodString;
|
|
140
|
+
metricEventName: z.ZodOptional<z.ZodString>;
|
|
141
|
+
}, z.core.$strip>], "kind">;
|
|
142
|
+
generation: z.ZodOptional<z.ZodObject<{
|
|
143
|
+
promptId: z.ZodString;
|
|
144
|
+
promptVersion: z.ZodNumber;
|
|
145
|
+
reserveTokensPerCall: z.ZodNumber;
|
|
146
|
+
maxOutputTokens: z.ZodNumber;
|
|
147
|
+
temperature: z.ZodNumber;
|
|
148
|
+
items: z.ZodArray<z.ZodObject<{
|
|
149
|
+
itemId: z.ZodString;
|
|
150
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
151
|
+
role: z.ZodEnum<{
|
|
152
|
+
system: "system";
|
|
153
|
+
user: "user";
|
|
154
|
+
assistant: "assistant";
|
|
155
|
+
}>;
|
|
156
|
+
content: z.ZodString;
|
|
157
|
+
}, z.core.$strip>>;
|
|
158
|
+
}, z.core.$strip>>;
|
|
159
|
+
}, z.core.$strip>>;
|
|
160
|
+
evaluatorNames: z.ZodArray<z.ZodString>;
|
|
161
|
+
maxJudgeTokens: z.ZodOptional<z.ZodNumber>;
|
|
162
|
+
reserveTokensPerCall: z.ZodOptional<z.ZodNumber>;
|
|
163
|
+
createdAtIso: z.ZodString;
|
|
164
|
+
status: z.ZodEnum<{
|
|
165
|
+
pending: "pending";
|
|
166
|
+
running: "running";
|
|
167
|
+
succeeded: "succeeded";
|
|
168
|
+
failed: "failed";
|
|
169
|
+
cancelled: "cancelled";
|
|
170
|
+
}>;
|
|
171
|
+
scoredExamples: z.ZodNumber;
|
|
172
|
+
totalExamples: z.ZodNumber;
|
|
173
|
+
tokensSpent: z.ZodNumber;
|
|
174
|
+
costUsd: z.ZodNullable<z.ZodNumber>;
|
|
175
|
+
startedAtIso: z.ZodOptional<z.ZodString>;
|
|
176
|
+
finishedAtIso: z.ZodOptional<z.ZodString>;
|
|
177
|
+
error: z.ZodOptional<z.ZodString>;
|
|
178
|
+
}, z.core.$strip>;
|
|
179
|
+
type EvalRun = z.infer<typeof EvalRun>;
|
|
180
|
+
|
|
181
|
+
interface ChatMessage {
|
|
182
|
+
role: 'system' | 'user' | 'assistant';
|
|
183
|
+
content: string;
|
|
184
|
+
}
|
|
185
|
+
interface ModelResponse {
|
|
186
|
+
text: string;
|
|
187
|
+
tokens: TokenUsage;
|
|
188
|
+
}
|
|
189
|
+
interface ModelCompletionOptions {
|
|
190
|
+
/** Judges must be deterministic unless a caller explicitly builds another evaluator. */
|
|
191
|
+
temperature: number;
|
|
192
|
+
/** Provider-enforced completion ceiling used by the run budget reservation. */
|
|
193
|
+
maxOutputTokens: number;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The only surface through which evaluators reach a model. Production ships
|
|
197
|
+
* a Databricks Model Serving adapter at the explicit `/databricks` package
|
|
198
|
+
* subpath; the provider-neutral root never imports a provider client. Tests
|
|
199
|
+
* use `StaticModelClient`.
|
|
200
|
+
*/
|
|
201
|
+
interface ModelClient {
|
|
202
|
+
/** Identifier recorded in EvalScore.modelEndpoint for provenance. */
|
|
203
|
+
readonly endpoint: string;
|
|
204
|
+
complete(messages: readonly ChatMessage[], options: ModelCompletionOptions): Promise<ModelResponse>;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Deterministic client for unit tests and `fx dev`: responses are matched by
|
|
208
|
+
* substring of the last user message, mirroring the frozen-vector discipline
|
|
209
|
+
* in `@fabricorg/experiments-testkit`.
|
|
210
|
+
*/
|
|
211
|
+
declare class StaticModelClient implements ModelClient {
|
|
212
|
+
private readonly rules;
|
|
213
|
+
private readonly fallback;
|
|
214
|
+
readonly endpoint = "static-test-endpoint";
|
|
215
|
+
constructor(rules: Array<{
|
|
216
|
+
match: string;
|
|
217
|
+
respond: string;
|
|
218
|
+
}>, fallback?: string);
|
|
219
|
+
complete(messages: readonly ChatMessage[], options: ModelCompletionOptions): Promise<ModelResponse>;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Conservative provider-independent upper bound used before a judge call.
|
|
223
|
+
* A tokenizer cannot emit more tokens than the UTF-8 bytes representing the
|
|
224
|
+
* message content; the fixed allowance covers chat framing and role markers.
|
|
225
|
+
*/
|
|
226
|
+
declare function maxCompletionTokenUsage(messages: readonly ChatMessage[], options: ModelCompletionOptions): number;
|
|
227
|
+
|
|
228
|
+
/** What an evaluator sees: the example under test plus the produced output. */
|
|
229
|
+
interface EvalInput {
|
|
230
|
+
input: unknown;
|
|
231
|
+
output: unknown;
|
|
232
|
+
expectedOutput?: unknown;
|
|
233
|
+
/** Retrieved context for RAG-style judges (documents, tool results). */
|
|
234
|
+
context?: unknown;
|
|
235
|
+
metadata?: Record<string, unknown>;
|
|
236
|
+
}
|
|
237
|
+
interface EvalContext {
|
|
238
|
+
model: ModelClient;
|
|
239
|
+
nowMs: () => number;
|
|
240
|
+
}
|
|
241
|
+
interface Evaluator {
|
|
242
|
+
readonly kind: EvaluatorKind;
|
|
243
|
+
readonly name: string;
|
|
244
|
+
readonly version: string;
|
|
245
|
+
/** Worst-case judge usage reserved before IO; absent for token-free evaluators. */
|
|
246
|
+
maxJudgeTokens?(input: EvalInput): number;
|
|
247
|
+
/**
|
|
248
|
+
* The judge's prompt template, when the evaluator is an LLM judge. Exposed
|
|
249
|
+
* so budget derivation (deriveReserveTokensPerCall) can size worst-case
|
|
250
|
+
* per-call token reservations from the actual prompt text.
|
|
251
|
+
*/
|
|
252
|
+
readonly promptTemplate?: Pick<JudgeTemplate, 'system' | 'user'>;
|
|
253
|
+
evaluate(input: EvalInput, ctx: EvalContext): Promise<EvalScore>;
|
|
254
|
+
}
|
|
255
|
+
interface JudgeTemplate {
|
|
256
|
+
name: string;
|
|
257
|
+
version: string;
|
|
258
|
+
/** Labels the judge may answer with, mapped to normalized scores. */
|
|
259
|
+
labels: Record<string, number>;
|
|
260
|
+
system: string;
|
|
261
|
+
/** Rendered with {{input}}, {{output}}, {{expectedOutput}}, {{context}}. */
|
|
262
|
+
user: string;
|
|
263
|
+
/** Deterministic provider-enforced response ceiling. Default: 256. */
|
|
264
|
+
maxOutputTokens?: number;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Build an LLM-judge evaluator from a template. Response contract: the model
|
|
268
|
+
* answers `LABEL: <label>` on the first line, free-form explanation after —
|
|
269
|
+
* a portable explanation-bearing format that remains easy to import/export.
|
|
270
|
+
*/
|
|
271
|
+
declare function llmJudge(template: JudgeTemplate): Evaluator;
|
|
272
|
+
/** Build a deterministic code evaluator from a pure function. */
|
|
273
|
+
declare function codeEvaluator(name: string, version: string, fn: (input: EvalInput) => {
|
|
274
|
+
label?: string;
|
|
275
|
+
score: number | null;
|
|
276
|
+
explanation?: string;
|
|
277
|
+
}): Evaluator;
|
|
278
|
+
declare function render(template: string, input: EvalInput): string;
|
|
279
|
+
declare function parseJudgeResponse(text: string, labels: Record<string, number>): {
|
|
280
|
+
label?: string;
|
|
281
|
+
score: number | null;
|
|
282
|
+
explanation?: string;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
interface RunItem {
|
|
286
|
+
/** Dataset exampleId or span id — opaque to the runner. */
|
|
287
|
+
itemId: string;
|
|
288
|
+
input: EvalInput;
|
|
289
|
+
}
|
|
290
|
+
interface ScoredItem {
|
|
291
|
+
itemId: string;
|
|
292
|
+
score: EvalScore;
|
|
293
|
+
}
|
|
294
|
+
interface ExecuteOptions {
|
|
295
|
+
evaluators: readonly Evaluator[];
|
|
296
|
+
items: readonly RunItem[];
|
|
297
|
+
ctx: EvalContext;
|
|
298
|
+
/**
|
|
299
|
+
* Hard token budget (governance: eval-cost-controls). Enforced by
|
|
300
|
+
* reservation: a judge call only starts if `spent + reserved +
|
|
301
|
+
* reserveTokensPerCall` still fits, so concurrent workers can never
|
|
302
|
+
* collectively overshoot by racing the check.
|
|
303
|
+
*/
|
|
304
|
+
maxJudgeTokens?: number;
|
|
305
|
+
/**
|
|
306
|
+
* Optional minimum reservation per judge call. The runner always takes the
|
|
307
|
+
* larger of this value and the evaluator's input-specific worst-case bound.
|
|
308
|
+
* Code and heuristic evaluators reserve zero tokens and continue after a
|
|
309
|
+
* judge budget is exhausted.
|
|
310
|
+
*/
|
|
311
|
+
reserveTokensPerCall?: number;
|
|
312
|
+
concurrency?: number;
|
|
313
|
+
/** Called after each item completes — the agent checkpoints here. */
|
|
314
|
+
onProgress?: (done: number, total: number, tokensSpent: number) => void;
|
|
315
|
+
}
|
|
316
|
+
interface ExecuteResult {
|
|
317
|
+
scores: ScoredItem[];
|
|
318
|
+
tokensSpent: number;
|
|
319
|
+
/** Items fully or partially skipped because the token budget was exhausted. */
|
|
320
|
+
skippedForBudget: number;
|
|
321
|
+
/** Individual judge evaluations skipped because their reservation did not fit. */
|
|
322
|
+
skippedEvaluationsForBudget: number;
|
|
323
|
+
/** Per-item evaluator failures (item kept; other evaluators still ran). */
|
|
324
|
+
failures: Array<{
|
|
325
|
+
itemId: string;
|
|
326
|
+
evaluatorName: string;
|
|
327
|
+
message: string;
|
|
328
|
+
}>;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Completion cap assumed per judge call when sizing reservations. Judges
|
|
332
|
+
* answer `LABEL: <label>` plus a brief explanation — 512 tokens is a generous
|
|
333
|
+
* ceiling for that contract.
|
|
334
|
+
*/
|
|
335
|
+
declare const JUDGE_COMPLETION_TOKEN_CAP = 512;
|
|
336
|
+
/**
|
|
337
|
+
* Prompt-token allowance for the item content rendered into the template
|
|
338
|
+
* ({{input}}/{{output}}/{{expectedOutput}}/{{context}}). A worst-case bound
|
|
339
|
+
* for typical dataset examples; oversized examples only weaken the guarantee
|
|
340
|
+
* to "caps the number of calls started" (see reserveTokensPerCall docs).
|
|
341
|
+
*/
|
|
342
|
+
declare const ITEM_CONTENT_TOKEN_ALLOWANCE = 1024;
|
|
343
|
+
/**
|
|
344
|
+
* Worst-case tokens one judge call may consume, derived from the largest
|
|
345
|
+
* prompt template among the run's evaluators (chars/4 heuristic) plus the
|
|
346
|
+
* item-content allowance and the completion cap. Threaded from run creation
|
|
347
|
+
* into ExecuteOptions.reserveTokensPerCall so the hard budget is enforced by
|
|
348
|
+
* reservation rather than after-the-fact accounting.
|
|
349
|
+
*/
|
|
350
|
+
declare function deriveReserveTokensPerCall(evaluators: readonly Evaluator[]): number;
|
|
351
|
+
/**
|
|
352
|
+
* Pure orchestration: evaluate every item with every evaluator under a hard
|
|
353
|
+
* token budget, bounded concurrency, and per-evaluator error isolation. IO
|
|
354
|
+
* happens only through the injected ModelClient; persistence is the caller's
|
|
355
|
+
* job (the eval-runner agent writes to the warehouse between batches).
|
|
356
|
+
*/
|
|
357
|
+
declare function executeEvalRun(opts: ExecuteOptions): Promise<ExecuteResult>;
|
|
358
|
+
|
|
359
|
+
export { type ChatMessage as C, type Evaluator as E, GenerationSignal as G, ITEM_CONTENT_TOKEN_ALLOWANCE as I, JUDGE_COMPLETION_TOKEN_CAP as J, type ModelClient as M, type RunItem as R, type ScoredItem as S, TokenUsage as T, EvalScore as a, type EvalInput as b, type EvalContext as c, EvalRun as d, EvalRunSpec as e, EvalRunStatus as f, EvalRunTarget as g, EvaluatorKind as h, type ExecuteOptions as i, type ExecuteResult as j, GenerationSignalItem as k, type JudgeTemplate as l, type ModelCompletionOptions as m, type ModelResponse as n, StaticModelClient as o, codeEvaluator as p, deriveReserveTokensPerCall as q, executeEvalRun as r, llmJudge as s, maxCompletionTokenUsage as t, parseJudgeResponse as u, render as v };
|