@crowandraven/evalkeeper 0.9.0 → 0.10.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.
@@ -1,6 +1,8 @@
1
1
  import type { Metadata } from "next";
2
2
  import Link from "next/link";
3
3
  import {
4
+ attackMistakes,
5
+ attacksFrom,
4
6
  attention,
5
7
  isInjectionSuite,
6
8
  perAnswer,
@@ -52,8 +54,14 @@ export default async function EvalsHub() {
52
54
  const down = thumbs.reduce((t, s) => t + s.down, 0);
53
55
  const waiting = thumbs.reduce((t, s) => t + s.open, 0);
54
56
  const flagged = thumbs.filter((s) => s.alert).length;
57
+ // An injection suite shows on its base suite's card, not its own.
58
+ const attacksOn = (key: string) =>
59
+ boards.filter((x) => isInjectionSuite(x.suite) && x.suite.base.key === key);
60
+ const cards = boards
61
+ .map((b, i) => ({ b, i }))
62
+ .filter(({ b }) => !isInjectionSuite(b.suite));
55
63
  const needs = attention(
56
- boards.map((b) => ({
64
+ cards.map(({ b }) => ({
57
65
  key: b.suite.key,
58
66
  label: b.suite.label,
59
67
  rows: b.rows,
@@ -124,9 +132,10 @@ export default async function EvalsHub() {
124
132
  Suites
125
133
  <InfoTip term="suites" />
126
134
  </h2>
127
- {boards.length === 0 && <NoSuites />}
135
+ {cards.length === 0 && <NoSuites />}
128
136
  <div className="space-y-4">
129
- {boards.map((b, i) => {
137
+ {cards.map(({ b, i }) => {
138
+ const attacked = attacksOn(b.suite.key);
130
139
  const h = suiteHealth(
131
140
  b.rows,
132
141
  b.suite.checks,
@@ -134,12 +143,14 @@ export default async function EvalsHub() {
134
143
  b.cases,
135
144
  b.provisional,
136
145
  MODELS,
146
+ { attacks: attacksFrom(attacked) },
137
147
  );
138
148
  const [history, current] = histories[i] ?? [[], null];
139
149
  return (
140
150
  <SuiteCard
141
151
  key={b.suite.key}
142
152
  board={b}
153
+ attacked={attacked}
143
154
  health={h}
144
155
  history={history}
145
156
  current={current}
@@ -224,16 +235,19 @@ const scoreTone = (rate: number) =>
224
235
 
225
236
  /**
226
237
  * One feature on the hub: its live version and models, what the live
227
- * model costs and how fast it is, its latest test, what needs a look, and
228
- * its settings history.
238
+ * model costs and how fast it is, its latest test, how it does under
239
+ * attack, what needs a look, and its settings history.
229
240
  */
230
241
  function SuiteCard({
231
242
  board: b,
243
+ attacked,
232
244
  health: h,
233
245
  history,
234
246
  current,
235
247
  }: {
236
248
  board: Board;
249
+ /** The injection suites that attack this feature. */
250
+ attacked: Board[];
237
251
  health: ReturnType<typeof suiteHealth>;
238
252
  history: HistoryEntry[];
239
253
  current: { settings: Settings; version: SettingsVersion | null } | null;
@@ -328,39 +342,57 @@ function SuiteCard({
328
342
  </ul>
329
343
  )}
330
344
 
331
- {isInjectionSuite(b.suite) ? (
332
- <p className="readable text-sm text-muted">
333
- Shares {b.suite.base.label}&apos;s settings and versions history.
334
- </p>
335
- ) : (
336
- s && (
337
- <details className="group/history relative rounded-md bg-tint">
338
- <summary className="flex list-none items-center justify-between gap-2 p-3 text-sm font-medium">
339
- Versions
340
- <span className="flex items-center gap-1 text-xs font-normal text-muted">
341
- <span className="font-medium text-ink">
342
- v{version?.number ?? 1}
343
- </span>{" "}
344
- {since ? `live since ${day(since)}` : "defaults from code"} ·{" "}
345
- {versions} version{versions === 1 ? "" : "s"}
346
- <ChevronDown
347
- aria-hidden
348
- className="h-4 w-4 transition-transform group-open/history:rotate-180"
349
- />
345
+ {attacked.map((a) => {
346
+ const n = live ? attackMistakes(live.key, attacksFrom([a])) : null;
347
+ return (
348
+ <p key={a.suite.key} className="relative text-sm">
349
+ Under attack
350
+ <InfoTip term="underAttack" />:{" "}
351
+ {n === null ? (
352
+ <span className="text-muted">live model not tested</span>
353
+ ) : (
354
+ <span className={n ? "font-semibold text-bad" : "text-good"}>
355
+ {n} serious {n === 1 ? "mistake" : "mistakes"}
350
356
  </span>
351
- </summary>
352
- <div className="px-3 pb-3">
353
- <HistoryEntries
354
- suite={b.suite.key}
355
- entries={history}
356
- liveId={version?.id ?? null}
357
- label={label}
358
- defaults={s}
359
- plain
357
+ )}{" "}
358
+ · {a.cases} attack cases ·{" "}
359
+ <Link
360
+ href={evalsPath(a.suite.key)}
361
+ className="text-accent hover:underline"
362
+ >
363
+ {a.suite.label}
364
+ </Link>
365
+ </p>
366
+ );
367
+ })}
368
+
369
+ {s && (
370
+ <details className="group/history relative rounded-md bg-tint">
371
+ <summary className="flex list-none items-center justify-between gap-2 p-3 text-sm font-medium">
372
+ Versions
373
+ <span className="flex items-center gap-1 text-xs font-normal text-muted">
374
+ <span className="font-medium text-ink">
375
+ v{version?.number ?? 1}
376
+ </span>{" "}
377
+ {since ? `live since ${day(since)}` : "defaults from code"} ·{" "}
378
+ {versions} version{versions === 1 ? "" : "s"}
379
+ <ChevronDown
380
+ aria-hidden
381
+ className="h-4 w-4 transition-transform group-open/history:rotate-180"
360
382
  />
361
- </div>
362
- </details>
363
- )
383
+ </span>
384
+ </summary>
385
+ <div className="px-3 pb-3">
386
+ <HistoryEntries
387
+ suite={b.suite.key}
388
+ entries={history}
389
+ liveId={version?.id ?? null}
390
+ label={label}
391
+ defaults={s}
392
+ plain
393
+ />
394
+ </div>
395
+ </details>
364
396
  )}
365
397
  </Card>
366
398
  );
@@ -12,8 +12,8 @@ import {
12
12
  } from "@crowandraven/evalkeeper";
13
13
  import { addCase, editAnswer, retireCase } from "@/lib/evalkeeper/actions";
14
14
  import { Check, ChevronRight, CircleAlert, X } from "lucide-react";
15
- import { store } from "@/lib/evalkeeper";
16
- import { FieldValues, Fields } from "./Fields";
15
+ import { answerEditors, store } from "@/lib/evalkeeper";
16
+ import { AnswerInput, FieldValues, Fields } from "./Fields";
17
17
  import { AddCaseHeader } from "./AddCase";
18
18
  import { CaseMenu } from "./CaseMenu";
19
19
  import { ConfirmAnswer } from "./ConfirmAnswer";
@@ -85,14 +85,18 @@ export async function AnswerKey({
85
85
  tools={tools}
86
86
  form={
87
87
  fields &&
88
- suite.labelFromForm && (
88
+ (suite.labelFromForm || answerEditors[suite.key]) && (
89
89
  <form action={addCase} className="space-y-4">
90
90
  <input type="hidden" name="suite" value={suite.key} />
91
91
  <Fields fields={fields.input} prefix="new-" />
92
92
  <p className="readable text-sm text-muted">
93
93
  What a good answer is. You're writing it, so it's confirmed.
94
94
  </p>
95
- <Fields fields={fields.label} prefix="new-" />
95
+ <AnswerInput
96
+ fields={fields.label}
97
+ editor={answerEditors[suite.key]}
98
+ prefix="new-"
99
+ />
96
100
  <div className="grid gap-4 sm:grid-cols-2">
97
101
  <div className="space-y-1">
98
102
  <label
@@ -348,7 +352,7 @@ function CaseItem({
348
352
  retire={retireCase}
349
353
  startEditing={!answer}
350
354
  editLabel={
351
- suite.fields && suite.labelFromForm
355
+ suite.fields && (suite.labelFromForm || answerEditors[suite.key])
352
356
  ? answer
353
357
  ? "Edit answer"
354
358
  : "Write the answer"
@@ -363,8 +367,10 @@ function CaseItem({
363
367
  >
364
368
  <input type="hidden" name="suite" value={suite.key} />
365
369
  <input type="hidden" name="case" value={c.id} />
366
- <Fields
370
+ <AnswerInput
367
371
  fields={suite.fields.label}
372
+ editor={answerEditors[suite.key]}
373
+ input={c.input}
368
374
  values={answer?.value}
369
375
  prefix={`${c.id}-`}
370
376
  />
@@ -1,4 +1,10 @@
1
- import { asText, fieldValue, type FormField } from "@crowandraven/evalkeeper";
1
+ import {
2
+ ANSWER_JSON_FIELD,
3
+ asText,
4
+ fieldValue,
5
+ type AnswerEditorProps,
6
+ type FormField,
7
+ } from "@crowandraven/evalkeeper";
2
8
  import { InfoTip } from "./Tip";
3
9
 
4
10
  /**
@@ -54,8 +60,9 @@ export function Fields({
54
60
  name={f.name}
55
61
  defaultValue={value}
56
62
  required={f.required}
57
- rows={f.kind === "lines" ? 4 : 5}
58
- className={box}
63
+ rows={f.kind === "lines" ? 4 : f.kind === "json" ? 8 : 5}
64
+ spellCheck={f.kind !== "json"}
65
+ className={`${box} ${f.kind === "json" ? "font-mono text-xs" : ""}`}
59
66
  />
60
67
  )}
61
68
  <p className="readable text-xs text-muted">{f.help}</p>
@@ -87,8 +94,12 @@ export function FieldValues({
87
94
  {f.label}
88
95
  <InfoTip text={f.help} id={`${prefix}${f.name}-read`} />
89
96
  </dt>
90
- <dd className="readable whitespace-pre-wrap">
91
- {Array.isArray(v) ? (
97
+ <dd className="readable break-words whitespace-pre-wrap">
98
+ {f.kind === "json" && v !== undefined && v !== null ? (
99
+ <pre className="text-xs whitespace-pre-wrap">
100
+ {JSON.stringify(v, null, 2)}
101
+ </pre>
102
+ ) : Array.isArray(v) ? (
92
103
  v.length ? (
93
104
  <ul className="list-disc pl-5">
94
105
  {v.map((x, i) => (
@@ -108,3 +119,36 @@ export function FieldValues({
108
119
  </dl>
109
120
  );
110
121
  }
122
+
123
+ /**
124
+ * A suite's answer, for writing or editing it: the app's own answer editor
125
+ * when it registered one for this suite (`answerEditors` in the wiring
126
+ * module), otherwise the suite's answer fields.
127
+ */
128
+ export function AnswerInput({
129
+ fields,
130
+ editor: Editor,
131
+ input = null,
132
+ values,
133
+ prefix = "",
134
+ }: {
135
+ fields: FormField[];
136
+ /** The app's editor for this suite, if any. */
137
+ editor?: React.ComponentType<AnswerEditorProps> | undefined;
138
+ /** The case's input; null on "Add a case". */
139
+ input?: unknown;
140
+ values?: unknown;
141
+ prefix?: string;
142
+ }) {
143
+ if (Editor)
144
+ return (
145
+ <Editor
146
+ name={ANSWER_JSON_FIELD}
147
+ idPrefix={prefix}
148
+ input={input}
149
+ value={values ?? null}
150
+ fields={fields}
151
+ />
152
+ );
153
+ return <Fields fields={fields} values={values} prefix={prefix} />;
154
+ }
@@ -3,6 +3,9 @@
3
3
  import { after } from "next/server";
4
4
  import { revalidatePath } from "next/cache";
5
5
  import {
6
+ answerFromForm,
7
+ attackMistakes,
8
+ attacksFrom,
6
9
  blindRating,
7
10
  caseFromFeedback,
8
11
  formText,
@@ -34,6 +37,21 @@ import { runWeeklyCheck, startWeeklyCheck } from "./weekly";
34
37
  const suiteFrom = (form: FormData) =>
35
38
  runner.suiteOrThrow(formText(form, "suite"));
36
39
 
40
+ /**
41
+ * The suite whose page chooses models: never an injection suite, whose
42
+ * results show on its base suite's page and count in its suggestion.
43
+ */
44
+ function choosingSuite(form: FormData) {
45
+ const suite = suiteFrom(form);
46
+ if (isInjectionSuite(suite))
47
+ throw new Error(`Choose models on ${suite.base.label}`);
48
+ return suite;
49
+ }
50
+
51
+ /** A suite's injection suites, as its suggestion reads them. */
52
+ const attacksOn = async (suiteKey: string) =>
53
+ attacksFrom(await runner.attackBoards(suiteKey));
54
+
37
55
  export async function testModel(form: FormData) {
38
56
  await requireAdmin();
39
57
  const suite = suiteFrom(form);
@@ -103,15 +121,16 @@ const VS: Record<string, string> = {
103
121
 
104
122
  export async function makeLive(form: FormData) {
105
123
  const admin = await requireAdmin();
106
- const suite = suiteFrom(form);
124
+ const suite = choosingSuite(form);
107
125
  const model = formText(form, "model");
108
126
  const { row, evidence } = await evidenceFor(suite.key, model);
127
+ const attacked = attackMistakes(row.key, await attacksOn(suite.key));
109
128
  await settings.update(
110
129
  suite.operation,
111
130
  { model },
112
131
  {
113
132
  by: admin.name,
114
- reason: `Made ${row.label} live: ${evidence.score.right}/${evidence.score.total}, ${VS[row.vsLive ?? ""] ?? "no comparison"}`,
133
+ reason: `Made ${row.label} live: ${evidence.score.right}/${evidence.score.total}, ${VS[row.vsLive ?? ""] ?? "no comparison"}${attacked === null ? "" : `; ${attacked} serious ${attacked === 1 ? "mistake" : "mistakes"} under attack`}`,
115
134
  evidence,
116
135
  },
117
136
  );
@@ -120,7 +139,7 @@ export async function makeLive(form: FormData) {
120
139
 
121
140
  export async function makeFallback(form: FormData) {
122
141
  const admin = await requireAdmin();
123
- const suite = suiteFrom(form);
142
+ const suite = choosingSuite(form);
124
143
  const model = formText(form, "model");
125
144
  const { reason, evidence } = await fallbackEvidence(suite.key, model);
126
145
  await settings.update(
@@ -134,9 +153,14 @@ export async function makeFallback(form: FormData) {
134
153
  /** Applies the suggestion: its live and fallback models, in one change. */
135
154
  export async function useSuggestion(form: FormData) {
136
155
  const admin = await requireAdmin();
137
- const suite = suiteFrom(form);
138
- const board = await runner.board(suite.key);
139
- const s = suggest(board.rows, suite.checks, suite.priority, MODELS);
156
+ const suite = choosingSuite(form);
157
+ const [board, attacks] = await Promise.all([
158
+ runner.board(suite.key),
159
+ attacksOn(suite.key),
160
+ ]);
161
+ const s = suggest(board.rows, suite.checks, suite.priority, MODELS, {
162
+ attacks,
163
+ });
140
164
  if (!s || s.same) return;
141
165
  await settings.update(
142
166
  suite.operation,
@@ -160,7 +184,7 @@ export async function useSuggestion(form: FormData) {
160
184
  /** Makes an earlier version live again; a reason is required. */
161
185
  export async function rollBackSettings(form: FormData) {
162
186
  const admin = await requireAdmin();
163
- const suite = suiteFrom(form);
187
+ const suite = choosingSuite(form);
164
188
  const reason = formText(form, "reason");
165
189
  if (!reason) throw new Error("Say why you're rolling back");
166
190
  await settings.rollBack(suite.operation, formText(form, "version"), {
@@ -193,7 +217,6 @@ export async function rescore(form: FormData) {
193
217
  export async function addCase(form: FormData) {
194
218
  await requireAdmin();
195
219
  const suite = suiteFrom(form);
196
- if (!suite.labelFromForm) throw new Error("This suite has no answer form");
197
220
  const { input, removed } = withoutLeaks(
198
221
  suite,
199
222
  suite.inputFromForm(form),
@@ -215,7 +238,7 @@ export async function addCase(form: FormData) {
215
238
  {
216
239
  kind: "EXPECTED",
217
240
  status: "CONFIRMED",
218
- value: suite.labelFromForm(form),
241
+ value: answerFromForm(suite, form),
219
242
  raterRole: "OWNER",
220
243
  raterId: null,
221
244
  note: null,
@@ -232,14 +255,13 @@ export async function addCase(form: FormData) {
232
255
  export async function editAnswer(form: FormData) {
233
256
  await requireAdmin();
234
257
  const suite = suiteFrom(form);
235
- if (!suite.labelFromForm) throw new Error("This suite has no answer form");
236
258
  const caseId = formText(form, "case");
237
259
  const known = (await store.listCases(suite.key)).some((c) => c.id === caseId);
238
260
  if (!known) throw new Error("Unknown case");
239
261
  await store.addLabel(caseId, {
240
262
  kind: "EXPECTED",
241
263
  status: "CONFIRMED",
242
- value: suite.labelFromForm(form),
264
+ value: answerFromForm(suite, form),
243
265
  raterRole: "OWNER",
244
266
  raterId: null,
245
267
  note: null,
@@ -257,7 +279,7 @@ export async function editAnswer(form: FormData) {
257
279
  */
258
280
  async function caseToRate(form: FormData, raterId: string) {
259
281
  const suite = suiteFrom(form);
260
- if (suite.caseKind !== "imported" || !suite.labelFromForm)
282
+ if (suite.caseKind !== "imported")
261
283
  throw new Error("This suite isn't rated blind");
262
284
  const caseId = formText(form, "case");
263
285
  const c = (await store.listCases(suite.key)).find((x) => x.id === caseId);
@@ -274,12 +296,11 @@ async function caseToRate(form: FormData, raterId: string) {
274
296
  export async function rateBlind(form: FormData) {
275
297
  const admin = await requireAdmin();
276
298
  const { suite, c } = await caseToRate(form, admin.id);
277
- if (!suite.labelFromForm) throw new Error("This suite has no answer form");
278
299
  await store.addLabel(
279
300
  c.id,
280
301
  blindRating({
281
302
  raterId: admin.id,
282
- value: suite.labelFromForm(form),
303
+ value: answerFromForm(suite, form),
283
304
  reason: formText(form, "reason"),
284
305
  }),
285
306
  );