@crowandraven/evalkeeper 0.5.0 → 0.8.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/README.md +16 -0
- package/dist/activity.d.ts +58 -0
- package/dist/activity.js +125 -0
- package/dist/activity.js.map +1 -0
- package/dist/assertExpect.d.ts +52 -0
- package/dist/assertExpect.js +104 -0
- package/dist/assertExpect.js.map +1 -0
- package/dist/blind.d.ts +79 -0
- package/dist/blind.js +113 -0
- package/dist/blind.js.map +1 -0
- package/dist/cli/addPages.d.ts +6 -1
- package/dist/cli/addPages.js +19 -4
- package/dist/cli/addPages.js.map +1 -1
- package/dist/cli/main.d.ts +1 -1
- package/dist/cli/main.js +4 -3
- package/dist/cli/main.js.map +1 -1
- package/dist/compare.d.ts +38 -0
- package/dist/compare.js +62 -0
- package/dist/compare.js.map +1 -1
- package/dist/decisions.js +8 -0
- package/dist/decisions.js.map +1 -1
- package/dist/feedback.d.ts +17 -2
- package/dist/feedback.js +13 -2
- package/dist/feedback.js.map +1 -1
- package/dist/glossary.d.ts +22 -0
- package/dist/glossary.js +22 -0
- package/dist/glossary.js.map +1 -1
- package/dist/health.js +5 -3
- package/dist/health.js.map +1 -1
- package/dist/importCases.d.ts +76 -5
- package/dist/importCases.js +114 -14
- package/dist/importCases.js.map +1 -1
- package/dist/inInstructions.d.ts +47 -0
- package/dist/inInstructions.js +95 -0
- package/dist/inInstructions.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/memoryStore.js +3 -1
- package/dist/memoryStore.js.map +1 -1
- package/dist/readCheck.d.ts +116 -0
- package/dist/readCheck.js +321 -0
- package/dist/readCheck.js.map +1 -0
- package/dist/runner.d.ts +16 -0
- package/dist/runner.js +51 -3
- package/dist/runner.js.map +1 -1
- package/dist/settings.d.ts +81 -3
- package/dist/settings.js +160 -23
- package/dist/settings.js.map +1 -1
- package/dist/store.d.ts +10 -3
- package/dist/suggest.d.ts +10 -1
- package/dist/suggest.js +22 -4
- package/dist/suggest.js.map +1 -1
- package/dist/suiteContract.d.ts +23 -0
- package/dist/suiteContract.js +106 -0
- package/dist/suiteContract.js.map +1 -0
- package/dist/suites/crisisRisk.d.ts +83 -0
- package/dist/suites/crisisRisk.js +176 -0
- package/dist/suites/crisisRisk.js.map +1 -0
- package/dist/suites/crisisRiskCases.d.ts +40 -0
- package/dist/suites/crisisRiskCases.js +179 -0
- package/dist/suites/crisisRiskCases.js.map +1 -0
- package/dist/suites/hopelessness.d.ts +116 -0
- package/dist/suites/hopelessness.js +293 -0
- package/dist/suites/hopelessness.js.map +1 -0
- package/dist/suites/hopelessnessCases.d.ts +61 -0
- package/dist/suites/hopelessnessCases.js +242 -0
- package/dist/suites/hopelessnessCases.js.map +1 -0
- package/dist/suites/index.d.ts +11 -0
- package/dist/suites/index.js +12 -0
- package/dist/suites/index.js.map +1 -0
- package/dist/testing.d.ts +162 -12
- package/dist/testing.js +479 -115
- package/dist/testing.js.map +1 -1
- package/dist/types.d.ts +98 -0
- package/dist/types.js +68 -0
- package/dist/types.js.map +1 -1
- package/dist/weekly.d.ts +21 -3
- package/dist/weekly.js +18 -1
- package/dist/weekly.js.map +1 -1
- package/package.json +5 -1
- package/src/activity.ts +154 -0
- package/src/assertExpect.ts +168 -0
- package/src/blind.ts +138 -0
- package/src/cli/addPages.ts +20 -4
- package/src/cli/main.ts +4 -3
- package/src/compare.ts +85 -0
- package/src/decisions.ts +10 -0
- package/src/feedback.ts +20 -2
- package/src/glossary.ts +40 -0
- package/src/health.ts +5 -3
- package/src/importCases.ts +172 -33
- package/src/inInstructions.ts +105 -0
- package/src/index.ts +5 -0
- package/src/memoryStore.ts +2 -1
- package/src/readCheck.ts +458 -0
- package/src/runner.ts +74 -4
- package/src/settings.ts +192 -26
- package/src/store.ts +11 -3
- package/src/suggest.ts +33 -4
- package/src/suiteContract.ts +147 -0
- package/src/suites/crisisRisk.ts +250 -0
- package/src/suites/crisisRiskCases.ts +205 -0
- package/src/suites/hopelessness.ts +410 -0
- package/src/suites/hopelessnessCases.ts +286 -0
- package/src/suites/index.ts +11 -0
- package/src/testing.ts +646 -121
- package/src/types.ts +147 -0
- package/src/weekly.ts +39 -3
- package/starter/index.ts +8 -0
- package/templates/app/evals/[suite]/compare/page.tsx +385 -0
- package/templates/app/evals/[suite]/page.tsx +104 -31
- package/templates/app/evals/[suite]/rate/page.tsx +143 -0
- package/templates/app/evals/[suite]/runs/[runId]/page.tsx +84 -3
- package/templates/app/evals/[suite]/side-by-side/page.tsx +320 -0
- package/templates/app/evals/feedback/page.tsx +3 -0
- package/templates/app/evals/page.tsx +3 -0
- package/templates/components/evalkeeper/AnswerKey.tsx +2 -1
- package/templates/components/evalkeeper/DisagreementChip.tsx +35 -0
- package/templates/components/evalkeeper/ReadableOutput.tsx +97 -0
- package/templates/components/evalkeeper/RollBack.tsx +21 -1
- package/templates/components/evalkeeper/SettingsHistory.tsx +29 -5
- package/templates/components/evalkeeper/WeeklyCheck.tsx +34 -2
- package/templates/lib/evalkeeper/actions.ts +68 -4
- package/templates/lib/evalkeeper/weekly.ts +27 -4
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The matchers the contracts in `@crowandraven/evalkeeper/testing` use, a
|
|
5
|
+
* small part of Vitest's and Jest's `expect`. Any `expect` with these
|
|
6
|
+
* works: Vitest's, the `expect` package, or `assertExpect`.
|
|
7
|
+
*/
|
|
8
|
+
export type ContractMatchers = {
|
|
9
|
+
/** Passes when the value is the same one (`Object.is`). */
|
|
10
|
+
toBe(expected: unknown): void;
|
|
11
|
+
/** Passes when the value has the same content, ignoring undefined keys. */
|
|
12
|
+
toEqual(expected: unknown): void;
|
|
13
|
+
/** Passes when the value has at least these keys with these values. */
|
|
14
|
+
toMatchObject(expected: object): void;
|
|
15
|
+
/** Passes when the value's `length` is this. */
|
|
16
|
+
toHaveLength(length: number): void;
|
|
17
|
+
/** Passes when the value is null. */
|
|
18
|
+
toBeNull(): void;
|
|
19
|
+
/** Passes when the value is a number at least this. */
|
|
20
|
+
toBeGreaterThanOrEqual(expected: number): void;
|
|
21
|
+
/** Passes when the value is a number at most this. */
|
|
22
|
+
toBeLessThanOrEqual(expected: number): void;
|
|
23
|
+
/** For a promise: passes when it fails as described. */
|
|
24
|
+
rejects: {
|
|
25
|
+
/** Passes when the promise fails with an error whose message has this text. */
|
|
26
|
+
toThrow(expected: string): Promise<void>;
|
|
27
|
+
/** Passes when the promise fails with an instance of this class. */
|
|
28
|
+
toBeInstanceOf(
|
|
29
|
+
expected: abstract new (...args: never[]) => unknown,
|
|
30
|
+
): Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* An `expect` the contracts can use: takes a value (and a message to show
|
|
36
|
+
* when a check fails) and returns the matchers.
|
|
37
|
+
*/
|
|
38
|
+
export type ContractExpect = (
|
|
39
|
+
actual: unknown,
|
|
40
|
+
message?: string,
|
|
41
|
+
) => ContractMatchers;
|
|
42
|
+
|
|
43
|
+
function isPlainObject(v: unknown): v is Record<string, unknown> {
|
|
44
|
+
if (typeof v !== "object" || v === null) return false;
|
|
45
|
+
const proto: unknown = Object.getPrototypeOf(v);
|
|
46
|
+
return proto === Object.prototype || proto === null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A copy without undefined keys, as Vitest's `toEqual` compares. */
|
|
50
|
+
function withoutUndefined(v: unknown): unknown {
|
|
51
|
+
if (Array.isArray(v)) return v.map(withoutUndefined);
|
|
52
|
+
if (!isPlainObject(v)) return v;
|
|
53
|
+
const out: Record<string, unknown> = {};
|
|
54
|
+
for (const [k, x] of Object.entries(v))
|
|
55
|
+
if (x !== undefined) out[k] = withoutUndefined(x);
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The part of `actual` that `expected` names, so a deep comparison of the
|
|
61
|
+
* two checks only those keys (Vitest's `toMatchObject`).
|
|
62
|
+
*/
|
|
63
|
+
function picked(actual: unknown, expected: unknown): unknown {
|
|
64
|
+
if (Array.isArray(expected) && Array.isArray(actual))
|
|
65
|
+
return actual.length === expected.length
|
|
66
|
+
? actual.map((a, i) => picked(a, expected[i]))
|
|
67
|
+
: actual;
|
|
68
|
+
if (!isPlainObject(expected) || !isPlainObject(actual)) return actual;
|
|
69
|
+
const out: Record<string, unknown> = {};
|
|
70
|
+
for (const k of Object.keys(expected))
|
|
71
|
+
if (k in actual) out[k] = picked(actual[k], expected[k]);
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function failure(p: unknown): Promise<unknown> {
|
|
76
|
+
try {
|
|
77
|
+
await p;
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return e;
|
|
80
|
+
}
|
|
81
|
+
throw new assert.AssertionError({
|
|
82
|
+
message: "Expected the promise to fail, but it succeeded",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* An `expect` on `node:assert`, with just the matchers the contracts use,
|
|
88
|
+
* for running them outside Vitest (under `node:test`, say). Failures are
|
|
89
|
+
* `node:assert` errors, so any runner reports them.
|
|
90
|
+
*
|
|
91
|
+
* @param actual - The value to check.
|
|
92
|
+
* @param message - What to say when a check fails.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { describe, it } from "node:test";
|
|
97
|
+
* import { assertExpect, describeStoreContract } from "@crowandraven/evalkeeper/testing";
|
|
98
|
+
*
|
|
99
|
+
* describeStoreContract("my store", () => myStore(), {
|
|
100
|
+
* test: { describe, it, expect: assertExpect },
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export const assertExpect: ContractExpect = (actual, message) => ({
|
|
105
|
+
toBe(expected) {
|
|
106
|
+
assert.ok(
|
|
107
|
+
Object.is(actual, expected),
|
|
108
|
+
message ?? `Expected ${String(actual)} to be ${String(expected)}`,
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
toEqual(expected) {
|
|
112
|
+
assert.deepStrictEqual(
|
|
113
|
+
withoutUndefined(actual),
|
|
114
|
+
withoutUndefined(expected),
|
|
115
|
+
message,
|
|
116
|
+
);
|
|
117
|
+
},
|
|
118
|
+
toMatchObject(expected) {
|
|
119
|
+
assert.ok(
|
|
120
|
+
typeof actual === "object" && actual !== null,
|
|
121
|
+
message ?? "Expected an object",
|
|
122
|
+
);
|
|
123
|
+
assert.deepStrictEqual(
|
|
124
|
+
withoutUndefined(picked(actual, expected)),
|
|
125
|
+
withoutUndefined(expected),
|
|
126
|
+
message,
|
|
127
|
+
);
|
|
128
|
+
},
|
|
129
|
+
toHaveLength(length) {
|
|
130
|
+
const got: unknown =
|
|
131
|
+
typeof actual === "string" || Array.isArray(actual)
|
|
132
|
+
? actual.length
|
|
133
|
+
: undefined;
|
|
134
|
+
assert.strictEqual(got, length, message);
|
|
135
|
+
},
|
|
136
|
+
toBeNull() {
|
|
137
|
+
assert.strictEqual(actual, null, message);
|
|
138
|
+
},
|
|
139
|
+
toBeGreaterThanOrEqual(expected) {
|
|
140
|
+
assert.ok(
|
|
141
|
+
typeof actual === "number" && actual >= expected,
|
|
142
|
+
message ?? `Expected ${String(actual)} to be at least ${expected}`,
|
|
143
|
+
);
|
|
144
|
+
},
|
|
145
|
+
toBeLessThanOrEqual(expected) {
|
|
146
|
+
assert.ok(
|
|
147
|
+
typeof actual === "number" && actual <= expected,
|
|
148
|
+
message ?? `Expected ${String(actual)} to be at most ${expected}`,
|
|
149
|
+
);
|
|
150
|
+
},
|
|
151
|
+
rejects: {
|
|
152
|
+
async toThrow(expected) {
|
|
153
|
+
const e = await failure(actual);
|
|
154
|
+
const text = e instanceof Error ? e.message : String(e);
|
|
155
|
+
assert.ok(
|
|
156
|
+
text.includes(expected),
|
|
157
|
+
message ?? `Expected an error saying "${expected}", got "${text}"`,
|
|
158
|
+
);
|
|
159
|
+
},
|
|
160
|
+
async toBeInstanceOf(expected) {
|
|
161
|
+
const e = await failure(actual);
|
|
162
|
+
assert.ok(
|
|
163
|
+
e instanceof expected,
|
|
164
|
+
message ?? `Expected an error of class ${expected.name}`,
|
|
165
|
+
);
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
package/src/blind.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { CaseRecord, NewLabel } from "./store.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Rating imported cases blind: one person at a time, shown only a case's
|
|
5
|
+
* input, gives the answer and a reason, or skips it. What someone did with
|
|
6
|
+
* an item isn't the answer (docs/lessons.md, "History isn't a verdict"),
|
|
7
|
+
* and seeing what the app decided anchors the rating, so the page hides it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The `raterRole` on answers given by rating blind, so they can be told
|
|
12
|
+
* apart from answers written while looking at the app's output.
|
|
13
|
+
*/
|
|
14
|
+
export const BLIND_RATER = "BLIND_RATER";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Where a case stands for one rater: they gave it an answer ("rated"),
|
|
18
|
+
* passed on it ("skipped"), or neither yet (null). Any answer of theirs
|
|
19
|
+
* counts as rated, whatever its status, so nobody is asked twice.
|
|
20
|
+
*
|
|
21
|
+
* @param c - The case, with its answers.
|
|
22
|
+
* @param raterId - The person rating, as your app identifies them.
|
|
23
|
+
*/
|
|
24
|
+
export function raterStatus(
|
|
25
|
+
c: Pick<CaseRecord, "labels">,
|
|
26
|
+
raterId: string,
|
|
27
|
+
): "rated" | "skipped" | null {
|
|
28
|
+
const theirs = c.labels.filter((l) => l.raterId === raterId);
|
|
29
|
+
if (theirs.some((l) => l.status !== "SKIPPED")) return "rated";
|
|
30
|
+
return theirs.length ? "skipped" : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** One rater's place in a suite's blind rating. */
|
|
34
|
+
export type RateQueue = {
|
|
35
|
+
/** The oldest case they haven't rated or skipped; null when none is left. */
|
|
36
|
+
next: CaseRecord | null;
|
|
37
|
+
/** Cases they've given an answer. */
|
|
38
|
+
rated: number;
|
|
39
|
+
/** Cases they passed on. */
|
|
40
|
+
skipped: number;
|
|
41
|
+
/** Cases still waiting for them, the next one included. */
|
|
42
|
+
left: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* One rater's queue over a suite's cases: the next case to rate (the
|
|
47
|
+
* oldest one they haven't rated or skipped) and how far along they are.
|
|
48
|
+
* Answers other people gave don't take a case out of the queue: each
|
|
49
|
+
* rater gives their own. Retired cases are left out.
|
|
50
|
+
*
|
|
51
|
+
* @param cases - The suite's cases, as `store.listCases` returns them.
|
|
52
|
+
* @param raterId - The person rating, as your app identifies them.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const queue = rateQueue(await store.listCases("ticket_routing"), admin.id);
|
|
57
|
+
* if (queue.next) showInputOnly(queue.next.input);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function rateQueue(
|
|
61
|
+
cases: readonly CaseRecord[],
|
|
62
|
+
raterId: string,
|
|
63
|
+
): RateQueue {
|
|
64
|
+
const inUse = cases
|
|
65
|
+
.filter((c) => c.status !== "RETIRED")
|
|
66
|
+
.sort((a, b) => +a.createdAt - +b.createdAt);
|
|
67
|
+
let rated = 0;
|
|
68
|
+
let skipped = 0;
|
|
69
|
+
const waiting: CaseRecord[] = [];
|
|
70
|
+
for (const c of inUse) {
|
|
71
|
+
const s = raterStatus(c, raterId);
|
|
72
|
+
if (s === "rated") rated += 1;
|
|
73
|
+
else if (s === "skipped") skipped += 1;
|
|
74
|
+
else waiting.push(c);
|
|
75
|
+
}
|
|
76
|
+
return { next: waiting[0] ?? null, rated, skipped, left: waiting.length };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The oldest case this person hasn't rated or skipped, or null when none
|
|
81
|
+
* is left. See `rateQueue` for their progress too.
|
|
82
|
+
*
|
|
83
|
+
* @param cases - The suite's cases, as `store.listCases` returns them.
|
|
84
|
+
* @param raterId - The person rating, as your app identifies them.
|
|
85
|
+
*/
|
|
86
|
+
export function nextToRate(
|
|
87
|
+
cases: readonly CaseRecord[],
|
|
88
|
+
raterId: string,
|
|
89
|
+
): CaseRecord | null {
|
|
90
|
+
return rateQueue(cases, raterId).next;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A blind rating as an answer to add with `store.addLabel`: confirmed,
|
|
95
|
+
* since the person gave it themselves, recorded as theirs with their
|
|
96
|
+
* reason. It's added beside other people's answers, never over them.
|
|
97
|
+
* Throws when the reason is blank: a rating without one can't be checked
|
|
98
|
+
* later.
|
|
99
|
+
*
|
|
100
|
+
* @param r - Who rated, the answer (already read with the suite's
|
|
101
|
+
* `labelFromForm`), and why.
|
|
102
|
+
*/
|
|
103
|
+
export function blindRating(r: {
|
|
104
|
+
raterId: string;
|
|
105
|
+
value: unknown;
|
|
106
|
+
reason: string;
|
|
107
|
+
}): NewLabel {
|
|
108
|
+
const reason = r.reason.trim();
|
|
109
|
+
if (!reason) throw new Error("Say why: a rating needs a reason");
|
|
110
|
+
if (!r.raterId) throw new Error("A rating needs a rater");
|
|
111
|
+
return {
|
|
112
|
+
kind: "EXPECTED",
|
|
113
|
+
status: "CONFIRMED",
|
|
114
|
+
value: r.value,
|
|
115
|
+
raterRole: BLIND_RATER,
|
|
116
|
+
raterId: r.raterId,
|
|
117
|
+
note: reason,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A mark that this person passed on a case, to add with `store.addLabel`.
|
|
123
|
+
* It has no value and is never graded against; it only keeps the case
|
|
124
|
+
* out of their queue.
|
|
125
|
+
*
|
|
126
|
+
* @param raterId - The person who skipped it.
|
|
127
|
+
*/
|
|
128
|
+
export function skipMark(raterId: string): NewLabel {
|
|
129
|
+
if (!raterId) throw new Error("A skip needs a rater");
|
|
130
|
+
return {
|
|
131
|
+
kind: "EXPECTED",
|
|
132
|
+
status: "SKIPPED",
|
|
133
|
+
value: null,
|
|
134
|
+
raterRole: BLIND_RATER,
|
|
135
|
+
raterId,
|
|
136
|
+
note: null,
|
|
137
|
+
};
|
|
138
|
+
}
|
package/src/cli/addPages.ts
CHANGED
|
@@ -35,6 +35,9 @@ export const PAGE_NAMES: Readonly<Record<string, string>> = {
|
|
|
35
35
|
hub: "app/evals/page.tsx",
|
|
36
36
|
suite: "app/evals/[suite]/page.tsx",
|
|
37
37
|
run: "app/evals/[suite]/runs/[runId]/page.tsx",
|
|
38
|
+
rate: "app/evals/[suite]/rate/page.tsx",
|
|
39
|
+
compare: "app/evals/[suite]/compare/page.tsx",
|
|
40
|
+
"side-by-side": "app/evals/[suite]/side-by-side/page.tsx",
|
|
38
41
|
feedback: "app/evals/feedback/page.tsx",
|
|
39
42
|
cron: "app/api/cron/evals-weekly/route.ts",
|
|
40
43
|
};
|
|
@@ -47,7 +50,7 @@ export function templateName(templatePath: string): string {
|
|
|
47
50
|
|
|
48
51
|
/**
|
|
49
52
|
* The template files `--only` picks: each name is a page (hub, suite,
|
|
50
|
-
* run, feedback, cron), a component or glue file by its name (AnswerKey,
|
|
53
|
+
* run, rate, compare, side-by-side, feedback, cron), a component or glue file by its name (AnswerKey,
|
|
51
54
|
* actions, evalkeeper.css), or a group (pages, components), in any case.
|
|
52
55
|
* "index" (the wiring module) is allowed and handled by `planAddPages`.
|
|
53
56
|
* Throws on a name it doesn't know, listing the ones it does.
|
|
@@ -198,6 +201,17 @@ export function cleanBase(base: string): string {
|
|
|
198
201
|
return b;
|
|
199
202
|
}
|
|
200
203
|
|
|
204
|
+
/**
|
|
205
|
+
* The pages' URL from their folder: route groups ("(app)") are folders
|
|
206
|
+
* Next.js leaves out of the URL, so "(app)/admin/evals" is "/admin/evals".
|
|
207
|
+
*/
|
|
208
|
+
export function urlOfBase(base: string): string {
|
|
209
|
+
return `/${base
|
|
210
|
+
.split("/")
|
|
211
|
+
.filter((seg) => !/^\(.*\)$/.test(seg))
|
|
212
|
+
.join("/")}`;
|
|
213
|
+
}
|
|
214
|
+
|
|
201
215
|
function listFiles(dir: string): string[] {
|
|
202
216
|
return readdirSync(dir, { withFileTypes: true }).flatMap((e) =>
|
|
203
217
|
e.isDirectory() ? listFiles(join(dir, e.name)) : [join(dir, e.name)],
|
|
@@ -216,7 +230,7 @@ export function fitFile(
|
|
|
216
230
|
if (templatePath === "lib/evalkeeper/paths.ts")
|
|
217
231
|
out = out.replace(
|
|
218
232
|
/export const EVALS_BASE = "[^"]*";/,
|
|
219
|
-
`export const EVALS_BASE = "
|
|
233
|
+
`export const EVALS_BASE = "${urlOfBase(o.base)}";`,
|
|
220
234
|
);
|
|
221
235
|
return out;
|
|
222
236
|
}
|
|
@@ -302,8 +316,10 @@ export function planAddPages(o: AddPagesOptions): {
|
|
|
302
316
|
);
|
|
303
317
|
|
|
304
318
|
// What the chosen files import that the app won't have.
|
|
319
|
+
// Imports name files without their extension; a file this run copies
|
|
320
|
+
// counts as there.
|
|
305
321
|
const has = (t: string) =>
|
|
306
|
-
sources.includes(
|
|
322
|
+
[t, `${t}.ts`, `${t}.tsx`].some((p) => sources.includes(p)) ||
|
|
307
323
|
(t === wiring && files.some((f) => f.path === join(root, wiring))) ||
|
|
308
324
|
[t, `${t}.ts`, `${t}.tsx`].some((p) =>
|
|
309
325
|
existsSync(join(rootDir, destinationOf(p, base))),
|
|
@@ -350,6 +366,6 @@ export function nextSteps(r: {
|
|
|
350
366
|
!wiring || wiring.action === "skip"
|
|
351
367
|
? `Check ${wiring?.path ?? join(r.root, "lib/evalkeeper/index.ts")} exports what the pages use: MODELS, availableModels, modelsFor, SUITES, SUITE_BY_KEY, store, feedbackStore, settings, routeFor, runner, and requireAdmin.`
|
|
352
368
|
: `Fill in ${wiring.path}: your Prisma client, models, suites, and requireAdmin (until then, nobody can open the pages).`,
|
|
353
|
-
`Open
|
|
369
|
+
`Open ${urlOfBase(r.base)} in your app.`,
|
|
354
370
|
];
|
|
355
371
|
}
|
package/src/cli/main.ts
CHANGED
|
@@ -21,9 +21,10 @@ Options:
|
|
|
21
21
|
--root <dir> Where the alias points, e.g. "src" (default: from tsconfig.json)
|
|
22
22
|
--no-cron Leave out the weekly check's cron route
|
|
23
23
|
--only <names> Copy only these, comma-separated: pages (hub, suite, run,
|
|
24
|
-
feedback, cron), components
|
|
25
|
-
actions, …), the groups
|
|
26
|
-
"index" for a starter
|
|
24
|
+
rate, compare, side-by-side, feedback, cron), components
|
|
25
|
+
and glue by name (AnswerKey, actions, …), the groups
|
|
26
|
+
"pages" and "components", or "index" for a starter
|
|
27
|
+
lib/evalkeeper/index.ts
|
|
27
28
|
--force Overwrite files that already exist (never your lib/evalkeeper/index.ts)
|
|
28
29
|
--dry-run Show what would be written, and write nothing
|
|
29
30
|
--help Show this
|
package/src/compare.ts
CHANGED
|
@@ -259,3 +259,88 @@ export function verdictSentence(c: Comparison, challengerName: string): string {
|
|
|
259
259
|
return `No clear difference: ${challengerName} is somewhere between ${Math.round(c.low * 100)} and ${c.high > 0 ? "+" : ""}${Math.round(c.high * 100)} points${cost}.`;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* How two tests' answers to one case differ: the challenger broke a case
|
|
265
|
+
* the champion got fully right, fixed one the champion didn't, or both
|
|
266
|
+
* missed it in different ways (other checks failed, or one gave no answer).
|
|
267
|
+
*/
|
|
268
|
+
export type DisagreementKind = "broke" | "fixed" | "differ";
|
|
269
|
+
|
|
270
|
+
/** One case the two tests graded differently, for reading side by side. */
|
|
271
|
+
export type Disagreement = {
|
|
272
|
+
caseId: string;
|
|
273
|
+
kind: DisagreementKind;
|
|
274
|
+
/** Each test's score on the case, averaged over its repeats (0 to 1). */
|
|
275
|
+
champion: number;
|
|
276
|
+
challenger: number;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/** The order disagreements are listed in: what got worse first. */
|
|
280
|
+
const KIND_ORDER: Record<DisagreementKind, number> = {
|
|
281
|
+
broke: 0,
|
|
282
|
+
fixed: 1,
|
|
283
|
+
differ: 2,
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/** What went wrong on a case across its repeats: failed checks, and "no answer". */
|
|
287
|
+
function missesByCase(outputs: RunOutput[]): Map<string, string> {
|
|
288
|
+
const by = new Map<string, Set<string>>();
|
|
289
|
+
for (const o of outputs) {
|
|
290
|
+
const misses = by.get(o.caseId) ?? new Set<string>();
|
|
291
|
+
if (!o.checks) misses.add("(no answer)");
|
|
292
|
+
for (const c of o.checks ?? []) if (c.pass === false) misses.add(c.key);
|
|
293
|
+
by.set(o.caseId, misses);
|
|
294
|
+
}
|
|
295
|
+
return new Map([...by].map(([id, m]) => [id, [...m].sort().join("|")]));
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The cases two tests graded differently, on the cases they share: a
|
|
300
|
+
* different score, different checks failed, or an answer on one side and
|
|
301
|
+
* none on the other. Cases the challenger broke come first, then fixed,
|
|
302
|
+
* then the rest, each in case order. Use it to read where two models
|
|
303
|
+
* disagree: next to `compareRuns`, which says by how much.
|
|
304
|
+
*
|
|
305
|
+
* @param champion - The answers of the test in place (usually the live model's).
|
|
306
|
+
* @param challenger - The answers of the test it's compared with.
|
|
307
|
+
*/
|
|
308
|
+
export function disagreements(
|
|
309
|
+
champion: RunOutput[],
|
|
310
|
+
challenger: RunOutput[],
|
|
311
|
+
): Disagreement[] {
|
|
312
|
+
const a = passShareByCase(champion);
|
|
313
|
+
const b = passShareByCase(challenger);
|
|
314
|
+
const ma = missesByCase(champion);
|
|
315
|
+
const mb = missesByCase(challenger);
|
|
316
|
+
const found: Disagreement[] = [];
|
|
317
|
+
for (const id of [...a.keys()].filter((k) => b.has(k)).sort()) {
|
|
318
|
+
const sa = mustGet(a, id);
|
|
319
|
+
const sb = mustGet(b, id);
|
|
320
|
+
if (sa === sb && ma.get(id) === mb.get(id)) continue;
|
|
321
|
+
const kind: DisagreementKind =
|
|
322
|
+
sa === 1 && sb < 1 ? "broke" : sb === 1 && sa < 1 ? "fixed" : "differ";
|
|
323
|
+
found.push({ caseId: id, kind, champion: sa, challenger: sb });
|
|
324
|
+
}
|
|
325
|
+
return found.sort((x, y) => KIND_ORDER[x.kind] - KIND_ORDER[y.kind]);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Where a case sits in a list of disagreements, and the cases before and
|
|
330
|
+
* after it, for stepping through them one at a time. `index` is -1 (and
|
|
331
|
+
* `previous` null, `next` the first) when the case isn't in the list.
|
|
332
|
+
*
|
|
333
|
+
* @param list - The disagreements, in the order they're read.
|
|
334
|
+
* @param caseId - The case being read now.
|
|
335
|
+
*/
|
|
336
|
+
export function aroundCase(
|
|
337
|
+
list: Disagreement[],
|
|
338
|
+
caseId: string,
|
|
339
|
+
): { index: number; previous: string | null; next: string | null } {
|
|
340
|
+
const index = list.findIndex((d) => d.caseId === caseId);
|
|
341
|
+
return {
|
|
342
|
+
index,
|
|
343
|
+
previous: index > 0 ? (list[index - 1]?.caseId ?? null) : null,
|
|
344
|
+
next: list[index + 1]?.caseId ?? null,
|
|
345
|
+
};
|
|
346
|
+
}
|
package/src/decisions.ts
CHANGED
|
@@ -162,10 +162,20 @@ export function decisionCheck(
|
|
|
162
162
|
: answer.type === "choice"
|
|
163
163
|
? say(answer.choice)
|
|
164
164
|
: `level ${answer.score.toFixed(1)}`;
|
|
165
|
+
const pct = (p: number) => `${Math.round(p * 100)}%`;
|
|
166
|
+
const sure =
|
|
167
|
+
answer.type === "choice" &&
|
|
168
|
+
answer.probabilities?.[answer.choice] !== undefined
|
|
169
|
+
? ` (${pct(answer.probabilities[answer.choice] ?? 0)})`
|
|
170
|
+
: "";
|
|
165
171
|
return {
|
|
166
172
|
key,
|
|
167
173
|
pass: s.correct,
|
|
168
174
|
...(s.correct ? {} : { note: `Expected ${say(expected)}, got ${given}` }),
|
|
175
|
+
given:
|
|
176
|
+
answer.type === "boolean"
|
|
177
|
+
? `${given}, bar ${pct(opts.threshold ?? 0.5)}`
|
|
178
|
+
: `${given}${sure}`,
|
|
169
179
|
measures,
|
|
170
180
|
};
|
|
171
181
|
}
|
package/src/feedback.ts
CHANGED
|
@@ -40,6 +40,12 @@ export type FeedbackRecord = {
|
|
|
40
40
|
caseId: string | null;
|
|
41
41
|
createdAt: Date;
|
|
42
42
|
updatedAt: Date;
|
|
43
|
+
/**
|
|
44
|
+
* False when the store has no column for inputs (an app's own thumbs
|
|
45
|
+
* table that never kept them), so no rating from it can become a case.
|
|
46
|
+
* Stores that keep inputs leave it out.
|
|
47
|
+
*/
|
|
48
|
+
keepsInputs?: boolean;
|
|
43
49
|
};
|
|
44
50
|
|
|
45
51
|
/** A rating to save; `cleanRating` trims and bounds it. */
|
|
@@ -105,14 +111,24 @@ export function cleanRating(r: NewRating): Required<NewRating> {
|
|
|
105
111
|
};
|
|
106
112
|
}
|
|
107
113
|
|
|
114
|
+
/** Why no rating can become a case when the store keeps no inputs. */
|
|
115
|
+
export const NO_INPUTS_KEPT =
|
|
116
|
+
"This app doesn't keep inputs with ratings, so a rating can't become a case.";
|
|
117
|
+
|
|
108
118
|
/**
|
|
109
119
|
* Why a rating can't become a case for this suite, or null when it can. A
|
|
110
|
-
* case needs the input that produced the answer, in the suite's shape
|
|
120
|
+
* case needs the input that produced the answer, in the suite's shape, so
|
|
121
|
+
* a rating from a store that keeps no inputs (`keepsInputs: false`) never
|
|
122
|
+
* can.
|
|
123
|
+
*
|
|
124
|
+
* @param f - The rating.
|
|
125
|
+
* @param suite - The suite that tests its feature, if any.
|
|
111
126
|
*/
|
|
112
127
|
export function whyNotACase(
|
|
113
128
|
f: FeedbackRecord,
|
|
114
129
|
suite: AnySuite | undefined,
|
|
115
130
|
): string | null {
|
|
131
|
+
if (f.keepsInputs === false) return NO_INPUTS_KEPT;
|
|
116
132
|
if (!suite) return "No suite tests this feature yet.";
|
|
117
133
|
if (f.input === null || f.input === undefined)
|
|
118
134
|
return "The input behind this answer wasn't kept, so there's nothing to test.";
|
|
@@ -125,7 +141,9 @@ export function whyNotACase(
|
|
|
125
141
|
* A draft case from a rating, for a person to finish. A thumbs down has no
|
|
126
142
|
* answer yet: the person writes what a good one is. A thumbs up proposes
|
|
127
143
|
* the model's own answer, pending until a person confirms it. Never
|
|
128
|
-
* confirmed on anyone's behalf. Null when it can't become a case
|
|
144
|
+
* confirmed on anyone's behalf. Null when it can't become a case
|
|
145
|
+
* (`whyNotACase` says why in plain words, including when the store keeps
|
|
146
|
+
* no inputs at all).
|
|
129
147
|
*
|
|
130
148
|
* @example
|
|
131
149
|
* ```ts
|
package/src/glossary.ts
CHANGED
|
@@ -49,12 +49,27 @@ export const GLOSSARY = {
|
|
|
49
49
|
"Keeps what you typed, without your name, so it can become a test case for future models. Without it, a rating still counts but can't become a case.",
|
|
50
50
|
makeCase:
|
|
51
51
|
"Turns this rating into a draft case on its real input. A thumbs down needs a person to write the right answer; a thumbs up proposes the model's answer for a person to confirm.",
|
|
52
|
+
rateBlind:
|
|
53
|
+
"Rating imported cases one at a time from their input alone, never the app's output or what anyone did, so nothing anchors your answer. Each rating is your own confirmed answer, kept beside other people's.",
|
|
54
|
+
rateQueue:
|
|
55
|
+
"Your progress: cases you rated, cases you skipped, and cases still waiting for you, oldest first. Other people's answers don't count toward yours.",
|
|
56
|
+
skip: "Passes on this case for you only. It gives no answer and changes no test; others can still rate it, and you can still answer it in the answer key.",
|
|
52
57
|
needsAnswer:
|
|
53
58
|
"A draft case with no answer yet. Write what a good answer is; until then, tests leave it out.",
|
|
54
59
|
weeklyCheck:
|
|
55
60
|
"Each suite's quick set, answered again on its live model every week. A drop of 15 points or more against last week's check of the same model, instructions, and grading is drift.",
|
|
61
|
+
activityDraft:
|
|
62
|
+
"A case drafted from what the feature saw in your app this week. Its answer is pending or missing until a person reviews it, and tests leave it out until then.",
|
|
56
63
|
versions:
|
|
57
64
|
"Each numbered version of this feature's settings (model, fallback, reasoning, output limit, temperature), with who changed it, when, why, and its evidence. Any version can be made live again.",
|
|
65
|
+
changedOutside:
|
|
66
|
+
"The app's own settings no longer matched the live version: a script, SQL, or another page changed them. Recorded as found, before the next save, so you can roll back to it.",
|
|
67
|
+
inInstructions:
|
|
68
|
+
"A case whose words appear in the instructions the model is told. A test then grades it on an answer it was handed, so the score rises without the model getting better.",
|
|
69
|
+
newInstructions:
|
|
70
|
+
"The instructions changed in code and were recorded under the same models. No model was switched.",
|
|
71
|
+
instructionsEdited:
|
|
72
|
+
"Instructions edited at runtime (an admin override or added guidance) were recorded under the same models. No model was switched. Dated when noticed, which can be after the edit.",
|
|
58
73
|
suites:
|
|
59
74
|
"One suite per AI feature: its cases, the answers people confirmed, and the checks that grade any model against them. Open one to compare models and choose the live one.",
|
|
60
75
|
answerKey:
|
|
@@ -69,6 +84,31 @@ export const GLOSSARY = {
|
|
|
69
84
|
"The model returns its own probabilities for every option, so they can be scored and compared.",
|
|
70
85
|
promptedProbabilities:
|
|
71
86
|
"The model writes out its own estimate. Choices come without a distribution, so only true-or-false questions get probability scores.",
|
|
87
|
+
comparison:
|
|
88
|
+
"Two finished tests of one suite, compared case by case on the cases both answered, so which cases each happened to get can't decide it.",
|
|
89
|
+
inPlace:
|
|
90
|
+
"The test the other is weighed against, usually the live model's. Differences are counted from it.",
|
|
91
|
+
challenger:
|
|
92
|
+
"The test weighed against the one in place: another model, reasoning setting, or set of instructions.",
|
|
93
|
+
verdict:
|
|
94
|
+
"More accurate, about as accurate, or less accurate, read off a 95% range from resampling the shared cases. Under 5 shared cases, too few to tell.",
|
|
95
|
+
sharedCases: "Cases both tests answered. Only these are compared.",
|
|
96
|
+
measuredDifferently:
|
|
97
|
+
"The tests differ in more than the model: other cases, answers, checks, or instructions. Rescore both, or test again, before trusting the verdict.",
|
|
98
|
+
passRate:
|
|
99
|
+
"How often the check passed on the answers it applies to, and on how many answers.",
|
|
100
|
+
disagreements:
|
|
101
|
+
"Cases the two tests graded differently. About as accurate can hide cases one model gets right and the other wrong, so read them side by side.",
|
|
102
|
+
broke: "The test in place got this case fully right; the challenger didn't.",
|
|
103
|
+
fixed: "The challenger got this case fully right; the test in place didn't.",
|
|
104
|
+
missedDifferently:
|
|
105
|
+
"Neither got this case fully right, but they missed it in different ways: other checks failed, fewer parts right, or no answer on one side.",
|
|
106
|
+
caseScore:
|
|
107
|
+
"A test's score on this one case: 100% when every check passed, or parts right of parts expected with partial credit, averaged over repeats.",
|
|
108
|
+
sideBySide:
|
|
109
|
+
"Both tests' answers to one case, next to the expected answer, with what each check found. Step through every case where they differ.",
|
|
110
|
+
expectedAnswer:
|
|
111
|
+
"The answer the checks grade against: confirmed by a person, or provisional when put to use before review.",
|
|
72
112
|
} as const;
|
|
73
113
|
|
|
74
114
|
/** A word the glossary defines, for tooltips. */
|
package/src/health.ts
CHANGED
|
@@ -103,9 +103,11 @@ export function suiteHealth(
|
|
|
103
103
|
const change = s && !s.same;
|
|
104
104
|
if (change)
|
|
105
105
|
details.push(
|
|
106
|
-
s.
|
|
107
|
-
?
|
|
108
|
-
:
|
|
106
|
+
s.retestLive
|
|
107
|
+
? (s.reasons[0] ?? `Test ${s.live.label} again.`)
|
|
108
|
+
: s.keepLive
|
|
109
|
+
? `A better fallback is suggested: ${s.fallback?.label}.`
|
|
110
|
+
: `${s.live.label} is suggested over ${liveRow.label}.`,
|
|
109
111
|
);
|
|
110
112
|
if (testedModels < 2)
|
|
111
113
|
details.push("Only one model tested: test others to compare.");
|