@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/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
- it("keeps the temperature a run was tested at", async () => {
138
- const store = await make();
139
- const warm = await store.createRun({ ...newRun("s"), temperature: 0.7 });
140
- const none = await store.createRun({ ...newRun("s"), temperature: null });
141
- expect((await store.getRun(warm.id))?.temperature).toBe(0.7);
142
- expect((await store.getRun(none.id))?.temperature ?? null).toBeNull();
143
- });
144
-
145
- it("keeps the output cap a run was tested at", async () => {
146
- const store = await make();
147
- const capped = await store.createRun({
148
- ...newRun("s"),
149
- maxOutputTokens: 4000,
150
- });
151
- const none = await store.createRun({
152
- ...newRun("s"),
153
- maxOutputTokens: null,
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
- expect((await store.getRun(capped.id))?.maxOutputTokens).toBe(4000);
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
- it("keeps a version's temperature", async () => {
484
- const store = await make();
485
- const v1 = await store.switchTo("triage", {
486
- ...create("a", null),
487
- create: {
488
- settings: { ...settings("a"), temperature: 0.4 },
489
- promptVersion: "p1",
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
- expect(v1.temperature).toBe(0.4);
493
- expect((await store.liveVersion("triage"))?.temperature).toBe(0.4);
494
- const v2 = await store.switchTo("triage", create("b", v1.id));
495
- expect(v2.temperature ?? null).toBeNull();
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
- {right}/{total}
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 { row, evidence } = await evidenceFor(suite.key, model);
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
  }