@crowandraven/evalkeeper 0.17.0 → 0.18.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.
@@ -33,14 +33,14 @@ export function Fields({
33
33
  <label htmlFor={id} className="block text-sm font-medium">
34
34
  {f.label}
35
35
  </label>
36
- {f.kind === "select" ? (
36
+ {f.kind === "select" || choices(f) ? (
37
37
  <Select
38
38
  id={id}
39
39
  name={f.name}
40
- defaultValue={value || f.options?.[0]}
40
+ defaultValue={value || (f.options ?? choices(f))?.[0]}
41
41
  className={box}
42
42
  >
43
- {f.options?.map((o) => (
43
+ {(f.options ?? choices(f))?.map((o) => (
44
44
  <option key={o} value={o}>
45
45
  {f.optionLabels?.[o] ?? o.replace(/_/g, " ")}
46
46
  </option>
@@ -102,15 +102,12 @@ export function FieldValues({
102
102
  <InfoTip text={f.help} id={`${prefix}${f.name}-read`} />
103
103
  </dt>
104
104
  <dd className="mt-0.5 break-words">
105
- {f.kind === "select" &&
106
- typeof v === "string" &&
107
- f.optionLabels?.[v] ? (
108
- f.optionLabels[v]
109
- ) : f.kind === "json" && typeof v === "string" ? (
110
- <ReadableValue value={parseJson(v)} marks={marks} />
111
- ) : (
112
- <ReadableValue value={v} marks={marks} />
113
- )}
105
+ {labelOf(f, v) ??
106
+ (f.kind === "json" && typeof v === "string" ? (
107
+ <ReadableValue value={parseJson(v)} marks={marks} />
108
+ ) : (
109
+ <ReadableValue value={v} marks={marks} />
110
+ ))}
114
111
  </dd>
115
112
  </div>
116
113
  );
@@ -119,6 +116,26 @@ export function FieldValues({
119
116
  );
120
117
  }
121
118
 
119
+ /**
120
+ * A JSON field whose values are all named in `optionLabels` (a
121
+ * yes-or-no: "true" and "false") is a choice, not a box to type JSON in.
122
+ * Its value is submitted as the JSON it names.
123
+ */
124
+ function choices(f: FormField): string[] | undefined {
125
+ if (f.kind !== "json" || !f.optionLabels) return undefined;
126
+ const keys = Object.keys(f.optionLabels);
127
+ return keys.length ? keys : undefined;
128
+ }
129
+
130
+ /**
131
+ * How a value reads by the field's `optionLabels`: a choice ("YES" →
132
+ * "Would apply") or a yes-or-no (true → "Yes, as they typed it").
133
+ */
134
+ function labelOf(f: FormField, v: unknown): string | undefined {
135
+ if (typeof v !== "string" && typeof v !== "boolean") return undefined;
136
+ return f.optionLabels?.[String(v)];
137
+ }
138
+
122
139
  /** A JSON field stored as text, parsed when it parses. */
123
140
  function parseJson(text: string): unknown {
124
141
  try {
@@ -203,8 +203,8 @@ export function ReadableValue({
203
203
  return <span className="text-muted">—</span>;
204
204
  if (typeof value === "string")
205
205
  return <ReadableText text={value} marks={marks} />;
206
- if (typeof value === "number" || typeof value === "boolean")
207
- return String(value);
206
+ if (typeof value === "boolean") return value ? "Yes" : "No";
207
+ if (typeof value === "number") return String(value);
208
208
  if (depth >= MAX_DEPTH)
209
209
  return (
210
210
  <pre className="whitespace-pre-wrap text-xs">
@@ -21,6 +21,9 @@ import {
21
21
  seconds,
22
22
  seriousMistakes,
23
23
  suggest,
24
+ withRounds,
25
+ EASY_FLOOR_CASES,
26
+ EASY_MIN_ROUNDS,
24
27
  } from "../index.js";
25
28
  import { AnswerKey } from "./AnswerKey.js";
26
29
  import { ModelMenu } from "./ModelMenu.js";
@@ -117,7 +120,14 @@ export async function loadSuitePage(app: EvalAppConfig, key: string) {
117
120
  (m, r) => (r.test && (!m || r.test.at > m) ? r.test.at : m),
118
121
  null,
119
122
  );
120
- const health = answerKeyHealth(cases, b.caseResults, new Date(), testedAt);
123
+ // Rounds each case passed (read only past the floor of cases).
124
+ const rounds = await app.runner.easyRounds(key, cases);
125
+ const health = answerKeyHealth(
126
+ cases,
127
+ withRounds(b.caseResults, rounds),
128
+ new Date(),
129
+ testedAt,
130
+ );
121
131
  // For each split case, which models got it fully right and which didn't,
122
132
  // so a person sees the disagreement before deciding.
123
133
  const split = new Set(health.split.map((c) => c.id));
@@ -980,6 +990,10 @@ export function AnswerKeySection({ data }: { data: SuitePageData }) {
980
990
  const { app, key, b, suite, rows, attackBoards } = data;
981
991
  // A feature's attack cases are a tab of its answer key.
982
992
  const attacked = attackBoards.filter((a) => a.cases > 0);
993
+ // Attack tests set up but not made yet: nothing else on this page says so.
994
+ const unmade = app.actions.makeAttackCases
995
+ ? attackBoards.filter((a) => a.cases === 0)
996
+ : [];
983
997
  const guide =
984
998
  suite.answerGuide ??
985
999
  (suite.labelHelp ? { points: [{ text: suite.labelHelp }] } : null);
@@ -1038,6 +1052,32 @@ export function AnswerKeySection({ data }: { data: SuitePageData }) {
1038
1052
  return (
1039
1053
  // The weekly check links here to review drafts.
1040
1054
  <section id="answer-key" className="scroll-mt-4 space-y-3">
1055
+ {unmade.length > 0 && b.cases > 0 && (
1056
+ <Card className="space-y-3">
1057
+ <p className="readable text-sm">
1058
+ <ShieldAlert
1059
+ aria-hidden
1060
+ className="mr-1.5 inline h-4 w-4 text-warn"
1061
+ />
1062
+ This feature has attack tests set up, but no attack cases yet. Each
1063
+ is one of its confirmed cases with an attack planted where text it
1064
+ can&apos;t trust goes, so a test shows whether a model follows it.
1065
+ <InfoTip term="attacksResisted" />
1066
+ </p>
1067
+ <div className="flex flex-wrap gap-2">
1068
+ {unmade.map((a) => (
1069
+ <form key={a.suite.key} action={app.actions.makeAttackCases}>
1070
+ <input type="hidden" name="suite" value={a.suite.key} />
1071
+ <Submit variant="quiet">
1072
+ {unmade.length > 1
1073
+ ? `Make attack cases: ${a.suite.label}`
1074
+ : "Make attack cases"}
1075
+ </Submit>
1076
+ </form>
1077
+ ))}
1078
+ </div>
1079
+ </Card>
1080
+ )}
1041
1081
  {attacked.length === 0 ? (
1042
1082
  cases
1043
1083
  ) : (
@@ -1169,7 +1209,7 @@ function UnderAttack({
1169
1209
  }
1170
1210
 
1171
1211
  /**
1172
- * Keeping the answer key useful: easy cases to retire (a floor stays),
1212
+ * Keeping the answer key useful: easy cases to retire (past a floor of 50),
1173
1213
  * cases models split on and near-duplicates to check, old drafts, and
1174
1214
  * tags with a single case. Shows only what needs a look, and nothing on
1175
1215
  * an injection suite, whose cases are made from its base suite's.
@@ -1376,12 +1416,11 @@ export function AnswerKeyHealthSection({ data }: { data: SuitePageData }) {
1376
1416
  {h.easyToRetire.length > 0 && (
1377
1417
  <div className="space-y-2">
1378
1418
  <p>
1379
- Every current model gets {cases(h.easy.length)} fully right,
1380
- so they no longer tell models apart. Retire{" "}
1381
- {h.easyToRetire.length} and keep{" "}
1382
- {h.easy.length - h.easyToRetire.length} as a floor, so a test
1383
- still catches a model that breaks the basics. Recent tests are
1384
- rescored for free.
1419
+ Every model got {cases(h.easyToRetire.length)} fully right in{" "}
1420
+ {EASY_MIN_ROUNDS} or more rounds of testing, so they no longer
1421
+ tell models apart. Retiring them keeps{" "}
1422
+ {h.inUse - h.easyToRetire.length} cases, at or above the floor
1423
+ of {EASY_FLOOR_CASES}. Recent tests are rescored for free.
1385
1424
  <InfoTip term="easyCases" />
1386
1425
  </p>
1387
1426
  {retireEasy && (
@@ -431,7 +431,7 @@ export function IconSubmit(props: IconSubmitProps) {
431
431
  type="submit"
432
432
  aria-label={props.label}
433
433
  disabled={pending}
434
- className="inline-flex h-8 w-8 items-center justify-center rounded-md border border-line bg-card text-ink hover:bg-tint disabled:opacity-60"
434
+ className={`inline-flex h-8 w-8 items-center justify-center rounded-md disabled:opacity-60 ${QUIET_BUTTON}`}
435
435
  >
436
436
  {pending ? <Spinner /> : props.icon}
437
437
  </button>
package/src/runner.ts CHANGED
@@ -16,7 +16,13 @@ import {
16
16
  import type { BoardRow } from "./board.js";
17
17
  import { allPassed } from "./stats.js";
18
18
  import { pickQuickSet } from "./quickSet.js";
19
- import { answerKeyHealth } from "./prune.js";
19
+ import {
20
+ EASY_FLOOR_CASES,
21
+ EASY_MIN_MODELS,
22
+ answerKeyHealth,
23
+ withRounds,
24
+ type CaseResult,
25
+ } from "./prune.js";
20
26
  import { stableJson } from "./stableJson.js";
21
27
  import { suiteMetrics, type ScoredOutput } from "./stats.js";
22
28
  import type {
@@ -520,7 +526,10 @@ export function createRunner(opts: RunnerOptions) {
520
526
  label: parsed?.success ? parsed.data : null,
521
527
  };
522
528
  });
523
- const extra = suite.gradeTogether(answers);
529
+ // Marked, so the case is known to matter to others (never easy).
530
+ const extra = suite
531
+ .gradeTogether(answers)
532
+ .map((cs) => cs.map((c) => ({ ...c, together: true })));
524
533
  await mapLimit(
525
534
  group.map((o, i) => ({ o, add: extra[i] ?? [] })),
526
535
  6,
@@ -760,13 +769,30 @@ export function createRunner(opts: RunnerOptions) {
760
769
  });
761
770
  }
762
771
 
763
- /** Regrades a suite's recent finished tests, e.g. after answers change. */
772
+ /**
773
+ * Regrades a suite's finished tests after answers change: the latest of
774
+ * every model and setting the board shows, however many tests ran since,
775
+ * plus the `limit` most recent. Any answer change puts every test out of
776
+ * date until it's regraded, and a test left out of date drops out of the
777
+ * board, its scores, and the answer key's health ("models split").
778
+ */
764
779
  async function rescoreRecent(suiteKey: string, limit = 10) {
765
- for (const r of await store.listRuns(suiteKey, {
766
- status: "SUCCEEDED",
767
- limit,
768
- }))
769
- await rescoreRun(r.id);
780
+ const runs = await store.listRuns(suiteKey, { status: "SUCCEEDED" });
781
+ const latest = new Map<string, string>();
782
+ for (const r of runs) {
783
+ const key = [
784
+ r.model,
785
+ r.reasoningEffort ?? "",
786
+ r.temperature ?? "",
787
+ r.maxOutputTokens ?? "",
788
+ ].join("|");
789
+ if (!latest.has(key)) latest.set(key, r.id);
790
+ }
791
+ const ids = new Set([
792
+ ...runs.slice(0, limit).map((r) => r.id),
793
+ ...latest.values(),
794
+ ]);
795
+ for (const id of ids) await rescoreRun(id);
770
796
  }
771
797
 
772
798
  /**
@@ -779,7 +805,57 @@ export function createRunner(opts: RunnerOptions) {
779
805
  board(suiteKey),
780
806
  store.listCases(suiteKey),
781
807
  ]);
782
- return answerKeyHealth(cases, b.caseResults, today);
808
+ const rounds = await easyRounds(suiteKey, cases);
809
+ return answerKeyHealth(cases, withRounds(b.caseResults, rounds), today);
810
+ }
811
+
812
+ /**
813
+ * Per case, the rounds of testing it passed (EASY_MIN_ROUNDS): days on
814
+ * which at least EASY_MIN_MODELS models were tested on it and every one
815
+ * got it fully right (all repeats), counted only after its answer last
816
+ * changed. Empty when the suite has EASY_FLOOR_CASES cases in use or
817
+ * fewer: nothing can be retired then, so the history isn't read.
818
+ */
819
+ async function easyRounds(
820
+ suiteKey: string,
821
+ cases?: readonly CaseRecord[],
822
+ ): Promise<Record<string, number>> {
823
+ const all = cases ?? (await store.listCases(suiteKey));
824
+ const inUse = all.filter(
825
+ (c) => c.status !== "RETIRED" && confirmedLabel(c.labels),
826
+ );
827
+ if (inUse.length <= EASY_FLOOR_CASES) return {};
828
+ const since = new Map(
829
+ inUse.map((c) => {
830
+ const l = confirmedLabel(c.labels);
831
+ return [c.id, Math.max(+c.updatedAt, l ? +l.updatedAt : 0)];
832
+ }),
833
+ );
834
+ const runs = (await store.listRuns(suiteKey, { status: "SUCCEEDED" })).map(
835
+ (r) => ({ ...r, day: r.startedAt.toISOString().slice(0, 10) }),
836
+ );
837
+ const outputs = await outputsByRun(runs.map((r) => r.id));
838
+ // case → day → model → right on every answer that day
839
+ const seen = new Map<string, Map<string, Map<string, boolean>>>();
840
+ for (const r of runs) {
841
+ for (const o of outputs.get(r.id) ?? []) {
842
+ const after = since.get(o.caseId);
843
+ if (after === undefined || +r.startedAt <= after) continue;
844
+ const days =
845
+ seen.get(o.caseId) ?? new Map<string, Map<string, boolean>>();
846
+ const models = days.get(r.day) ?? new Map<string, boolean>();
847
+ const right = !o.error && allPassed(o.scores ?? []);
848
+ models.set(r.model, (models.get(r.model) ?? true) && right);
849
+ days.set(r.day, models);
850
+ seen.set(o.caseId, days);
851
+ }
852
+ }
853
+ const rounds: Record<string, number> = {};
854
+ for (const [caseId, days] of seen)
855
+ rounds[caseId] = [...days.values()].filter(
856
+ (m) => m.size >= EASY_MIN_MODELS && [...m.values()].every(Boolean),
857
+ ).length;
858
+ return rounds;
783
859
  }
784
860
 
785
861
  /**
@@ -788,6 +864,9 @@ export function createRunner(opts: RunnerOptions) {
788
864
  * Returns how many it retired.
789
865
  */
790
866
  async function retireEasy(suiteKey: string): Promise<number> {
867
+ // Regraded first, so every compared case is marked as such (tests
868
+ // graded before the mark existed have none).
869
+ if (suiteOrThrow(suiteKey).gradeTogether) await rescoreRecent(suiteKey);
791
870
  const { easyToRetire } = await answerKeyHealthOf(suiteKey);
792
871
  for (const c of easyToRetire) await store.setCaseStatus(c.id, "RETIRED");
793
872
  if (easyToRetire.length) await rescoreRecent(suiteKey);
@@ -1202,14 +1281,27 @@ export function createRunner(opts: RunnerOptions) {
1202
1281
  a.label.localeCompare(b.label),
1203
1282
  );
1204
1283
  // How each case fared across current, complete tests: easy and split cases.
1205
- const caseResults: Record<string, { passed: number; models: number }> = {};
1284
+ const caseResults: Record<string, CaseResult> = {};
1206
1285
  for (const row of rows) {
1207
1286
  if (row.variant || !row.test || row.test.stale || row.test.failedAnswers)
1208
1287
  continue;
1288
+ // Each model once per case: right only if every repeat was right.
1289
+ const byCase = new Map<string, { right: boolean; ranked: boolean }>();
1209
1290
  for (const x of outputsOf(row.test.runId)) {
1210
- const c = (caseResults[x.caseId] ??= { passed: 0, models: 0 });
1291
+ const had = byCase.get(x.caseId) ?? { right: true, ranked: false };
1292
+ byCase.set(x.caseId, {
1293
+ right: had.right && allPassed(x.checks),
1294
+ // Compared with other cases (a ranking): others' results need it.
1295
+ ranked:
1296
+ had.ranked ||
1297
+ Boolean(x.checks?.some((k) => k.together && k.pass !== null)),
1298
+ });
1299
+ }
1300
+ for (const [caseId, r] of byCase) {
1301
+ const c = (caseResults[caseId] ??= { passed: 0, models: 0 });
1211
1302
  c.models++;
1212
- if (allPassed(x.checks)) c.passed++;
1303
+ if (r.right) c.passed++;
1304
+ if (r.ranked) c.ranked = true;
1213
1305
  }
1214
1306
  }
1215
1307
  return {
@@ -1335,6 +1427,7 @@ export function createRunner(opts: RunnerOptions) {
1335
1427
  rescoreRecent,
1336
1428
  answerKeyHealth: answerKeyHealthOf,
1337
1429
  retireEasy,
1430
+ easyRounds,
1338
1431
  retireStaleDrafts,
1339
1432
  stopStuckRuns,
1340
1433
  compare,
package/src/types.ts CHANGED
@@ -34,6 +34,12 @@ export type CheckResult = {
34
34
  * `brier`, `logLoss`, `confidence`, and `correct` (see decisionCheck).
35
35
  */
36
36
  measures?: Record<string, number> | undefined;
37
+ /**
38
+ * Set by Evalkeeper on checks from a suite's `gradeTogether`: they grade
39
+ * this answer against others (a ranking), so the case matters to other
40
+ * cases' results too, and is never retired as easy.
41
+ */
42
+ together?: boolean | undefined;
37
43
  };
38
44
 
39
45
  /**
@@ -299,6 +305,18 @@ export type Suite<Input, Output, Label> = {
299
305
  * @param answer - The answer being checked, or null without one.
300
306
  */
301
307
  lookAt?(input: Input, answer: Label | null): LookAt[];
308
+ /**
309
+ * One model's answer as a short line, shown beside that model's latest
310
+ * test in the answer key ("“Get a full-time admin job in local
311
+ * government”", or "Left as typed"), so a person can compare what
312
+ * models wrote with the input and the answer. Shown below the answer,
313
+ * so a person reads the answer first. Shown as given: quote the
314
+ * model's own words yourself. For people only.
315
+ *
316
+ * @param output - What the model returned, as stored.
317
+ * @returns The line, or null to show none for this output.
318
+ */
319
+ outputLine?(output: Output): string | null;
302
320
  };
303
321
 
304
322
  /** One thing to look at when checking an answer (`Suite.lookAt`). */
@@ -354,7 +372,11 @@ export type FormField = {
354
372
  kind: "text" | "textarea" | "select" | "lines" | "json";
355
373
  /** For "select". */
356
374
  options?: readonly string[];
357
- /** For "select": how each option reads to a person ("YES" → "Would apply"). */
375
+ /**
376
+ * How each value reads to a person: a choice's options ("YES" → "Would
377
+ * apply"), or "true" and "false" for a yes-or-no field. A JSON field
378
+ * with these is edited as a choice between them.
379
+ */
358
380
  optionLabels?: Readonly<Record<string, string>>;
359
381
  required?: boolean;
360
382
  };