@crowandraven/evalkeeper 0.4.0 → 0.5.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/board.d.ts +5 -1
- package/dist/cli/addPages.d.ts +34 -0
- package/dist/cli/addPages.js +88 -11
- package/dist/cli/addPages.js.map +1 -1
- package/dist/cli/main.d.ts +1 -1
- package/dist/cli/main.js +8 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/glossary.d.ts +1 -1
- package/dist/glossary.js +1 -1
- package/dist/glossary.js.map +1 -1
- package/dist/runner.js +4 -6
- package/dist/runner.js.map +1 -1
- package/dist/testing.d.ts +20 -4
- package/dist/testing.js +57 -36
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
- package/src/board.ts +5 -1
- package/src/cli/addPages.ts +116 -17
- package/src/cli/main.ts +10 -0
- package/src/glossary.ts +1 -1
- package/src/runner.ts +4 -6
- package/src/testing.ts +73 -35
- package/templates/app/evals/[suite]/page.tsx +7 -0
- package/templates/components/evalkeeper/ui.tsx +3 -1
- package/templates/lib/evalkeeper/actions.ts +20 -6
package/src/testing.ts
CHANGED
|
@@ -15,10 +15,24 @@ import {
|
|
|
15
15
|
import type { EvalStore, NewCase } from "./store.js";
|
|
16
16
|
import type { Suite } from "./types.js";
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Options for a store contract, for a store on tables that lack an
|
|
20
|
+
* optional column.
|
|
21
|
+
*/
|
|
22
|
+
export type StoreContractOptions = {
|
|
23
|
+
/**
|
|
24
|
+
* Settings the store has no column for. The contract then checks the
|
|
25
|
+
* store refuses a value for them (rather than losing it) and reads
|
|
26
|
+
* them as null.
|
|
27
|
+
*/
|
|
28
|
+
without?: ("temperature" | "maxOutputTokens")[];
|
|
29
|
+
};
|
|
30
|
+
|
|
18
31
|
/**
|
|
19
32
|
* The contract every EvalStore must meet, as Vitest tests. Run it against
|
|
20
33
|
* your store to know the runner will work on it. `make` must return an
|
|
21
|
-
* empty store each time it's called.
|
|
34
|
+
* empty store each time it's called; `opts.without` names run settings
|
|
35
|
+
* its tables have no column for.
|
|
22
36
|
*
|
|
23
37
|
* @example
|
|
24
38
|
* ```ts
|
|
@@ -30,6 +44,7 @@ import type { Suite } from "./types.js";
|
|
|
30
44
|
export function describeStoreContract(
|
|
31
45
|
name: string,
|
|
32
46
|
make: () => EvalStore | Promise<EvalStore>,
|
|
47
|
+
opts: StoreContractOptions = {},
|
|
33
48
|
) {
|
|
34
49
|
const newCase = (suite: string, over: Partial<NewCase> = {}): NewCase => ({
|
|
35
50
|
suite,
|
|
@@ -134,27 +149,30 @@ export function describeStoreContract(
|
|
|
134
149
|
expect(await store.getRun("missing")).toBeNull();
|
|
135
150
|
});
|
|
136
151
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
const runSettings = [
|
|
153
|
+
["temperature", "temperature", 0.7],
|
|
154
|
+
["maxOutputTokens", "output cap", 4000],
|
|
155
|
+
] as const;
|
|
156
|
+
for (const [field, words, value] of runSettings) {
|
|
157
|
+
if (opts.without?.includes(field)) {
|
|
158
|
+
it(`refuses a ${words} it has no column for, and keeps none`, async () => {
|
|
159
|
+
const store = await make();
|
|
160
|
+
await expect(
|
|
161
|
+
store.createRun({ ...newRun("s"), [field]: value }),
|
|
162
|
+
).rejects.toThrow(field);
|
|
163
|
+
const none = await store.createRun({ ...newRun("s"), [field]: null });
|
|
164
|
+
expect((await store.getRun(none.id))?.[field] ?? null).toBeNull();
|
|
165
|
+
});
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
it(`keeps the ${words} a run was tested at`, async () => {
|
|
169
|
+
const store = await make();
|
|
170
|
+
const set = await store.createRun({ ...newRun("s"), [field]: value });
|
|
171
|
+
const none = await store.createRun({ ...newRun("s"), [field]: null });
|
|
172
|
+
expect((await store.getRun(set.id))?.[field]).toBe(value);
|
|
173
|
+
expect((await store.getRun(none.id))?.[field] ?? null).toBeNull();
|
|
154
174
|
});
|
|
155
|
-
|
|
156
|
-
expect((await store.getRun(none.id))?.maxOutputTokens ?? null).toBeNull();
|
|
157
|
-
});
|
|
175
|
+
}
|
|
158
176
|
|
|
159
177
|
it("updates a run only while it has the status it's guarded by", async () => {
|
|
160
178
|
const store = await make();
|
|
@@ -381,11 +399,13 @@ export function describeFeedbackStoreContract(
|
|
|
381
399
|
|
|
382
400
|
/**
|
|
383
401
|
* The contract every SettingsStore must meet. `make` must return an empty
|
|
384
|
-
* store each time it's called.
|
|
402
|
+
* store each time it's called; `opts.without` names settings its tables
|
|
403
|
+
* have no column for (see `StoreContractOptions`).
|
|
385
404
|
*/
|
|
386
405
|
export function describeSettingsStoreContract(
|
|
387
406
|
name: string,
|
|
388
407
|
make: () => SettingsStore | Promise<SettingsStore>,
|
|
408
|
+
opts: { without?: "temperature"[] } = {},
|
|
389
409
|
) {
|
|
390
410
|
const settings = (model: string): Settings => ({
|
|
391
411
|
model,
|
|
@@ -480,20 +500,38 @@ export function describeSettingsStoreContract(
|
|
|
480
500
|
);
|
|
481
501
|
});
|
|
482
502
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
503
|
+
if (opts.without?.includes("temperature")) {
|
|
504
|
+
it("refuses a temperature it has no column for, and keeps none", async () => {
|
|
505
|
+
const store = await make();
|
|
506
|
+
await expect(
|
|
507
|
+
store.switchTo("triage", {
|
|
508
|
+
...create("a", null),
|
|
509
|
+
create: {
|
|
510
|
+
settings: { ...settings("a"), temperature: 0.4 },
|
|
511
|
+
promptVersion: "p1",
|
|
512
|
+
},
|
|
513
|
+
}),
|
|
514
|
+
).rejects.toThrow("temperature");
|
|
515
|
+
expect(await store.liveVersion("triage")).toBeNull();
|
|
516
|
+
const v1 = await store.switchTo("triage", create("a", null));
|
|
517
|
+
expect(v1.temperature ?? null).toBeNull();
|
|
491
518
|
});
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
519
|
+
} else {
|
|
520
|
+
it("keeps a version's temperature", async () => {
|
|
521
|
+
const store = await make();
|
|
522
|
+
const v1 = await store.switchTo("triage", {
|
|
523
|
+
...create("a", null),
|
|
524
|
+
create: {
|
|
525
|
+
settings: { ...settings("a"), temperature: 0.4 },
|
|
526
|
+
promptVersion: "p1",
|
|
527
|
+
},
|
|
528
|
+
});
|
|
529
|
+
expect(v1.temperature).toBe(0.4);
|
|
530
|
+
expect((await store.liveVersion("triage"))?.temperature).toBe(0.4);
|
|
531
|
+
const v2 = await store.switchTo("triage", create("b", v1.id));
|
|
532
|
+
expect(v2.temperature ?? null).toBeNull();
|
|
533
|
+
});
|
|
534
|
+
}
|
|
497
535
|
|
|
498
536
|
it("keeps each feature's versions and live one apart", async () => {
|
|
499
537
|
const store = await make();
|
|
@@ -335,6 +335,13 @@ export default async function SuitePage({
|
|
|
335
335
|
id={r.key}
|
|
336
336
|
estimate={estimates.get(r.key)}
|
|
337
337
|
/>
|
|
338
|
+
{r.test && !r.test.stale && r.test.failedAnswers > 0 && (
|
|
339
|
+
<span className="text-right text-xs text-muted">
|
|
340
|
+
{r.test.failedAnswers}{" "}
|
|
341
|
+
{r.test.failedAnswers === 1 ? "answer" : "answers"}{" "}
|
|
342
|
+
failed on its last test
|
|
343
|
+
</span>
|
|
344
|
+
)}
|
|
338
345
|
</div>
|
|
339
346
|
</td>
|
|
340
347
|
</tr>
|
|
@@ -49,7 +49,9 @@ export function Score({ right, total }: { right: number; total: number }) {
|
|
|
49
49
|
/>
|
|
50
50
|
</span>
|
|
51
51
|
<span className="text-xs text-muted tabular-nums">
|
|
52
|
-
{
|
|
52
|
+
{/* Whole numbers: a failed answer counts a graded answer's average
|
|
53
|
+
parts, which can be a fraction. */}
|
|
54
|
+
{Math.round(right)}/{Math.round(total)}
|
|
53
55
|
</span>
|
|
54
56
|
</div>
|
|
55
57
|
);
|
|
@@ -66,6 +66,24 @@ async function evidenceFor(suiteKey: string, model: string) {
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/** What a fallback choice records: its current test, if it has one. */
|
|
70
|
+
async function fallbackEvidence(suiteKey: string, model: string) {
|
|
71
|
+
const board = await runner.board(suiteKey);
|
|
72
|
+
const row = board.rows.find((r) => r.model === model && !r.variant);
|
|
73
|
+
if (!row?.canMakeFallback)
|
|
74
|
+
throw new Error("This model can't be the fallback");
|
|
75
|
+
const test = row.test && !row.test.stale ? row.test : null;
|
|
76
|
+
const failed = test?.failedAnswers ? `, ${test.failedAnswers} failed` : "";
|
|
77
|
+
return {
|
|
78
|
+
reason: `Made ${row.label} the fallback: ${test ? `${Math.round(test.right)}/${Math.round(test.total)}${failed}` : "not tested"}`,
|
|
79
|
+
evidence: {
|
|
80
|
+
runId: test?.runId ?? null,
|
|
81
|
+
liveRunId: board.liveRunId,
|
|
82
|
+
score: test ? { right: test.right, total: test.total } : null,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
69
87
|
const VS: Record<string, string> = {
|
|
70
88
|
BETTER: "more accurate than live",
|
|
71
89
|
SAME: "about as accurate as live",
|
|
@@ -94,15 +112,11 @@ export async function makeFallback(form: FormData) {
|
|
|
94
112
|
const admin = await requireAdmin();
|
|
95
113
|
const suite = suiteFrom(form);
|
|
96
114
|
const model = formText(form, "model");
|
|
97
|
-
const {
|
|
115
|
+
const { reason, evidence } = await fallbackEvidence(suite.key, model);
|
|
98
116
|
await settings.update(
|
|
99
117
|
suite.operation,
|
|
100
118
|
{ fallbackModel: model },
|
|
101
|
-
{
|
|
102
|
-
by: admin.name,
|
|
103
|
-
reason: `Made ${row.label} the fallback: ${evidence.score.right}/${evidence.score.total}, from another provider`,
|
|
104
|
-
evidence,
|
|
105
|
-
},
|
|
119
|
+
{ by: admin.name, reason, evidence },
|
|
106
120
|
);
|
|
107
121
|
revalidatePath(EVALS_BASE, "layout");
|
|
108
122
|
}
|