@crowandraven/evalkeeper 0.11.1 → 0.13.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/drafts.d.ts +49 -0
- package/dist/drafts.js +105 -0
- package/dist/drafts.js.map +1 -0
- package/dist/glossary.d.ts +6 -2
- package/dist/glossary.js +6 -2
- package/dist/glossary.js.map +1 -1
- package/dist/health.d.ts +35 -2
- package/dist/health.js +29 -5
- package/dist/health.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/next/actions.js +128 -15
- package/dist/next/actions.js.map +1 -1
- package/dist/next/wiring.d.ts +6 -0
- package/dist/order.d.ts +18 -0
- package/dist/order.js +53 -0
- package/dist/order.js.map +1 -0
- package/dist/prisma/index.d.ts +1 -0
- package/dist/prisma/index.js +3 -0
- package/dist/prisma/index.js.map +1 -1
- package/dist/react/HubSections.d.ts +7 -0
- package/dist/react/HubSections.js +22 -8
- package/dist/react/HubSections.js.map +1 -1
- package/dist/react/ModelMenu.d.ts +18 -4
- package/dist/react/ModelMenu.js +12 -7
- package/dist/react/ModelMenu.js.map +1 -1
- package/dist/react/RateView.js +1 -0
- package/dist/react/RateView.js.map +1 -1
- package/dist/react/SuiteSections.d.ts +31 -0
- package/dist/react/SuiteSections.js +148 -32
- package/dist/react/SuiteSections.js.map +1 -1
- package/dist/react/app.d.ts +18 -0
- package/dist/react/app.js.map +1 -1
- package/dist/react/pieces.d.ts +10 -1
- package/dist/react/pieces.js +50 -0
- package/dist/react/pieces.js.map +1 -1
- package/dist/settings.d.ts +14 -0
- package/dist/settings.js +24 -2
- package/dist/settings.js.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +32 -0
- package/dist/testing.js.map +1 -1
- package/dist/types.d.ts +33 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/schema/evalkeeper.prisma +3 -0
- package/src/drafts.ts +123 -0
- package/src/glossary.ts +10 -2
- package/src/health.ts +53 -6
- package/src/index.ts +2 -0
- package/src/next/actions.ts +162 -16
- package/src/next/wiring.ts +6 -0
- package/src/order.ts +64 -0
- package/src/prisma/index.ts +5 -0
- package/src/react/HubSections.tsx +31 -7
- package/src/react/ModelMenu.tsx +33 -7
- package/src/react/RateView.tsx +1 -0
- package/src/react/SuiteSections.tsx +640 -170
- package/src/react/app.ts +15 -0
- package/src/react/pieces.tsx +62 -1
- package/src/settings.ts +37 -2
- package/src/testing.ts +35 -1
- package/src/types.ts +37 -0
- package/templates/lib/evalkeeper/actions.ts +20 -0
package/src/drafts.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { CaseRecord, EvalStore, NewCase } from "./store.js";
|
|
2
|
+
import type { AnySuite } from "./types.js";
|
|
3
|
+
import { confirmedLabel } from "./labels.js";
|
|
4
|
+
import { nextSplit } from "./quickSet.js";
|
|
5
|
+
import { draftsToTarget } from "./summary.js";
|
|
6
|
+
|
|
7
|
+
/** Where a case a model drafted on request came from. */
|
|
8
|
+
export const MODEL_DRAFT_SOURCE = "MODEL_DRAFT";
|
|
9
|
+
|
|
10
|
+
/** What drafting more cases did. */
|
|
11
|
+
export type DraftMoreResult = {
|
|
12
|
+
/** Cases added, each with a PENDING answer. */
|
|
13
|
+
drafted: number;
|
|
14
|
+
/** Drafts that didn't fit the suite's input or answer, and why. */
|
|
15
|
+
rejected: { problem: string }[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Has the suite's `draftMore` write enough new cases to bring the answer
|
|
20
|
+
* key toward its target size, aimed at what it's missing, with an optional
|
|
21
|
+
* focus from the person asking. Each arrives as a DRAFT case with a
|
|
22
|
+
* PENDING answer, split between DEV and TEST like any new case, and counts
|
|
23
|
+
* only once a person confirms it.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const { drafted } = await draftMoreCases({ store, suite, focus: "longer notes" });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export async function draftMoreCases(opts: {
|
|
31
|
+
store: EvalStore;
|
|
32
|
+
suite: AnySuite;
|
|
33
|
+
/** What to aim the drafts at, in the person's words; null for none. */
|
|
34
|
+
focus: string | null;
|
|
35
|
+
}): Promise<DraftMoreResult> {
|
|
36
|
+
const { store, suite } = opts;
|
|
37
|
+
const result: DraftMoreResult = { drafted: 0, rejected: [] };
|
|
38
|
+
if (!suite.draftMore) return result;
|
|
39
|
+
const all = await store.listCases(suite.key, { includeRetired: true });
|
|
40
|
+
const inUse = all.filter((c) => c.status !== "RETIRED");
|
|
41
|
+
const drafts = await suite.draftMore({
|
|
42
|
+
existing: all.map((c) => ({ input: c.input, tags: c.tags })),
|
|
43
|
+
count: draftsToTarget(inUse.length),
|
|
44
|
+
focus: opts.focus,
|
|
45
|
+
});
|
|
46
|
+
const counts = { DEV: 0, TEST: 0 };
|
|
47
|
+
for (const c of inUse) counts[c.split] += 1;
|
|
48
|
+
for (const d of drafts) {
|
|
49
|
+
const input = suite.input.safeParse(d.input);
|
|
50
|
+
if (!input.success) {
|
|
51
|
+
result.rejected.push({
|
|
52
|
+
problem: `input: ${input.error.issues[0]?.message ?? "invalid"}`,
|
|
53
|
+
});
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const label = suite.labelValue.safeParse(d.label);
|
|
57
|
+
if (!label.success) {
|
|
58
|
+
result.rejected.push({
|
|
59
|
+
problem: `answer: ${label.error.issues[0]?.message ?? "invalid"}`,
|
|
60
|
+
});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const split = nextSplit(counts);
|
|
64
|
+
counts[split] += 1;
|
|
65
|
+
const data: NewCase = {
|
|
66
|
+
suite: suite.key,
|
|
67
|
+
input: input.data,
|
|
68
|
+
tags: d.tags,
|
|
69
|
+
split,
|
|
70
|
+
status: "DRAFT",
|
|
71
|
+
source: MODEL_DRAFT_SOURCE,
|
|
72
|
+
sourceRef: null,
|
|
73
|
+
note: d.note || null,
|
|
74
|
+
labels: [
|
|
75
|
+
{
|
|
76
|
+
kind: "EXPECTED",
|
|
77
|
+
status: "PENDING",
|
|
78
|
+
value: label.data,
|
|
79
|
+
raterRole: "MODEL",
|
|
80
|
+
raterId: null,
|
|
81
|
+
note: "Drafted by a model. Confirm it if it's right.",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
await store.createCase(data);
|
|
86
|
+
result.drafted += 1;
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Cases in use whose only answer is a draft: what testing with drafts
|
|
93
|
+
* would put to use.
|
|
94
|
+
*/
|
|
95
|
+
export function draftAnswers(cases: readonly CaseRecord[]) {
|
|
96
|
+
return cases.flatMap((c) => {
|
|
97
|
+
if (c.status === "RETIRED" || confirmedLabel(c.labels)) return [];
|
|
98
|
+
const pending = c.labels
|
|
99
|
+
.filter((l) => l.status === "PENDING")
|
|
100
|
+
.sort((a, b) => +b.updatedAt - +a.updatedAt)[0];
|
|
101
|
+
return pending ? [{ case: c, label: pending }] : [];
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Puts every draft answer to use before review, so a feature can be
|
|
107
|
+
* tested now: each becomes PROVISIONAL (and its case ACTIVE), and every
|
|
108
|
+
* score resting on one says so until a person confirms it. Returns how
|
|
109
|
+
* many answers it put to use.
|
|
110
|
+
*/
|
|
111
|
+
export async function useDraftsProvisionally(opts: {
|
|
112
|
+
store: EvalStore;
|
|
113
|
+
suite: AnySuite;
|
|
114
|
+
}): Promise<number> {
|
|
115
|
+
const { store, suite } = opts;
|
|
116
|
+
const drafts = draftAnswers(await store.listCases(suite.key));
|
|
117
|
+
for (const d of drafts) {
|
|
118
|
+
await store.setLabelStatus(d.label.id, "PROVISIONAL");
|
|
119
|
+
if (d.case.status === "DRAFT")
|
|
120
|
+
await store.setCaseStatus(d.case.id, "ACTIVE");
|
|
121
|
+
}
|
|
122
|
+
return drafts.length;
|
|
123
|
+
}
|
package/src/glossary.ts
CHANGED
|
@@ -5,10 +5,14 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export const GLOSSARY = {
|
|
7
7
|
score:
|
|
8
|
-
"
|
|
8
|
+
"Accuracy: how much the model got right on every case in use. With partial credit, parts right of parts expected; otherwise answers with every check passed.",
|
|
9
9
|
seriousMistakes:
|
|
10
10
|
"Failed serious checks: mistakes that change what your product does. Models are compared on these first.",
|
|
11
|
-
time: "
|
|
11
|
+
time: "Speed: average seconds per answer, so lower is faster, from answers the model actually made (reused answers keep their original time).",
|
|
12
|
+
favors:
|
|
13
|
+
"What the suggestion weighs once accuracy holds. It never suggests a model with more serious mistakes, and only trades accuracy for a clear gain: accuracy alone, or the same accuracy at half the cost or time.",
|
|
14
|
+
attackFailures:
|
|
15
|
+
"Answers on the attack cases that never came back (an error or a timeout, not a wrong answer). Attacks resisted counts only complete tests: test again.",
|
|
12
16
|
cost: "Average cost per answer on this model, from your catalog's prices.",
|
|
13
17
|
againstLive:
|
|
14
18
|
"A paired comparison with the live model on the same cases: more accurate, about as accurate, less accurate, or too few cases to tell.",
|
|
@@ -24,6 +28,10 @@ export const GLOSSARY = {
|
|
|
24
28
|
minor:
|
|
25
29
|
"A fair difference of judgment. Minor checks should pass 75% of the time unless the check sets its own bar.",
|
|
26
30
|
bar: "The pass rate this check should reach.",
|
|
31
|
+
reasoningSetting:
|
|
32
|
+
"Some models think before answering, and how much is a setting. Less is faster and cheaper; more can be more accurate. Each setting you test gets its own row.",
|
|
33
|
+
checkBreakdown:
|
|
34
|
+
"How often each check passed, for every model with a current test. Serious checks come first; minor ones are fair differences of judgment, so their bar is lower.",
|
|
27
35
|
confirmed: "A person said this answer is right. Tests grade against it.",
|
|
28
36
|
provisional:
|
|
29
37
|
"Put to use before anyone reviewed it. Tests use it, and every score says it rests on unreviewed answers.",
|
package/src/health.ts
CHANGED
|
@@ -2,7 +2,12 @@ import type { BoardRow } from "./board.js";
|
|
|
2
2
|
import { confidenceFor, TARGET_CASES } from "./summary.js";
|
|
3
3
|
import { suggest, type SuggestOptions } from "./suggest.js";
|
|
4
4
|
import type { ModelCatalog } from "./models.js";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
checkBar,
|
|
7
|
+
pctBeside,
|
|
8
|
+
type CheckDef,
|
|
9
|
+
type SuitePriority,
|
|
10
|
+
} from "./types.js";
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Where a suite stands, for its card on the evals hub: one status and the
|
|
@@ -11,13 +16,31 @@ import { checkBar, type CheckDef, type SuitePriority } from "./types.js";
|
|
|
11
16
|
|
|
12
17
|
/** Where a suite stands, from not tested to good. */
|
|
13
18
|
export type HealthStatus =
|
|
14
|
-
"untested" | "stale" | "few" | "improve" | "fair" | "good";
|
|
19
|
+
"untested" | "stale" | "few" | "improve" | "change" | "fair" | "good";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One reason a suite stands where it does, for a chip on its card. A suite
|
|
23
|
+
* can have several: checks under their bar and a suggestion, say.
|
|
24
|
+
*/
|
|
25
|
+
export type HealthFlag =
|
|
26
|
+
| { kind: "untested" }
|
|
27
|
+
| { kind: "stale" }
|
|
28
|
+
| { kind: "below"; serious: number; minor: number }
|
|
29
|
+
| { kind: "suggestLive" }
|
|
30
|
+
| { kind: "suggestFallback" }
|
|
31
|
+
| { kind: "retestLive" }
|
|
32
|
+
| { kind: "provisional"; answers: number }
|
|
33
|
+
| { kind: "fewCases"; cases: number }
|
|
34
|
+
| { kind: "addCases"; cases: number; target: number }
|
|
35
|
+
| { kind: "good" };
|
|
15
36
|
|
|
16
37
|
/**
|
|
17
38
|
* A suite's status for its card, with the live model's score and the reasons, most important first.
|
|
18
39
|
*/
|
|
19
40
|
export type Health = {
|
|
20
41
|
status: HealthStatus;
|
|
42
|
+
/** Each reason behind the status, most important first, for chips. */
|
|
43
|
+
flags: HealthFlag[];
|
|
21
44
|
title: string;
|
|
22
45
|
/** The live model, its score, and how many models were tested. */
|
|
23
46
|
live: { label: string; rate: number } | null;
|
|
@@ -36,7 +59,7 @@ const pct = (x: number) => `${Math.round(x * 100)}%`;
|
|
|
36
59
|
* ```ts
|
|
37
60
|
* const board = await runner.board("ticket_triage");
|
|
38
61
|
* const h = suiteHealth(board.rows, suite.checks, suite.priority, board.cases, board.provisional, MODELS);
|
|
39
|
-
* // h.status: "good" | "fair" | "improve" | "few" | "stale" | "untested"
|
|
62
|
+
* // h.status: "good" | "fair" | "change" | "improve" | "few" | "stale" | "untested"
|
|
40
63
|
* ```
|
|
41
64
|
*/
|
|
42
65
|
export function suiteHealth(
|
|
@@ -65,6 +88,7 @@ export function suiteHealth(
|
|
|
65
88
|
return {
|
|
66
89
|
...base,
|
|
67
90
|
status: "untested",
|
|
91
|
+
flags: [{ kind: "untested" }],
|
|
68
92
|
title: "Not tested yet",
|
|
69
93
|
details: [
|
|
70
94
|
`Test the models to see how ${liveRow?.label ?? "the live model"} does.`,
|
|
@@ -74,6 +98,7 @@ export function suiteHealth(
|
|
|
74
98
|
return {
|
|
75
99
|
...base,
|
|
76
100
|
status: "stale",
|
|
101
|
+
flags: [{ kind: "stale" }],
|
|
77
102
|
title: "Test again",
|
|
78
103
|
details: ["Cases, answers, or instructions changed since the last test."],
|
|
79
104
|
};
|
|
@@ -97,7 +122,7 @@ export function suiteHealth(
|
|
|
97
122
|
);
|
|
98
123
|
for (const { c, rate } of below.slice(0, 3))
|
|
99
124
|
details.push(
|
|
100
|
-
`${c.label}: ${
|
|
125
|
+
`${c.label}: ${pctBeside(rate, checkBar(c))}, under the ${pct(checkBar(c))} bar${c.severity === "serious" ? " (serious)" : ""}.`,
|
|
101
126
|
);
|
|
102
127
|
if (below.length > 3) details.push(`${below.length - 3} more under the bar.`);
|
|
103
128
|
|
|
@@ -115,21 +140,41 @@ export function suiteHealth(
|
|
|
115
140
|
details.push("Only one model tested: test others to compare.");
|
|
116
141
|
|
|
117
142
|
const confidence = confidenceFor(cases, live?.rate ?? 0.5);
|
|
143
|
+
const serious = below.filter((x) => x.c.severity === "serious").length;
|
|
144
|
+
const flags: HealthFlag[] = [];
|
|
145
|
+
if (below.length)
|
|
146
|
+
flags.push({ kind: "below", serious, minor: below.length - serious });
|
|
147
|
+
if (change)
|
|
148
|
+
flags.push(
|
|
149
|
+
s.retestLive
|
|
150
|
+
? { kind: "retestLive" }
|
|
151
|
+
: s.keepLive
|
|
152
|
+
? { kind: "suggestFallback" }
|
|
153
|
+
: { kind: "suggestLive" },
|
|
154
|
+
);
|
|
155
|
+
if (provisional) flags.push({ kind: "provisional", answers: provisional });
|
|
156
|
+
if (confidence.level === "too-few") flags.push({ kind: "fewCases", cases });
|
|
157
|
+
else if (cases < TARGET_CASES)
|
|
158
|
+
flags.push({ kind: "addCases", cases, target: TARGET_CASES });
|
|
118
159
|
if (confidence.level === "too-few")
|
|
119
160
|
return {
|
|
120
161
|
...base,
|
|
121
162
|
status: "few",
|
|
163
|
+
flags,
|
|
122
164
|
title: "Too few cases to trust",
|
|
123
165
|
details: [
|
|
124
166
|
`${fewer}: a score could be off by about ${confidence.margin} points.`,
|
|
125
167
|
...details,
|
|
126
168
|
],
|
|
127
169
|
};
|
|
170
|
+
// Checks under their bar need work; a better choice alone is only a
|
|
171
|
+
// suggestion, even when the live model meets every bar.
|
|
128
172
|
if (below.length || change)
|
|
129
173
|
return {
|
|
130
174
|
...base,
|
|
131
|
-
status: "improve",
|
|
132
|
-
|
|
175
|
+
status: below.length ? "improve" : "change",
|
|
176
|
+
flags,
|
|
177
|
+
title: below.length ? "Room to improve" : "Change suggested",
|
|
133
178
|
details: fewer
|
|
134
179
|
? [...details, `${fewer}: add more to firm it up.`]
|
|
135
180
|
: details,
|
|
@@ -138,6 +183,7 @@ export function suiteHealth(
|
|
|
138
183
|
return {
|
|
139
184
|
...base,
|
|
140
185
|
status: "fair",
|
|
186
|
+
flags,
|
|
141
187
|
title: "Good so far",
|
|
142
188
|
details: [
|
|
143
189
|
`Meets every bar, but with ${fewer} a score could be off by about ${confidence.margin} points.`,
|
|
@@ -147,6 +193,7 @@ export function suiteHealth(
|
|
|
147
193
|
return {
|
|
148
194
|
...base,
|
|
149
195
|
status: "good",
|
|
196
|
+
flags: flags.length ? flags : [{ kind: "good" }],
|
|
150
197
|
title: "In good shape",
|
|
151
198
|
details: details.length ? details : ["Meets every bar on enough cases."],
|
|
152
199
|
};
|
package/src/index.ts
CHANGED
package/src/next/actions.ts
CHANGED
|
@@ -6,15 +6,21 @@ import {
|
|
|
6
6
|
attacksFrom,
|
|
7
7
|
blindRating,
|
|
8
8
|
caseFromFeedback,
|
|
9
|
+
draftMoreCases,
|
|
9
10
|
formText,
|
|
11
|
+
importStarters,
|
|
10
12
|
isInjectionSuite,
|
|
11
13
|
leakNote,
|
|
12
14
|
raterStatus,
|
|
13
15
|
skipMark,
|
|
14
16
|
suggest,
|
|
17
|
+
useDraftsProvisionally,
|
|
15
18
|
withoutLeaks,
|
|
19
|
+
priorityOf,
|
|
20
|
+
type ReasoningEffort,
|
|
16
21
|
} from "../index.js";
|
|
17
22
|
import { evalsPath, type EvalActions } from "../react/app.js";
|
|
23
|
+
import { injectionCases } from "../suites/injection.js";
|
|
18
24
|
import { weeklyCheck } from "./weekly.js";
|
|
19
25
|
import type { EvalWiring } from "./wiring.js";
|
|
20
26
|
|
|
@@ -45,6 +51,10 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
|
|
|
45
51
|
};
|
|
46
52
|
const weekly = weeklyCheck(w);
|
|
47
53
|
|
|
54
|
+
/** Who a settings change records: the admin's name, or their id. */
|
|
55
|
+
const changer = (admin: { id: string; name: string }) =>
|
|
56
|
+
w.changedBy === "id" ? admin.id : admin.name;
|
|
57
|
+
|
|
48
58
|
const suiteFrom = (form: FormData) =>
|
|
49
59
|
runner.suiteOrThrow(formText(form, "suite"));
|
|
50
60
|
|
|
@@ -83,7 +93,7 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
|
|
|
83
93
|
*/
|
|
84
94
|
async function caseToRate(form: FormData, raterId: string) {
|
|
85
95
|
const suite = suiteFrom(form);
|
|
86
|
-
if (suite.caseKind !== "imported")
|
|
96
|
+
if (suite.caseKind !== "imported" || suite.rateBlind === false)
|
|
87
97
|
throw new Error("This suite isn't rated blind");
|
|
88
98
|
const c = await knownCase(suite.key, form);
|
|
89
99
|
if (raterStatus(c, raterId))
|
|
@@ -92,14 +102,65 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
|
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
/** The current test of a model's row, for choosing it live or fallback. */
|
|
95
|
-
|
|
105
|
+
/**
|
|
106
|
+
* A model's row: at the feature's own setting, or with `effort` at
|
|
107
|
+
* another ("default": the model's own default).
|
|
108
|
+
*/
|
|
109
|
+
async function rowOf(suiteKey: string, model: string, effort?: string) {
|
|
96
110
|
const board = await runner.board(suiteKey);
|
|
111
|
+
const wanted = effort === "default" ? null : effort;
|
|
97
112
|
return {
|
|
98
113
|
board,
|
|
99
|
-
row: board.rows.find((r) =>
|
|
114
|
+
row: board.rows.find((r) =>
|
|
115
|
+
effort === undefined
|
|
116
|
+
? r.model === model && !r.variant
|
|
117
|
+
: r.model === model && r.variant && r.effort === wanted,
|
|
118
|
+
),
|
|
100
119
|
};
|
|
101
120
|
}
|
|
102
121
|
|
|
122
|
+
/**
|
|
123
|
+
* The model and reasoning setting a Test form asks for: `setting` (a
|
|
124
|
+
* model and setting together, from one dropdown) or `model` with an
|
|
125
|
+
* optional `effort`. No setting: the feature's own. "default": the
|
|
126
|
+
* model's own default, sending none. Any other must be one the catalog
|
|
127
|
+
* lists for the model.
|
|
128
|
+
*/
|
|
129
|
+
function testRequest(
|
|
130
|
+
form: FormData,
|
|
131
|
+
operation: string,
|
|
132
|
+
): { model: string; reasoningEffort?: ReasoningEffort | null } {
|
|
133
|
+
let model: string;
|
|
134
|
+
let effort: string | undefined;
|
|
135
|
+
const setting = form.get("setting");
|
|
136
|
+
if (typeof setting === "string" && setting) {
|
|
137
|
+
let parsed: unknown;
|
|
138
|
+
try {
|
|
139
|
+
parsed = JSON.parse(setting);
|
|
140
|
+
} catch {
|
|
141
|
+
throw new Error("Unknown setting");
|
|
142
|
+
}
|
|
143
|
+
if (
|
|
144
|
+
!Array.isArray(parsed) ||
|
|
145
|
+
parsed.length !== 2 ||
|
|
146
|
+
!parsed.every((x) => typeof x === "string")
|
|
147
|
+
)
|
|
148
|
+
throw new Error("Unknown setting");
|
|
149
|
+
[model, effort] = parsed as [string, string];
|
|
150
|
+
} else {
|
|
151
|
+
model = formText(form, "model");
|
|
152
|
+
const e = form.get("effort");
|
|
153
|
+
effort = typeof e === "string" && e ? e : undefined;
|
|
154
|
+
}
|
|
155
|
+
if (!runner.modelsFor(operation).includes(model))
|
|
156
|
+
throw new Error("Unknown model");
|
|
157
|
+
if (effort === undefined) return { model };
|
|
158
|
+
if (effort === "default") return { model, reasoningEffort: null };
|
|
159
|
+
if (!w.models[model]?.efforts?.includes(effort))
|
|
160
|
+
throw new Error(`${model} doesn't take ${effort} reasoning`);
|
|
161
|
+
return { model, reasoningEffort: effort };
|
|
162
|
+
}
|
|
163
|
+
|
|
103
164
|
async function feedbackById(id: string) {
|
|
104
165
|
const f = (await feedbackStore.listFeedback()).find((x) => x.id === id);
|
|
105
166
|
if (!f) throw new Error("Unknown rating");
|
|
@@ -110,11 +171,12 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
|
|
|
110
171
|
async testModel(form) {
|
|
111
172
|
await w.requireAdmin();
|
|
112
173
|
const suite = suiteFrom(form);
|
|
113
|
-
const
|
|
114
|
-
if (!runner.modelsFor(suite.operation).includes(model))
|
|
115
|
-
throw new Error("Unknown model");
|
|
174
|
+
const request = testRequest(form, suite.operation);
|
|
116
175
|
// The feature's cases and its attack cases, in one test.
|
|
117
|
-
const { runs } = await runner.createTest({
|
|
176
|
+
const { runs } = await runner.createTest({
|
|
177
|
+
suite: suite.key,
|
|
178
|
+
...request,
|
|
179
|
+
});
|
|
118
180
|
after(() => runAll(runs));
|
|
119
181
|
revalidatePath(page(suite.key));
|
|
120
182
|
},
|
|
@@ -132,16 +194,24 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
|
|
|
132
194
|
async makeLive(form) {
|
|
133
195
|
const admin = await w.requireAdmin();
|
|
134
196
|
const suite = choosingSuite(form);
|
|
135
|
-
const
|
|
197
|
+
const effort = form.get("effort");
|
|
198
|
+
const { board, row } = await rowOf(
|
|
199
|
+
suite.key,
|
|
200
|
+
formText(form, "model"),
|
|
201
|
+
typeof effort === "string" && effort ? effort : undefined,
|
|
202
|
+
);
|
|
136
203
|
if (!row?.test || row.test.stale)
|
|
137
204
|
throw new Error("Test this model on the current cases first");
|
|
138
205
|
const score = { right: row.test.right, total: row.test.total };
|
|
139
206
|
const attacked = attackMistakes(row.key, await attacksOn(suite.key));
|
|
140
207
|
await settings.update(
|
|
141
208
|
suite.operation,
|
|
142
|
-
|
|
209
|
+
// A row at another setting goes live at that setting.
|
|
210
|
+
row.variant
|
|
211
|
+
? { model: row.model, reasoningEffort: row.effort }
|
|
212
|
+
: { model: row.model },
|
|
143
213
|
{
|
|
144
|
-
by: admin
|
|
214
|
+
by: changer(admin),
|
|
145
215
|
reason: `Made ${row.label} live: ${score.right}/${score.total}, ${VS[row.vsLive ?? ""] ?? "no comparison"}${attacked === null ? "" : `; ${attacked} serious ${attacked === 1 ? "mistake" : "mistakes"} under attack`}`,
|
|
146
216
|
// The evidence, so the history can show why.
|
|
147
217
|
evidence: {
|
|
@@ -169,7 +239,7 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
|
|
|
169
239
|
suite.operation,
|
|
170
240
|
{ fallbackModel: row.model },
|
|
171
241
|
{
|
|
172
|
-
by: admin
|
|
242
|
+
by: changer(admin),
|
|
173
243
|
reason: `Made ${row.label} the fallback: ${test ? `${Math.round(test.right)}/${Math.round(test.total)}${failed}` : "not tested"}`,
|
|
174
244
|
evidence: {
|
|
175
245
|
runId: test?.runId ?? null,
|
|
@@ -189,15 +259,22 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
|
|
|
189
259
|
runner.board(suite.key),
|
|
190
260
|
attacksOn(suite.key),
|
|
191
261
|
]);
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
262
|
+
const { settings: live } = await settings.current(suite.operation);
|
|
263
|
+
const s = suggest(
|
|
264
|
+
board.rows,
|
|
265
|
+
suite.checks,
|
|
266
|
+
priorityOf(suite, live),
|
|
267
|
+
w.models,
|
|
268
|
+
{
|
|
269
|
+
attacks,
|
|
270
|
+
},
|
|
271
|
+
);
|
|
195
272
|
if (!s || s.same) return;
|
|
196
273
|
await settings.update(
|
|
197
274
|
suite.operation,
|
|
198
275
|
{ model: s.live.model, fallbackModel: s.fallback?.model ?? null },
|
|
199
276
|
{
|
|
200
|
-
by: admin
|
|
277
|
+
by: changer(admin),
|
|
201
278
|
reason: s.reasons.join(" "),
|
|
202
279
|
evidence: {
|
|
203
280
|
suggestion: s.reasons,
|
|
@@ -216,7 +293,7 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
|
|
|
216
293
|
const reason = formText(form, "reason");
|
|
217
294
|
if (!reason) throw new Error("Say why you're rolling back");
|
|
218
295
|
await settings.rollBack(suite.operation, formText(form, "version"), {
|
|
219
|
-
by: admin
|
|
296
|
+
by: changer(admin),
|
|
220
297
|
reason,
|
|
221
298
|
});
|
|
222
299
|
everyPage();
|
|
@@ -327,6 +404,75 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
|
|
|
327
404
|
revalidatePath(page(suite.key));
|
|
328
405
|
},
|
|
329
406
|
|
|
407
|
+
async addStarters(form) {
|
|
408
|
+
await w.requireAdmin();
|
|
409
|
+
const suite = suiteFrom(form);
|
|
410
|
+
await importStarters(store, suite);
|
|
411
|
+
revalidatePath(page(suite.key));
|
|
412
|
+
},
|
|
413
|
+
|
|
414
|
+
async makeAttackCases(form) {
|
|
415
|
+
await w.requireAdmin();
|
|
416
|
+
const suite = suiteFrom(form);
|
|
417
|
+
if (!isInjectionSuite(suite))
|
|
418
|
+
throw new Error("This suite has no attacks");
|
|
419
|
+
const r = await injectionCases(
|
|
420
|
+
store,
|
|
421
|
+
// Trust boundary: isInjectionSuite means injectionSuite made it.
|
|
422
|
+
suite as unknown as Parameters<typeof injectionCases>[1],
|
|
423
|
+
);
|
|
424
|
+
if (!r.baseCases)
|
|
425
|
+
throw new Error(
|
|
426
|
+
`Confirm some ${suite.base.label} answers first: attack cases copy them`,
|
|
427
|
+
);
|
|
428
|
+
everyPage();
|
|
429
|
+
},
|
|
430
|
+
|
|
431
|
+
async draftMore(form) {
|
|
432
|
+
await w.requireAdmin();
|
|
433
|
+
const suite = suiteFrom(form);
|
|
434
|
+
if (!suite.draftMore) throw new Error("This suite can't draft cases");
|
|
435
|
+
const focus = form.get("focus");
|
|
436
|
+
await draftMoreCases({
|
|
437
|
+
store,
|
|
438
|
+
suite,
|
|
439
|
+
focus:
|
|
440
|
+
typeof focus === "string" && focus.trim()
|
|
441
|
+
? focus.trim().slice(0, 500)
|
|
442
|
+
: null,
|
|
443
|
+
});
|
|
444
|
+
revalidatePath(page(suite.key));
|
|
445
|
+
},
|
|
446
|
+
|
|
447
|
+
async setPriority(form) {
|
|
448
|
+
const admin = await w.requireAdmin();
|
|
449
|
+
const suite = choosingSuite(form);
|
|
450
|
+
const favor = formText(form, "favor");
|
|
451
|
+
if (favor !== "quality" && favor !== "speed" && favor !== "cost")
|
|
452
|
+
throw new Error("Pick accuracy, speed, or cost");
|
|
453
|
+
const reason = form.get("reason");
|
|
454
|
+
await settings.update(
|
|
455
|
+
suite.operation,
|
|
456
|
+
// The suite's own priority needs no override.
|
|
457
|
+
{ favor: favor === suite.priority.favor ? null : favor },
|
|
458
|
+
{
|
|
459
|
+
by: changer(admin),
|
|
460
|
+
reason:
|
|
461
|
+
typeof reason === "string" && reason.trim()
|
|
462
|
+
? reason.trim().slice(0, 300)
|
|
463
|
+
: `Favors ${favor === "quality" ? "accuracy" : favor}`,
|
|
464
|
+
},
|
|
465
|
+
);
|
|
466
|
+
everyPage();
|
|
467
|
+
},
|
|
468
|
+
|
|
469
|
+
async useDraftsProvisionally(form) {
|
|
470
|
+
await w.requireAdmin();
|
|
471
|
+
const suite = suiteFrom(form);
|
|
472
|
+
await useDraftsProvisionally({ store, suite });
|
|
473
|
+
everyPage();
|
|
474
|
+
},
|
|
475
|
+
|
|
330
476
|
/**
|
|
331
477
|
* A person rates an imported case blind: their own confirmed answer,
|
|
332
478
|
* with their reason, added beside anyone else's. Tests are rescored
|
package/src/next/wiring.ts
CHANGED
|
@@ -15,4 +15,10 @@ export type EvalWiring = Omit<EvalApp, "actions"> & {
|
|
|
15
15
|
* is recorded as who made each change.
|
|
16
16
|
*/
|
|
17
17
|
requireAdmin: () => Promise<EvalAdmin>;
|
|
18
|
+
/**
|
|
19
|
+
* What the settings history records as who made a change: the admin's
|
|
20
|
+
* `name` (the default) or `id`. Use "id" when your settings store keeps
|
|
21
|
+
* a user id there (a foreign key) and shows names from it.
|
|
22
|
+
*/
|
|
23
|
+
changedBy?: "name" | "id";
|
|
18
24
|
};
|
package/src/order.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { BoardRow } from "./board.js";
|
|
2
|
+
import type { CheckDef, SuitePriority } from "./types.js";
|
|
3
|
+
import { seriousMistakes } from "./suggest.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A board's rows in the order the suggestion weighs them: the suggested
|
|
7
|
+
* live model first, then the live one, then models with a current test by
|
|
8
|
+
* fewest serious mistakes, highest accuracy, and the suite's priority
|
|
9
|
+
* (lower cost or time), then the rest. Accuracy is never traded away by
|
|
10
|
+
* this order: cost and speed only break ties. Pure.
|
|
11
|
+
*/
|
|
12
|
+
export function orderRows<R extends BoardRow>(
|
|
13
|
+
rows: readonly R[],
|
|
14
|
+
checks: CheckDef[],
|
|
15
|
+
priority: SuitePriority,
|
|
16
|
+
suggested: { live: string | null } = { live: null },
|
|
17
|
+
): R[] {
|
|
18
|
+
const current = (r: R) => !!r.test && !r.test.stale;
|
|
19
|
+
const accuracy = (r: R) => (r.test?.total ? r.test.right / r.test.total : 0);
|
|
20
|
+
const favored = (r: R) =>
|
|
21
|
+
priority.favor === "cost"
|
|
22
|
+
? (r.test?.costPerAnswer ?? Infinity)
|
|
23
|
+
: priority.favor === "speed"
|
|
24
|
+
? (r.test?.avgMs ?? Infinity)
|
|
25
|
+
: 0;
|
|
26
|
+
const rank = (r: R): number[] => [
|
|
27
|
+
r.key === suggested.live ? 0 : 1,
|
|
28
|
+
r.live ? 0 : 1,
|
|
29
|
+
current(r) ? 0 : 1,
|
|
30
|
+
current(r) ? seriousMistakes(r, checks) : 0,
|
|
31
|
+
-accuracy(r),
|
|
32
|
+
favored(r),
|
|
33
|
+
];
|
|
34
|
+
return [...rows].sort((a, b) => {
|
|
35
|
+
const x = rank(a);
|
|
36
|
+
const y = rank(b);
|
|
37
|
+
for (let i = 0; i < x.length; i++)
|
|
38
|
+
if (x[i] !== y[i]) return (x[i] ?? 0) - (y[i] ?? 0);
|
|
39
|
+
return 0;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* What a model gains on the suite's priority over the live one, when
|
|
45
|
+
* it's about as accurate: "4× cheaper", "2.5× faster". Null under 1.5×,
|
|
46
|
+
* or when the suite favors accuracy. Pure.
|
|
47
|
+
*/
|
|
48
|
+
export function priorityGain(
|
|
49
|
+
row: BoardRow,
|
|
50
|
+
live: BoardRow | undefined,
|
|
51
|
+
priority: SuitePriority,
|
|
52
|
+
): string | null {
|
|
53
|
+
if (!row.test || !live?.test || priority.favor === "quality") return null;
|
|
54
|
+
const [mine, theirs, word] =
|
|
55
|
+
priority.favor === "cost"
|
|
56
|
+
? [row.test.costPerAnswer, live.test.costPerAnswer, "cheaper"]
|
|
57
|
+
: [row.test.avgMs, live.test.avgMs, "faster"];
|
|
58
|
+
if (mine === null || theirs === null || !(mine > 0) || !(theirs > 0))
|
|
59
|
+
return null;
|
|
60
|
+
const ratio = theirs / mine;
|
|
61
|
+
if (ratio < 1.5) return null;
|
|
62
|
+
const shown = ratio >= 10 ? Math.round(ratio) : Math.round(ratio * 10) / 10;
|
|
63
|
+
return `${shown}× ${word}`;
|
|
64
|
+
}
|
package/src/prisma/index.ts
CHANGED
|
@@ -863,6 +863,7 @@ export type EvalSettingsVersionRow = {
|
|
|
863
863
|
reasoningEffort: string | null;
|
|
864
864
|
maxOutputTokens: number | null;
|
|
865
865
|
temperature: number | null;
|
|
866
|
+
favor?: string | null;
|
|
866
867
|
promptVersion: string | null;
|
|
867
868
|
createdAt: Date;
|
|
868
869
|
};
|
|
@@ -921,10 +922,14 @@ const version = (v: Row): SettingsVersion => ({
|
|
|
921
922
|
reasoningEffort: strOrNull(v.reasoningEffort),
|
|
922
923
|
maxOutputTokens: numOrNull(v.maxOutputTokens),
|
|
923
924
|
temperature: numOrNull(v.temperature),
|
|
925
|
+
// An unknown or missing value reads as the suite's own priority.
|
|
926
|
+
favor: FAVORS.find((f) => f === v.favor) ?? null,
|
|
924
927
|
promptVersion: strOrNull(v.promptVersion),
|
|
925
928
|
createdAt: date(v.createdAt),
|
|
926
929
|
});
|
|
927
930
|
|
|
931
|
+
const FAVORS = ["speed", "cost", "quality"] as const;
|
|
932
|
+
|
|
928
933
|
const settingsChange = (c: Row, by: string | null): SettingsChange => ({
|
|
929
934
|
id: str(c.id),
|
|
930
935
|
operation: str(c.operation),
|