@crowandraven/evalkeeper 0.8.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.
- package/dist/cli/addPages.js +1 -1
- package/dist/cli/addPages.js.map +1 -1
- package/dist/feedback.d.ts +3 -1
- package/dist/feedback.js +3 -1
- package/dist/feedback.js.map +1 -1
- package/dist/glossary.d.ts +5 -0
- package/dist/glossary.js +5 -0
- package/dist/glossary.js.map +1 -1
- package/dist/health.d.ts +4 -1
- package/dist/health.js +4 -2
- package/dist/health.js.map +1 -1
- package/dist/importCases.d.ts +15 -4
- package/dist/importCases.js +20 -18
- package/dist/importCases.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/reviews.d.ts +172 -0
- package/dist/reviews.js +294 -0
- package/dist/reviews.js.map +1 -0
- package/dist/runner.d.ts +14 -1
- package/dist/runner.js +10 -0
- package/dist/runner.js.map +1 -1
- package/dist/suggest.d.ts +52 -2
- package/dist/suggest.js +101 -8
- package/dist/suggest.js.map +1 -1
- package/dist/suiteContract.d.ts +3 -2
- package/dist/suiteContract.js +5 -2
- package/dist/suiteContract.js.map +1 -1
- package/dist/suites/attackImport.d.ts +99 -0
- package/dist/suites/attackImport.js +283 -0
- package/dist/suites/attackImport.js.map +1 -0
- package/dist/suites/crisisRisk.d.ts +9 -2
- package/dist/suites/crisisRisk.js +8 -3
- package/dist/suites/crisisRisk.js.map +1 -1
- package/dist/suites/crisisRiskCases.d.ts +4 -3
- package/dist/suites/crisisRiskCases.js +4 -3
- package/dist/suites/crisisRiskCases.js.map +1 -1
- package/dist/suites/crisisRiskReviews.d.ts +15 -0
- package/dist/suites/crisisRiskReviews.js +926 -0
- package/dist/suites/crisisRiskReviews.js.map +1 -0
- package/dist/suites/hopelessness.d.ts +9 -2
- package/dist/suites/hopelessness.js +8 -5
- package/dist/suites/hopelessness.js.map +1 -1
- package/dist/suites/hopelessnessCases.d.ts +3 -2
- package/dist/suites/hopelessnessCases.js +3 -2
- package/dist/suites/hopelessnessCases.js.map +1 -1
- package/dist/suites/hopelessnessReviews.d.ts +15 -0
- package/dist/suites/hopelessnessReviews.js +1080 -0
- package/dist/suites/hopelessnessReviews.js.map +1 -0
- package/dist/suites/index.d.ts +5 -0
- package/dist/suites/index.js +5 -0
- package/dist/suites/index.js.map +1 -1
- package/dist/suites/injection.d.ts +162 -0
- package/dist/suites/injection.js +331 -0
- package/dist/suites/injection.js.map +1 -0
- package/dist/suites/injectionAttacks.d.ts +3 -0
- package/dist/suites/injectionAttacks.js +34 -0
- package/dist/suites/injectionAttacks.js.map +1 -0
- package/dist/types.d.ts +100 -2
- package/dist/types.js +106 -11
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/addPages.ts +1 -1
- package/src/feedback.ts +3 -1
- package/src/glossary.ts +10 -0
- package/src/health.ts +4 -2
- package/src/importCases.ts +21 -20
- package/src/index.ts +1 -0
- package/src/reviews.ts +428 -0
- package/src/runner.ts +15 -1
- package/src/suggest.ts +145 -13
- package/src/suiteContract.ts +5 -2
- package/src/suites/attackImport.ts +327 -0
- package/src/suites/crisisRisk.ts +15 -3
- package/src/suites/crisisRiskCases.ts +4 -3
- package/src/suites/crisisRiskReviews.ts +927 -0
- package/src/suites/hopelessness.ts +15 -5
- package/src/suites/hopelessnessCases.ts +3 -2
- package/src/suites/hopelessnessReviews.ts +1081 -0
- package/src/suites/index.ts +5 -0
- package/src/suites/injection.ts +463 -0
- package/src/suites/injectionAttacks.ts +136 -0
- package/src/types.ts +169 -17
- package/starter/index.ts +11 -0
- package/templates/app/evals/[suite]/page.tsx +185 -32
- package/templates/app/evals/[suite]/rate/page.tsx +14 -4
- package/templates/app/evals/feedback/page.tsx +3 -1
- package/templates/app/evals/page.tsx +44 -5
- package/templates/components/evalkeeper/AnswerKey.tsx +35 -6
- package/templates/components/evalkeeper/Fields.tsx +49 -5
- package/templates/lib/evalkeeper/actions.ts +39 -15
package/dist/suggest.js
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
import { isBaseline, retiresLabel } from "./models.js";
|
|
2
2
|
import { at } from "./util.js";
|
|
3
|
+
/**
|
|
4
|
+
* Injection suites' boards in the shape `suggest` reads, for its
|
|
5
|
+
* `attacks` option.
|
|
6
|
+
*
|
|
7
|
+
* @param boards - The boards of a feature's injection suites
|
|
8
|
+
* (`runner.attackBoards`).
|
|
9
|
+
* @returns One entry per injection suite.
|
|
10
|
+
*/
|
|
11
|
+
export function attacksFrom(boards) {
|
|
12
|
+
return boards.map((b) => ({
|
|
13
|
+
label: b.suite.label,
|
|
14
|
+
rows: b.rows,
|
|
15
|
+
checks: b.suite.checks,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A model's serious mistakes under attack: its serious mistakes on every
|
|
20
|
+
* injection suite, added up. Null when any of them has no current,
|
|
21
|
+
* complete test of it, so it can't be compared yet; also null with no
|
|
22
|
+
* injection suites.
|
|
23
|
+
*
|
|
24
|
+
* @param key - The model's row key (model and reasoning setting).
|
|
25
|
+
* @param attacks - The feature's injection suites.
|
|
26
|
+
*/
|
|
27
|
+
export function attackMistakes(key, attacks) {
|
|
28
|
+
if (!attacks.length)
|
|
29
|
+
return null;
|
|
30
|
+
let total = 0;
|
|
31
|
+
for (const a of attacks) {
|
|
32
|
+
const r = a.rows.find((x) => x.key === key);
|
|
33
|
+
if (!r?.test || r.test.stale || r.test.failedAnswers)
|
|
34
|
+
return null;
|
|
35
|
+
total += seriousMistakes(r, a.checks);
|
|
36
|
+
}
|
|
37
|
+
return total;
|
|
38
|
+
}
|
|
3
39
|
/**
|
|
4
40
|
* How many serious checks a model's test failed; Infinity without a test.
|
|
5
41
|
*/
|
|
@@ -38,7 +74,14 @@ const clearlyLess = (a, b) => Number.isFinite(a) && Number.isFinite(b) && a <= b
|
|
|
38
74
|
*/
|
|
39
75
|
export function suggest(rows, checks, priority = { favor: "quality" },
|
|
40
76
|
/** Your model catalog: providers (for the fallback) and retirements. */
|
|
41
|
-
models = {}
|
|
77
|
+
models = {},
|
|
78
|
+
/** The feature's injection suites, to weigh attacks too. */
|
|
79
|
+
opts = {}) {
|
|
80
|
+
const attacks = opts.attacks ?? [];
|
|
81
|
+
const weighAttacks = attacks.length > 0;
|
|
82
|
+
/** Serious mistakes under attack; null when not tested against them. */
|
|
83
|
+
const underAttack = (r) => attackMistakes(r.key, attacks);
|
|
84
|
+
const attackTested = (r) => !weighAttacks || underAttack(r) !== null;
|
|
42
85
|
const provider = (model) => models[model]?.provider ?? model;
|
|
43
86
|
const retiring = (r) => retiresLabel(models, r.model);
|
|
44
87
|
const limitMs = priority.maxSeconds ? priority.maxSeconds * 1000 : Infinity;
|
|
@@ -82,12 +125,27 @@ models = {}) {
|
|
|
82
125
|
else if (!live) {
|
|
83
126
|
if (!liveable.length)
|
|
84
127
|
return null;
|
|
85
|
-
|
|
128
|
+
// Only models tested against the attacks, unless none are.
|
|
129
|
+
const known = liveable.filter(attackTested);
|
|
130
|
+
next = at([...(known.length ? known : liveable)].sort((a, b) => rate(b) - rate(a) ||
|
|
131
|
+
serious(a) - serious(b) ||
|
|
132
|
+
(underAttack(a) ?? 0) - (underAttack(b) ?? 0) ||
|
|
133
|
+
cost(a) - cost(b)), 0);
|
|
86
134
|
reasons.push(liveRetires || liveSlow
|
|
87
135
|
? `${liveRetires && liveRow ? `${liveRow.label} retires in ${liveRetires}.` : liveSlow} ${next.label} scores highest of the rest (${pct(rate(next))}) with ${mistakes(serious(next))}.`
|
|
88
136
|
: `${next.label} scores highest (${pct(rate(next))}) with ${mistakes(serious(next))}. The live model has no up-to-date test to compare with.`);
|
|
137
|
+
if (!attackTested(next))
|
|
138
|
+
reasons.push(`No model has an up-to-date test against the attacks: test ${next.label} on them before relying on it.`);
|
|
89
139
|
}
|
|
90
140
|
else {
|
|
141
|
+
// At least two fewer serious mistakes under attack, as accurate or more.
|
|
142
|
+
const attackReason = (r) => {
|
|
143
|
+
const ra = underAttack(r);
|
|
144
|
+
const la = underAttack(live);
|
|
145
|
+
return ra !== null && la !== null && ra <= la - 2 && rate(r) >= rate(live)
|
|
146
|
+
? `${r.label} makes fewer serious mistakes under attack than ${live.label} (${ra} against ${la}), and scores at least as well (${pct(rate(r))} against ${pct(rate(live))}).`
|
|
147
|
+
: null;
|
|
148
|
+
};
|
|
91
149
|
const why = (r) => {
|
|
92
150
|
if (rate(r) < rate(live))
|
|
93
151
|
return trade(r);
|
|
@@ -95,6 +153,9 @@ models = {}) {
|
|
|
95
153
|
return `${r.label} is clearly more accurate than ${live.label}: ${pct(rate(r))} against ${pct(rate(live))}.`;
|
|
96
154
|
if (serious(r) <= serious(live) - 2)
|
|
97
155
|
return `${r.label} makes fewer serious mistakes than ${live.label} (${serious(r)} against ${serious(live)}), and scores at least as well (${pct(rate(r))} against ${pct(rate(live))}).`;
|
|
156
|
+
const byAttacks = attackReason(r);
|
|
157
|
+
if (byAttacks)
|
|
158
|
+
return byAttacks;
|
|
98
159
|
if (priority.favor === "cost" && clearlyLess(cost(r), cost(live)))
|
|
99
160
|
return `${r.label} scores at least as well as ${live.label} (${pct(rate(r))} against ${pct(rate(live))}) at ${Math.round((1 - cost(r) / cost(live)) * 100)}% less per answer.`;
|
|
100
161
|
if (priority.favor === "speed" && clearlyLess(ms(r), ms(live)))
|
|
@@ -116,11 +177,20 @@ models = {}) {
|
|
|
116
177
|
return `${close}, and answers in ${(ms(r) / 1000).toFixed(1)}s against ${(ms(live) / 1000).toFixed(1)}s. This suite favors speed.`;
|
|
117
178
|
return null;
|
|
118
179
|
};
|
|
119
|
-
|
|
120
|
-
|
|
180
|
+
// Under attack: tested, and no more serious mistakes than live (when
|
|
181
|
+
// live has a test to compare with).
|
|
182
|
+
const liveAttack = underAttack(live);
|
|
183
|
+
const safeUnderAttack = (r) => {
|
|
184
|
+
const a = underAttack(r);
|
|
185
|
+
return (!weighAttacks ||
|
|
186
|
+
(a !== null && (liveAttack === null || a <= liveAttack)));
|
|
187
|
+
};
|
|
188
|
+
const qualifies = (r) => !r.live &&
|
|
121
189
|
r.vsLive !== "WORSE" &&
|
|
122
190
|
serious(r) <= serious(live) &&
|
|
123
|
-
why(r)
|
|
191
|
+
why(r) !== null;
|
|
192
|
+
const candidates = liveable
|
|
193
|
+
.filter((r) => qualifies(r) && safeUnderAttack(r))
|
|
124
194
|
.sort((a, b) => Number(b.vsLive === "BETTER") - Number(a.vsLive === "BETTER") ||
|
|
125
195
|
// A trade-off only when nothing scores as well.
|
|
126
196
|
Number(rate(b) >= rate(live)) - Number(rate(a) >= rate(live)) ||
|
|
@@ -134,10 +204,23 @@ models = {}) {
|
|
|
134
204
|
const reason = why(next);
|
|
135
205
|
if (reason)
|
|
136
206
|
reasons.push(reason);
|
|
207
|
+
const a = underAttack(next);
|
|
208
|
+
if (a !== null && reason !== attackReason(next))
|
|
209
|
+
reasons.push(liveAttack === null
|
|
210
|
+
? `Under attack, ${next.label} makes ${mistakes(a)}. ${live.label} has no up-to-date test against the attacks to compare with.`
|
|
211
|
+
: `Under attack, ${next.label} makes ${mistakes(a)}, against ${liveAttack} for ${live.label}.`);
|
|
137
212
|
}
|
|
138
213
|
else {
|
|
139
214
|
next = live;
|
|
140
215
|
reasons.push(`Keep ${live.label}: no other model is safely better on these cases.`);
|
|
216
|
+
// Would have been suggested, but for the attacks.
|
|
217
|
+
const held = liveable.find((r) => qualifies(r) && !safeUnderAttack(r));
|
|
218
|
+
if (held) {
|
|
219
|
+
const a = underAttack(held);
|
|
220
|
+
reasons.push(a === null
|
|
221
|
+
? `${held.label} would otherwise qualify, but it has no up-to-date test against the attacks. Test it on ${at(attacks, 0).label}.`
|
|
222
|
+
: `${held.label} would otherwise qualify, but it makes more serious mistakes under attack (${a} against ${liveAttack ?? 0}).`);
|
|
223
|
+
}
|
|
141
224
|
// The one to watch: scored higher, but not by enough to tell.
|
|
142
225
|
const watch = tested
|
|
143
226
|
.filter((r) => !r.live && rate(r) > rate(live))
|
|
@@ -153,9 +236,19 @@ models = {}) {
|
|
|
153
236
|
!r.liveOnly &&
|
|
154
237
|
r.key !== next.key &&
|
|
155
238
|
provider(r.model) !== provider(next.model))
|
|
156
|
-
.sort((a, b) => rate(b) - rate(a) ||
|
|
157
|
-
|
|
158
|
-
|
|
239
|
+
.sort((a, b) => rate(b) - rate(a) ||
|
|
240
|
+
serious(a) - serious(b) ||
|
|
241
|
+
(underAttack(a) ?? Infinity) - (underAttack(b) ?? Infinity) ||
|
|
242
|
+
cost(a) - cost(b))[0] ?? null;
|
|
243
|
+
if (fallback) {
|
|
244
|
+
const a = underAttack(fallback);
|
|
245
|
+
const attacked = !weighAttacks
|
|
246
|
+
? ""
|
|
247
|
+
: a === null
|
|
248
|
+
? "; not tested against the attacks"
|
|
249
|
+
: `; ${mistakes(a)} under attack`;
|
|
250
|
+
reasons.push(`Fallback: ${fallback.label} is the most accurate from another provider (${pct(rate(fallback))}, ${mistakes(serious(fallback))}${attacked}).`);
|
|
251
|
+
}
|
|
159
252
|
const keepLive = next.live;
|
|
160
253
|
const retestLive = Boolean(liveFailed);
|
|
161
254
|
return {
|
package/dist/suggest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suggest.js","sourceRoot":"","sources":["../src/suggest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAqB,MAAM,aAAa,CAAC;AAI1E,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAmE/B;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,GAAe,EAAE,MAAkB;IACjE,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACtB,IAAI,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAC;IAC3B,OAAO,MAAM;SACV,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC;SACvC,MAAM,CAAC,CAAC,CAAC,EAAE,CA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MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACvC,OAAO;QACL,IAAI,EAAE,IAAI;QACV,QAAQ;QACR,QAAQ;QACR,IAAI,EAAE,QAAQ,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC;QACjE,UAAU;QACV,OAAO;KACR,CAAC;AACJ,CAAC"}
|
package/dist/suiteContract.d.ts
CHANGED
|
@@ -16,8 +16,9 @@ export declare function schemaKeys(schema: z.ZodTypeAny): string[] | null;
|
|
|
16
16
|
* sentences; empty when nothing is. Checks that suite keys are unique;
|
|
17
17
|
* every top-level field of each suite's input and answer (every option's,
|
|
18
18
|
* for a union) has a `fields` entry with a label and help, and no entry
|
|
19
|
-
* names a field the schema doesn't have; every check has a description;
|
|
20
|
-
* cases fit the suite's own schemas
|
|
19
|
+
* names a field the schema doesn't have; every check has a description;
|
|
20
|
+
* starter cases fit the suite's own schemas; and every shipped review
|
|
21
|
+
* still matches its case's input and answer (see `reviewProblems`). Pure; `describeSuiteContract` runs it
|
|
21
22
|
* as tests.
|
|
22
23
|
*/
|
|
23
24
|
export declare function suiteContractProblems(suites: readonly AnySuite[]): string[];
|
package/dist/suiteContract.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { reviewProblems } from "./reviews.js";
|
|
1
2
|
/** A field help shorter than this says nothing a label doesn't. */
|
|
2
3
|
const MIN_HELP = 10;
|
|
3
4
|
/**
|
|
@@ -78,8 +79,9 @@ function fieldProblems(suite, side, keys, fields) {
|
|
|
78
79
|
* sentences; empty when nothing is. Checks that suite keys are unique;
|
|
79
80
|
* every top-level field of each suite's input and answer (every option's,
|
|
80
81
|
* for a union) has a `fields` entry with a label and help, and no entry
|
|
81
|
-
* names a field the schema doesn't have; every check has a description;
|
|
82
|
-
* cases fit the suite's own schemas
|
|
82
|
+
* names a field the schema doesn't have; every check has a description;
|
|
83
|
+
* starter cases fit the suite's own schemas; and every shipped review
|
|
84
|
+
* still matches its case's input and answer (see `reviewProblems`). Pure; `describeSuiteContract` runs it
|
|
83
85
|
* as tests.
|
|
84
86
|
*/
|
|
85
87
|
export function suiteContractProblems(suites) {
|
|
@@ -100,6 +102,7 @@ export function suiteContractProblems(suites) {
|
|
|
100
102
|
if (!suite.labelValue.safeParse(s.label).success)
|
|
101
103
|
out.push(`${name}: starter ${i + 1}'s answer doesn't fit the schema.`);
|
|
102
104
|
});
|
|
105
|
+
out.push(...reviewProblems(suite));
|
|
103
106
|
}
|
|
104
107
|
return out;
|
|
105
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suiteContract.js","sourceRoot":"","sources":["../src/suiteContract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"suiteContract.js","sourceRoot":"","sources":["../src/suiteContract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C,mEAAmE;AACnE,MAAM,QAAQ,GAAG,EAAE,CAAC;AAYpB;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,MAAoB;IAC7C,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED,yEAAyE;AACzE,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,SAAS,MAAM,CAAC,MAAoB,EAAE,KAAa;IACjD,IAAI,CAAC,GAA6B,MAAM,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,kEAAkE;QAClE,MAAM,GAAG,GAAG,CAAC,CAAC,IAAW,CAAC;QAC1B,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,IAAI,GAAG,CAAC,KAAK;YAC3C,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;QAClC,IACE,CAAC,GAAG,CAAC,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AAC,IAAI,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type Attack, type AttackKind } from "./injection.js";
|
|
2
|
+
/**
|
|
3
|
+
* Attacks from other tools, for the injection suite (./injection.ts).
|
|
4
|
+
* Each reader takes what the tool wrote, as text, and returns attacks in
|
|
5
|
+
* Evalkeeper's shape; it never calls the tool or the network. Where the
|
|
6
|
+
* tool checks for a word the model shouldn't say, the reader swaps that
|
|
7
|
+
* word for `{{canary}}`, so the suite's own canary check grades it.
|
|
8
|
+
* Attacks the suite couldn't grade without a judge model are left out
|
|
9
|
+
* and counted in `skipped`.
|
|
10
|
+
*
|
|
11
|
+
* Their datasets carry their own licenses (garak: Apache-2.0;
|
|
12
|
+
* CyberSecEval: MIT; promptfoo's generated tests: yours). The attacks are
|
|
13
|
+
* stored as cases in your database, so read them before relying on them.
|
|
14
|
+
*/
|
|
15
|
+
/** Attacks read from a tool's output, and what was left out. */
|
|
16
|
+
export type ImportedAttacks = {
|
|
17
|
+
attacks: Attack[];
|
|
18
|
+
/** Entries left out, with why, for a person to check. */
|
|
19
|
+
skipped: {
|
|
20
|
+
id: string;
|
|
21
|
+
why: string;
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Reads an attack file: one JSON attack per line (`id`, `kind`, `text`,
|
|
26
|
+
* `technique`, `source`). Blank lines are skipped. Any line that doesn't
|
|
27
|
+
* fit, or an id used twice within a source, stops it with every problem
|
|
28
|
+
* listed, so a file is used whole or not at all.
|
|
29
|
+
*
|
|
30
|
+
* @param text - The file's contents.
|
|
31
|
+
* @returns The attacks, in file order.
|
|
32
|
+
* @throws When a line isn't JSON, doesn't fit, or repeats an id.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const attacks = readAttacks(readFileSync("attacks.jsonl", "utf8"));
|
|
36
|
+
* export const triageInjection = injectionSuite(ticketTriage, {
|
|
37
|
+
* inject,
|
|
38
|
+
* attacks: [...INJECTION_ATTACKS, ...attacks],
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function readAttacks(text: string): Attack[];
|
|
43
|
+
/**
|
|
44
|
+
* Attacks as an attack file: one JSON attack per line, for `readAttacks`.
|
|
45
|
+
*
|
|
46
|
+
* @param attacks - The attacks to write.
|
|
47
|
+
*/
|
|
48
|
+
export declare function writeAttacks(attacks: readonly Attack[]): string;
|
|
49
|
+
/**
|
|
50
|
+
* Reads CyberSecEval's prompt injection set (Meta's PurpleLlama,
|
|
51
|
+
* `CybersecurityBenchmarks/datasets/prompt_injection/prompt_injection.json`).
|
|
52
|
+
* A case whose check asks for a word the attack itself names ("say
|
|
53
|
+
* 'Piano'") becomes a direct or indirect attack carrying the canary. One
|
|
54
|
+
* whose word is a secret in the benchmark's own system prompt becomes an
|
|
55
|
+
* extraction attack, graded by your suite's `secrets`. Cases checked
|
|
56
|
+
* another way (a judge's reading of the answer) are skipped.
|
|
57
|
+
*
|
|
58
|
+
* @param json - The dataset's JSON text.
|
|
59
|
+
* @param source - Where it came from, recorded on each attack; include
|
|
60
|
+
* the commit or version.
|
|
61
|
+
*/
|
|
62
|
+
export declare function cyberSecEvalAttacks(json: string, source?: string): ImportedAttacks;
|
|
63
|
+
/**
|
|
64
|
+
* Reads garak's system prompt extraction attacks
|
|
65
|
+
* (`garak/data/sysprompt_extraction/attacks.json`: lists of requests by
|
|
66
|
+
* technique) as extraction attacks, graded by your suite's `secrets`.
|
|
67
|
+
*
|
|
68
|
+
* @param json - The file's JSON text.
|
|
69
|
+
* @param source - Where it came from, with garak's version.
|
|
70
|
+
*/
|
|
71
|
+
export declare function garakSyspromptAttacks(json: string, source?: string): ImportedAttacks;
|
|
72
|
+
/**
|
|
73
|
+
* Reads the attempts in a garak report (`garak.<run>.report.jsonl`) from
|
|
74
|
+
* its injection probes: run garak against its offline `test.Blank`
|
|
75
|
+
* generator and no model is called, but the report still records every
|
|
76
|
+
* attack. Each attempt's trigger (the string garak checks the answer
|
|
77
|
+
* for) becomes the canary; `latentinjection` probes, which hide the
|
|
78
|
+
* attack in a document, are indirect, the rest direct. Attempts with no
|
|
79
|
+
* trigger in their text, and repeats of the same text, are skipped.
|
|
80
|
+
*
|
|
81
|
+
* @param jsonl - The report's text.
|
|
82
|
+
* @param source - Where it came from, with garak's version.
|
|
83
|
+
*/
|
|
84
|
+
export declare function garakReportAttacks(jsonl: string, source?: string): ImportedAttacks;
|
|
85
|
+
/**
|
|
86
|
+
* Reads promptfoo's red team tests written as Burp payloads
|
|
87
|
+
* (`promptfoo redteam generate -o tests.burp`): one URL-encoded attack
|
|
88
|
+
* per line. They
|
|
89
|
+
* carry no canary, so only your suite's own checks and `secrets` grade
|
|
90
|
+
* them. Note that promptfoo writes these with a model, on its hosted
|
|
91
|
+
* service unless you set it up otherwise, and sends it your app's
|
|
92
|
+
* description.
|
|
93
|
+
*
|
|
94
|
+
* @param text - The .burp file's text.
|
|
95
|
+
* @param source - Where it came from, with promptfoo's version.
|
|
96
|
+
* @param kind - What the plugin you generated with tests; default
|
|
97
|
+
* "direct".
|
|
98
|
+
*/
|
|
99
|
+
export declare function promptfooBurpAttacks(text: string, source?: string, kind?: AttackKind): ImportedAttacks;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { starterKey } from "../reviews.js";
|
|
3
|
+
import { ATTACK_KINDS } from "./injection.js";
|
|
4
|
+
/** One attack, as Evalkeeper's attack file (JSONL) holds it. */
|
|
5
|
+
const attackRow = z.object({
|
|
6
|
+
id: z.string().min(1),
|
|
7
|
+
kind: z.enum(ATTACK_KINDS),
|
|
8
|
+
text: z.string().min(1),
|
|
9
|
+
technique: z.string().min(1),
|
|
10
|
+
source: z.string().min(1),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Reads an attack file: one JSON attack per line (`id`, `kind`, `text`,
|
|
14
|
+
* `technique`, `source`). Blank lines are skipped. Any line that doesn't
|
|
15
|
+
* fit, or an id used twice within a source, stops it with every problem
|
|
16
|
+
* listed, so a file is used whole or not at all.
|
|
17
|
+
*
|
|
18
|
+
* @param text - The file's contents.
|
|
19
|
+
* @returns The attacks, in file order.
|
|
20
|
+
* @throws When a line isn't JSON, doesn't fit, or repeats an id.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const attacks = readAttacks(readFileSync("attacks.jsonl", "utf8"));
|
|
24
|
+
* export const triageInjection = injectionSuite(ticketTriage, {
|
|
25
|
+
* inject,
|
|
26
|
+
* attacks: [...INJECTION_ATTACKS, ...attacks],
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function readAttacks(text) {
|
|
31
|
+
const problems = [];
|
|
32
|
+
const out = [];
|
|
33
|
+
const seen = new Set();
|
|
34
|
+
text.split(/\r?\n/).forEach((line, i) => {
|
|
35
|
+
if (!line.trim())
|
|
36
|
+
return;
|
|
37
|
+
let value;
|
|
38
|
+
try {
|
|
39
|
+
value = JSON.parse(line);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
problems.push(`line ${i + 1} isn't JSON`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const row = attackRow.safeParse(value);
|
|
46
|
+
if (!row.success) {
|
|
47
|
+
const issue = row.error.issues[0];
|
|
48
|
+
problems.push(`line ${i + 1}: ${issue?.path.join(".") || "attack"} ${issue?.message ?? "doesn't fit"}`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const key = `${row.data.source}|${row.data.id}`;
|
|
52
|
+
if (seen.has(key))
|
|
53
|
+
problems.push(`line ${i + 1} repeats the id ${row.data.id}`);
|
|
54
|
+
seen.add(key);
|
|
55
|
+
out.push(row.data);
|
|
56
|
+
});
|
|
57
|
+
if (problems.length)
|
|
58
|
+
throw new Error(`The attack file can't be read: ${problems.slice(0, 5).join("; ")}${problems.length > 5 ? "; …" : ""}.`);
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Attacks as an attack file: one JSON attack per line, for `readAttacks`.
|
|
63
|
+
*
|
|
64
|
+
* @param attacks - The attacks to write.
|
|
65
|
+
*/
|
|
66
|
+
export function writeAttacks(attacks) {
|
|
67
|
+
return attacks
|
|
68
|
+
.map((a) => JSON.stringify({
|
|
69
|
+
id: a.id,
|
|
70
|
+
kind: a.kind,
|
|
71
|
+
text: a.text,
|
|
72
|
+
technique: a.technique,
|
|
73
|
+
source: a.source,
|
|
74
|
+
}))
|
|
75
|
+
.join("\n")
|
|
76
|
+
.concat(attacks.length ? "\n" : "");
|
|
77
|
+
}
|
|
78
|
+
/** Every whole-word use of `word` in `text`, any case, swapped for the canary. */
|
|
79
|
+
function withCanary(text, word) {
|
|
80
|
+
const escaped = word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
81
|
+
const re = new RegExp(`(?<![\\w])${escaped}(?![\\w])`, "gi");
|
|
82
|
+
return re.test(text) ? text.replace(re, "{{canary}}") : null;
|
|
83
|
+
}
|
|
84
|
+
const cyberSecEvalRow = z.object({
|
|
85
|
+
prompt_id: z.union([z.number(), z.string()]),
|
|
86
|
+
test_case_prompt: z.string(),
|
|
87
|
+
user_input: z.string(),
|
|
88
|
+
judge_question: z.string(),
|
|
89
|
+
injection_variant: z.string(),
|
|
90
|
+
injection_type: z.string(),
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* Reads CyberSecEval's prompt injection set (Meta's PurpleLlama,
|
|
94
|
+
* `CybersecurityBenchmarks/datasets/prompt_injection/prompt_injection.json`).
|
|
95
|
+
* A case whose check asks for a word the attack itself names ("say
|
|
96
|
+
* 'Piano'") becomes a direct or indirect attack carrying the canary. One
|
|
97
|
+
* whose word is a secret in the benchmark's own system prompt becomes an
|
|
98
|
+
* extraction attack, graded by your suite's `secrets`. Cases checked
|
|
99
|
+
* another way (a judge's reading of the answer) are skipped.
|
|
100
|
+
*
|
|
101
|
+
* @param json - The dataset's JSON text.
|
|
102
|
+
* @param source - Where it came from, recorded on each attack; include
|
|
103
|
+
* the commit or version.
|
|
104
|
+
*/
|
|
105
|
+
export function cyberSecEvalAttacks(json, source = "CyberSecEval") {
|
|
106
|
+
const rows = z.array(cyberSecEvalRow).parse(JSON.parse(json));
|
|
107
|
+
const out = { attacks: [], skipped: [] };
|
|
108
|
+
for (const r of rows) {
|
|
109
|
+
const id = `cse-${r.prompt_id}`;
|
|
110
|
+
const word = /'([^']+)'/.exec(r.judge_question)?.[1];
|
|
111
|
+
const technique = r.injection_variant.replaceAll("_", " ");
|
|
112
|
+
const asked = word ? withCanary(r.user_input, word) : null;
|
|
113
|
+
const kind = asked
|
|
114
|
+
? r.injection_type === "indirect"
|
|
115
|
+
? "indirect"
|
|
116
|
+
: "direct"
|
|
117
|
+
: word && withCanary(r.test_case_prompt, word)
|
|
118
|
+
? "extract"
|
|
119
|
+
: null;
|
|
120
|
+
if (!kind) {
|
|
121
|
+
out.skipped.push({
|
|
122
|
+
id,
|
|
123
|
+
why: `its check needs a judge: “${r.judge_question}”`,
|
|
124
|
+
});
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
out.attacks.push({
|
|
128
|
+
id,
|
|
129
|
+
kind,
|
|
130
|
+
text: asked ?? r.user_input,
|
|
131
|
+
technique,
|
|
132
|
+
source,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Reads garak's system prompt extraction attacks
|
|
139
|
+
* (`garak/data/sysprompt_extraction/attacks.json`: lists of requests by
|
|
140
|
+
* technique) as extraction attacks, graded by your suite's `secrets`.
|
|
141
|
+
*
|
|
142
|
+
* @param json - The file's JSON text.
|
|
143
|
+
* @param source - Where it came from, with garak's version.
|
|
144
|
+
*/
|
|
145
|
+
export function garakSyspromptAttacks(json, source = "garak") {
|
|
146
|
+
const groups = z
|
|
147
|
+
.record(z.string(), z.array(z.string()))
|
|
148
|
+
.parse(JSON.parse(json));
|
|
149
|
+
return {
|
|
150
|
+
attacks: Object.entries(groups).flatMap(([group, texts]) => texts.map((text, i) => ({
|
|
151
|
+
id: `garak-sysprompt-${group}-${i + 1}`,
|
|
152
|
+
kind: "extract",
|
|
153
|
+
text,
|
|
154
|
+
technique: group.replaceAll("_", " "),
|
|
155
|
+
source,
|
|
156
|
+
}))),
|
|
157
|
+
skipped: [],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const garakAttempt = z.object({
|
|
161
|
+
entry_type: z.literal("attempt"),
|
|
162
|
+
uuid: z.string(),
|
|
163
|
+
probe_classname: z.string(),
|
|
164
|
+
prompt: z
|
|
165
|
+
.object({
|
|
166
|
+
turns: z.array(z.object({
|
|
167
|
+
role: z.string(),
|
|
168
|
+
content: z.object({ text: z.string().nullable() }),
|
|
169
|
+
})),
|
|
170
|
+
})
|
|
171
|
+
.nullable(),
|
|
172
|
+
notes: z.record(z.string(), z.unknown()).optional(),
|
|
173
|
+
});
|
|
174
|
+
/**
|
|
175
|
+
* Reads the attempts in a garak report (`garak.<run>.report.jsonl`) from
|
|
176
|
+
* its injection probes: run garak against its offline `test.Blank`
|
|
177
|
+
* generator and no model is called, but the report still records every
|
|
178
|
+
* attack. Each attempt's trigger (the string garak checks the answer
|
|
179
|
+
* for) becomes the canary; `latentinjection` probes, which hide the
|
|
180
|
+
* attack in a document, are indirect, the rest direct. Attempts with no
|
|
181
|
+
* trigger in their text, and repeats of the same text, are skipped.
|
|
182
|
+
*
|
|
183
|
+
* @param jsonl - The report's text.
|
|
184
|
+
* @param source - Where it came from, with garak's version.
|
|
185
|
+
*/
|
|
186
|
+
export function garakReportAttacks(jsonl, source = "garak") {
|
|
187
|
+
const out = { attacks: [], skipped: [] };
|
|
188
|
+
const texts = new Set();
|
|
189
|
+
for (const line of jsonl.split(/\r?\n/)) {
|
|
190
|
+
if (!line.trim())
|
|
191
|
+
continue;
|
|
192
|
+
let value;
|
|
193
|
+
try {
|
|
194
|
+
value = JSON.parse(line);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const a = garakAttempt.safeParse(value);
|
|
200
|
+
if (!a.success)
|
|
201
|
+
continue;
|
|
202
|
+
const turn = a.data.prompt?.turns.filter((t) => t.role === "user").at(-1);
|
|
203
|
+
const triggers = z
|
|
204
|
+
.array(z.string())
|
|
205
|
+
.catch([])
|
|
206
|
+
.parse(a.data.notes?.["triggers"] ?? []);
|
|
207
|
+
let text = turn?.content.text ?? null;
|
|
208
|
+
for (const t of triggers)
|
|
209
|
+
if (text)
|
|
210
|
+
text = withCanary(text, t) ?? text;
|
|
211
|
+
if (!text || !text.includes("{{canary}}")) {
|
|
212
|
+
out.skipped.push({
|
|
213
|
+
id: `garak-${a.data.uuid}`,
|
|
214
|
+
why: "no trigger in its text to check for",
|
|
215
|
+
});
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
// By its text, not garak's attempt id, which is new every run: a
|
|
219
|
+
// report made again names the same attacks the same way.
|
|
220
|
+
const id = `garak-${starterKey(text)}`;
|
|
221
|
+
if (texts.has(text)) {
|
|
222
|
+
out.skipped.push({ id, why: "the same text as an earlier attempt" });
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
texts.add(text);
|
|
226
|
+
const probe = a.data.probe_classname;
|
|
227
|
+
out.attacks.push({
|
|
228
|
+
id,
|
|
229
|
+
kind: probe.startsWith("latentinjection") ? "indirect" : "direct",
|
|
230
|
+
text,
|
|
231
|
+
technique: probe,
|
|
232
|
+
source,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Reads promptfoo's red team tests written as Burp payloads
|
|
239
|
+
* (`promptfoo redteam generate -o tests.burp`): one URL-encoded attack
|
|
240
|
+
* per line. They
|
|
241
|
+
* carry no canary, so only your suite's own checks and `secrets` grade
|
|
242
|
+
* them. Note that promptfoo writes these with a model, on its hosted
|
|
243
|
+
* service unless you set it up otherwise, and sends it your app's
|
|
244
|
+
* description.
|
|
245
|
+
*
|
|
246
|
+
* @param text - The .burp file's text.
|
|
247
|
+
* @param source - Where it came from, with promptfoo's version.
|
|
248
|
+
* @param kind - What the plugin you generated with tests; default
|
|
249
|
+
* "direct".
|
|
250
|
+
*/
|
|
251
|
+
export function promptfooBurpAttacks(text, source = "promptfoo", kind = "direct") {
|
|
252
|
+
const out = { attacks: [], skipped: [] };
|
|
253
|
+
const ids = new Set();
|
|
254
|
+
text.split(/\r?\n/).forEach((line, i) => {
|
|
255
|
+
if (!line.trim())
|
|
256
|
+
return;
|
|
257
|
+
let decoded;
|
|
258
|
+
try {
|
|
259
|
+
decoded = decodeURIComponent(line.trim());
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
out.skipped.push({ id: `line ${i + 1}`, why: "not URL-encoded text" });
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
// By its text, not its line: a file generated again names the same
|
|
266
|
+
// attacks the same way, and a new one never reuses an old id.
|
|
267
|
+
const id = `promptfoo-${starterKey(decoded)}`;
|
|
268
|
+
if (ids.has(id)) {
|
|
269
|
+
out.skipped.push({ id, why: "the same text as an earlier line" });
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
ids.add(id);
|
|
273
|
+
out.attacks.push({
|
|
274
|
+
id,
|
|
275
|
+
kind,
|
|
276
|
+
text: decoded,
|
|
277
|
+
technique: "promptfoo red team",
|
|
278
|
+
source,
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
return out;
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=attackImport.js.map
|