quantcheck 0.0.1__py3-none-any.whl
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.
- quantcheck/__init__.py +3 -0
- quantcheck/auth/__init__.py +6 -0
- quantcheck/auth/base.py +74 -0
- quantcheck/auth/callback.py +73 -0
- quantcheck/auth/fake.py +40 -0
- quantcheck/auth/service.py +49 -0
- quantcheck/auth/store.py +63 -0
- quantcheck/auth/supabase.py +168 -0
- quantcheck/bench.py +38 -0
- quantcheck/candidates.py +138 -0
- quantcheck/cli.py +251 -0
- quantcheck/config.py +63 -0
- quantcheck/executors/__init__.py +0 -0
- quantcheck/hardware.py +52 -0
- quantcheck/limits.py +19 -0
- quantcheck/pipeline.py +172 -0
- quantcheck/prompt.py +67 -0
- quantcheck/recommend.py +131 -0
- quantcheck/report/__init__.py +0 -0
- quantcheck/report/html.py +38 -0
- quantcheck/report/templates/report.html.j2 +272 -0
- quantcheck/report/terminal.py +90 -0
- quantcheck/report/tokens.py +41 -0
- quantcheck/report/view.py +161 -0
- quantcheck/runners/__init__.py +3 -0
- quantcheck/runners/base.py +87 -0
- quantcheck/runners/fake.py +68 -0
- quantcheck/runners/llamacpp_runner.py +185 -0
- quantcheck/runners/mlx_runner.py +153 -0
- quantcheck/runners/toolparse.py +107 -0
- quantcheck/scoring/__init__.py +0 -0
- quantcheck/scoring/checks.py +342 -0
- quantcheck/scoring/fake_judge.py +50 -0
- quantcheck/scoring/judge.py +171 -0
- quantcheck/scoring/language.py +99 -0
- quantcheck/scoring/models.py +92 -0
- quantcheck/scoring/score.py +167 -0
- quantcheck/scoring/stats.py +60 -0
- quantcheck/settings.py +14 -0
- quantcheck/store.py +88 -0
- quantcheck/tests_io.py +169 -0
- quantcheck/ui/__init__.py +1 -0
- quantcheck/ui/app.py +534 -0
- quantcheck/ui/catalog.py +47 -0
- quantcheck/ui/chat.py +211 -0
- quantcheck/ui/compare.py +63 -0
- quantcheck/ui/downloads.py +172 -0
- quantcheck/ui/jobs.py +173 -0
- quantcheck/ui/modeldetail.py +97 -0
- quantcheck/ui/reviews.py +59 -0
- quantcheck/ui/security.py +45 -0
- quantcheck/ui/static/chat.js +312 -0
- quantcheck/ui/static/fonts/JetBrainsMono-latin-b87346.woff2 +0 -0
- quantcheck/ui/static/fonts/JetBrainsMono-latin-ext-9326b4.woff2 +0 -0
- quantcheck/ui/static/fonts/NotoSansDevanagari-devanagari-3819bb.woff2 +0 -0
- quantcheck/ui/static/fonts/NotoSansDevanagari-latin-ext-542103.woff2 +0 -0
- quantcheck/ui/static/fonts/NotoSansDevanagari-latin-f3aaed.woff2 +0 -0
- quantcheck/ui/static/fonts/NotoSansTamil-latin-17e6dc.woff2 +0 -0
- quantcheck/ui/static/fonts/NotoSansTamil-latin-ext-027c12.woff2 +0 -0
- quantcheck/ui/static/fonts/NotoSansTamil-tamil-a57d5e.woff2 +0 -0
- quantcheck/ui/static/fonts/Outfit-latin-ebadd8.woff2 +0 -0
- quantcheck/ui/static/fonts/Outfit-latin-ext-744997.woff2 +0 -0
- quantcheck/ui/static/fonts/README.md +14 -0
- quantcheck/ui/static/fonts.css +228 -0
- quantcheck/ui/static/index.html +24 -0
- quantcheck/ui/static/lab.css +768 -0
- quantcheck/ui/static/lab.js +896 -0
- quantcheck/ui/static/logo.svg +5 -0
- quantcheck/ui/static/review.js +127 -0
- quantcheck/ui/static/setup.js +132 -0
- quantcheck/ui/static/testsets.js +527 -0
- quantcheck/ui/summary.py +104 -0
- quantcheck/ui/system.py +101 -0
- quantcheck/ui/testsets.py +243 -0
- quantcheck-0.0.1.dist-info/METADATA +115 -0
- quantcheck-0.0.1.dist-info/RECORD +79 -0
- quantcheck-0.0.1.dist-info/WHEEL +4 -0
- quantcheck-0.0.1.dist-info/entry_points.txt +2 -0
- quantcheck-0.0.1.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
/* Test sets screen + guided "Set up your test". Uses helpers from lab.js (h, api, shell, mount).
|
|
2
|
+
Loaded before lab.js; everything here runs only when a route calls it. */
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const NAME_OK = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;
|
|
6
|
+
let setsHelp = null;
|
|
7
|
+
const loadHelp = async () => (setsHelp = setsHelp || (await api("/api/testsets/help")));
|
|
8
|
+
const clone = (o) => JSON.parse(JSON.stringify(o));
|
|
9
|
+
const when = (ts) => new Date(ts * 1000).toLocaleDateString();
|
|
10
|
+
|
|
11
|
+
// ---- list ------------------------------------------------------------------------------
|
|
12
|
+
async function screenSets(arg) {
|
|
13
|
+
const body = h("div", { class: "ts-wrap" }, h("p", { class: "muted", text: "Loading…" }));
|
|
14
|
+
mount(shell("Test sets", body, "#/sets", null, { compact: true }));
|
|
15
|
+
let rows, help;
|
|
16
|
+
try { [rows, help] = await Promise.all([api("/api/testsets"), loadHelp()]); }
|
|
17
|
+
catch (e) { body.replaceChildren(h("div", { class: "notice fail", text: e.message })); return; }
|
|
18
|
+
if (!rows.length) {
|
|
19
|
+
body.replaceChildren(emptyCard(ICONS.sets, "Add your first prompts", "Paste a few real questions, upload a text file, or start from the example. Each step has an example you can load.",
|
|
20
|
+
[h("a", { class: "btn primary", href: "#/sets/new", text: "Guided setup" })]));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const st = { cur: null, data: null, sel: 0, tag: "", shown: 50, timer: null, saving: "", seq: 0 };
|
|
24
|
+
const enc = encodeURIComponent;
|
|
25
|
+
const listBox = h("nav", { class: "card ts-list", "aria-label": "Your sets" });
|
|
26
|
+
const mid = h("section", { class: "card ts-mid" });
|
|
27
|
+
const side = h("aside", { class: "card ts-edit" });
|
|
28
|
+
const savedNote = h("span", { class: "mono mu ts-saved" });
|
|
29
|
+
|
|
30
|
+
const ckText = (k) => {
|
|
31
|
+
const v = k.value;
|
|
32
|
+
const val = v === undefined || v === null ? "" : typeof v === "object" && !Array.isArray(v) ? "" : Array.isArray(v) ? v.join(", ") : String(v);
|
|
33
|
+
return val ? `${k.type}: ${val}` : k.type;
|
|
34
|
+
};
|
|
35
|
+
const cases = () => (st.data ? st.data.cases : []);
|
|
36
|
+
const cur = () => cases()[Math.min(st.sel, cases().length - 1)];
|
|
37
|
+
const noChecks = () => cases().filter((c) => !(c.checks || []).length);
|
|
38
|
+
const tagCounts = () => { const m = new Map(); for (const c of cases()) for (const t of c.tags || []) m.set(t, (m.get(t) || 0) + 1); return [...m.entries()].sort((a, b) => b[1] - a[1]); };
|
|
39
|
+
const visible = () => cases().filter((c) => st.tag === "" ? true : st.tag === "__none__" ? !(c.checks || []).length : (c.tags || []).includes(st.tag));
|
|
40
|
+
|
|
41
|
+
function scheduleSave() {
|
|
42
|
+
clearTimeout(st.timer); savedNote.textContent = "saving…"; savedNote.classList.remove("bad");
|
|
43
|
+
st.timer = setTimeout(save, 600);
|
|
44
|
+
}
|
|
45
|
+
async function save() {
|
|
46
|
+
const my = ++st.seq;
|
|
47
|
+
try {
|
|
48
|
+
const r = await api(`/api/testsets/${enc(st.cur)}`, { method: "PUT", body: { header: { system: st.data.header.system || "", tools: st.data.header.tools || [] }, cases: st.data.cases } });
|
|
49
|
+
if (my !== st.seq) return;
|
|
50
|
+
const i = rows.findIndex((x) => x.name === st.cur); if (i >= 0) rows[i] = r;
|
|
51
|
+
savedNote.textContent = "auto-saved"; savedNote.classList.remove("bad"); drawList();
|
|
52
|
+
} catch (e) { if (my === st.seq) { savedNote.textContent = `not saved: ${e.message}`; savedNote.classList.add("bad"); } }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function drawList() {
|
|
56
|
+
listBox.replaceChildren(h("span", { class: "lbl ts-pad", text: "Your sets" }),
|
|
57
|
+
...rows.map((r) => h("a", { href: `#/sets/${enc(r.name)}`, class: `ts-item ${r.name === st.cur ? "on" : ""}`, "aria-current": r.name === st.cur ? "page" : false },
|
|
58
|
+
h("span", { text: r.name }), h("span", { class: "mono mu ts-n", text: r.error ? "!" : String(r.prompts) }))),
|
|
59
|
+
h("a", { href: "#/sets/new", class: "ts-new" }, svgEl(["M12 5v14M5 12h14"], "ico"), "New set"));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function drawMid() {
|
|
63
|
+
const d = st.data, hd = d.header, tags = tagCounts(), vis = visible(), none = noChecks().length;
|
|
64
|
+
const sys = (hd.system || "").trim();
|
|
65
|
+
const docs = cases().reduce((a, c) => a + (c.context || []).length, 0);
|
|
66
|
+
const chip = (key, text, cls) => h("button", { type: "button", class: `chip nodot ${cls || ""} ${st.tag === key ? "on" : ""}`, "aria-pressed": String(st.tag === key), onclick: () => { st.tag = key; st.shown = 50; drawMid(); } }, text);
|
|
67
|
+
mid.replaceChildren(
|
|
68
|
+
h("div", { class: "ts-head" }, h("div", {}, h("h2", { text: st.cur }), h("span", { class: "mu ts-sub", text: `${cases().length} prompt${cases().length === 1 ? "" : "s"} · saved as ${st.cur}.jsonl` })),
|
|
69
|
+
h("div", { class: "ts-actions" },
|
|
70
|
+
h("a", { class: "btn", href: `#/new/${enc(st.cur + ".jsonl")}`, text: "Use in a test" }),
|
|
71
|
+
h("a", { class: "btn", href: `#/sets/edit/${enc(st.cur)}`, text: "Set up step by step" }),
|
|
72
|
+
h("button", { class: "btn", type: "button", text: "Duplicate", onclick: async () => { try { const r = await api(`/api/testsets/${enc(st.cur)}/duplicate`, { method: "POST" }); location.hash = `#/sets/${enc(r.name)}`; } catch (e) { alert(e.message); } } }),
|
|
73
|
+
h("button", { class: "btn", type: "button", text: "Delete", onclick: async () => { if (!confirm(`Delete ${st.cur}.jsonl? This cannot be undone.`)) return; try { await api(`/api/testsets/${enc(st.cur)}`, { method: "DELETE" }); location.hash = "#/sets"; screenSets(""); } catch (e) { alert(e.message); } } }),
|
|
74
|
+
h("button", { class: "btn", type: "button", onclick: addPrompt }, svgEl(["M12 5v14M5 12h14"], "ico"), "Add prompt"))),
|
|
75
|
+
h("div", { class: "ts-sent" }, h("div", { class: "ts-sent-h" }, h("b", { text: "Sent with every prompt" }), h("span", { class: "mu", text: "· exactly as your app sends it" })),
|
|
76
|
+
h("div", { class: "ts-sent-g" },
|
|
77
|
+
h("span", { class: "lbl", text: "Instructions" }), h("span", { class: "ts-ell", text: sys ? (sys.length > 110 ? sys.slice(0, 110) + "…" : sys) : "None. Add the rules your app sends." }), h("a", { href: `#/sets/edit/${enc(st.cur)}`, text: "Edit" }),
|
|
78
|
+
h("span", { class: "lbl", text: "Documents" }), h("span", {}, docs ? `${docs} document${docs === 1 ? "" : "s"} attached across the prompts` : "None attached"), h("a", { href: `#/sets/edit/${enc(st.cur)}`, text: "Edit" }),
|
|
79
|
+
h("span", { class: "lbl", text: "Tools" }), h("span", { class: "ts-tools" }, (hd.tools || []).length ? hd.tools.map((t) => h("span", { class: "chip nodot mono ts-tool", text: `${t.name}(${Object.keys((t.parameters || {}).properties || {}).join(", ")})` })) : "None"), h("a", { href: `#/sets/edit/${enc(st.cur)}`, text: "Edit" }))),
|
|
80
|
+
h("div", { class: "ts-chips" }, chip("", `All ${cases().length}`, "dark"), ...tags.slice(0, 10).map(([t, n]) => chip(t, `${t} ${n}`)), none ? chip("__none__", `No checks · ${none}`, "amber") : null),
|
|
81
|
+
h("div", { class: "ts-tw" }, h("table", { class: "ts-tbl" }, h("thead", {}, h("tr", {}, h("th", { text: "ID" }), h("th", { text: "Prompt and tags" }), h("th", { text: "Checks" }))),
|
|
82
|
+
h("tbody", {}, vis.slice(0, st.shown).map((c) => { const idx = cases().indexOf(c); return h("tr", { class: idx === st.sel ? "on" : "", tabindex: "0", onclick: () => select(idx), onkeydown: (e) => { if (e.key === "Enter") select(idx); } },
|
|
83
|
+
h("td", { class: "mono mu ts-id", text: c.id }),
|
|
84
|
+
h("td", {}, h("div", { class: "ts-p", text: c.prompt }), h("div", { class: "mu ts-t", text: (c.tags || []).join(" · ") })),
|
|
85
|
+
h("td", {}, h("span", { class: "ts-cks" }, (c.checks || []).length ? c.checks.map((k) => h("span", { class: "chip nodot mono ts-ck", text: ckText(k) })) : h("span", { class: "mu ts-t", text: "none" })))); }))),
|
|
86
|
+
vis.length ? null : h("p", { class: "mu", style: "padding:16px 20px", text: "No prompts match." })),
|
|
87
|
+
h("div", { class: "ts-foot mu" }, `Showing ${Math.min(st.shown, vis.length)} of ${vis.length}`, vis.length > st.shown ? h("button", { class: "btn", type: "button", text: "Show more", onclick: () => { st.shown += 50; drawMid(); } }) : null));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function select(i) { st.sel = i; drawMid(); drawSide(); }
|
|
91
|
+
function addPrompt() {
|
|
92
|
+
const ids = new Set(cases().map((c) => c.id)); let n = cases().length + 1;
|
|
93
|
+
while (ids.has(`p-${String(n).padStart(3, "0")}`)) n++;
|
|
94
|
+
st.data.cases.push({ id: `p-${String(n).padStart(3, "0")}`, prompt: "" }); st.tag = ""; st.shown = Math.max(st.shown, cases().length);
|
|
95
|
+
st.sel = cases().length - 1; drawMid(); drawSide(); scheduleSave();
|
|
96
|
+
side.querySelector("textarea")?.focus();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const area = (value, rows, label, onInput) => { const t = h("textarea", { rows: String(rows), "aria-label": label, class: "ts-ta" }); t.value = value || ""; t.addEventListener("input", () => onInput(t.value)); return t; };
|
|
100
|
+
function drawSide() {
|
|
101
|
+
const c = cur();
|
|
102
|
+
if (!c) { side.replaceChildren(h("p", { class: "mu", text: "No prompts yet. Use Add prompt." })); return; }
|
|
103
|
+
const touch = () => { scheduleSave(); };
|
|
104
|
+
const docs = c.context || [];
|
|
105
|
+
const kinds = help.checks;
|
|
106
|
+
const used = new Set((c.checks || []).map((k) => k.type));
|
|
107
|
+
const what = (t) => (kinds.find((k) => k.type === t) || {}).what || "";
|
|
108
|
+
const pick = h("select", { "aria-label": "Add a check" }, h("option", { value: "", text: "Add check…" }), ...kinds.filter((k) => !used.has(k.type)).map((k) => h("option", { value: k.type, text: `${k.type}: ${k.what}` })));
|
|
109
|
+
const val = h("input", { type: "text", "aria-label": "Check value", placeholder: "value", hidden: true });
|
|
110
|
+
pick.addEventListener("change", () => { const k = kinds.find((x) => x.type === pick.value); val.hidden = !k || k.value === "none" || k.type === "json_schema"; val.placeholder = k ? k.value : "value"; if (k && val.hidden) addCheck(); });
|
|
111
|
+
val.addEventListener("keydown", (e) => { if (e.key === "Enter") addCheck(); });
|
|
112
|
+
function addCheck() {
|
|
113
|
+
const t = pick.value; if (!t) return;
|
|
114
|
+
let spec = { type: t };
|
|
115
|
+
if (t === "language") spec.value = (val.value || "en").trim();
|
|
116
|
+
else if (t.endsWith("length")) spec.value = Number(val.value) || 1;
|
|
117
|
+
else if (["contains", "not_contains"].includes(t)) spec.value = val.value.includes(",") ? val.value.split(",").map((s) => s.trim()).filter(Boolean) : val.value;
|
|
118
|
+
else if (t === "regex") spec.value = val.value;
|
|
119
|
+
else if (t === "json_schema") spec.value = { type: "object" };
|
|
120
|
+
c.checks = [...(c.checks || []), spec]; touch(); drawSide(); drawMid();
|
|
121
|
+
}
|
|
122
|
+
side.replaceChildren(
|
|
123
|
+
h("div", { class: "ts-eh" }, h("h2", { text: `Edit ${c.id}` }), savedNote),
|
|
124
|
+
h("label", { class: "ts-f" }, "Prompt", area(c.prompt, 3, "Prompt", (v) => { c.prompt = v; touch(); })),
|
|
125
|
+
h("div", { class: "ts-f" }, h("span", { class: "ts-row" }, "Documents sent with this prompt", h("button", { class: "ts-link", type: "button", text: "Add", onclick: () => { c.context = [...docs, ""]; touch(); drawSide(); } })),
|
|
126
|
+
...(docs.length ? docs.map((dtext, i) => h("div", { class: "ts-doc" }, area(dtext, 2, `Document ${i + 1}`, (v) => { c.context[i] = v; touch(); }),
|
|
127
|
+
h("button", { class: "ts-link", type: "button", text: "Remove", onclick: () => { c.context = docs.filter((_, j) => j !== i); touch(); drawSide(); drawMid(); } }))) : [h("span", { class: "mu ts-t", text: "None. The model gets only the question." })])),
|
|
128
|
+
h("label", { class: "ts-f" }, "Expected answer (optional)", area(c.expected || "", 2, "Expected answer", (v) => { c.expected = v || null; touch(); })),
|
|
129
|
+
h("div", { class: "ts-f" }, h("span", { text: "Checks · run before the judge" }),
|
|
130
|
+
...(c.checks || []).map((k, i) => h("div", { class: "ts-chk" }, h("span", { class: "ts-row" }, h("b", { text: k.type }), h("span", { class: "mono ts-v", text: ckText(k).replace(/^[^:]+:?\s?/, "") }),
|
|
131
|
+
h("button", { class: "ts-x", type: "button", "aria-label": `Remove ${k.type} check`, onclick: () => { c.checks = c.checks.filter((_, j) => j !== i); touch(); drawSide(); drawMid(); } }, svgEl(["M6 6l12 12M18 6L6 18"], "ico"))),
|
|
132
|
+
h("span", { class: "mu ts-t", text: what(k.type) }))),
|
|
133
|
+
h("div", { class: "ts-addrow" }, pick, val, h("button", { class: "btn", type: "button", text: "Add", onclick: addCheck }))),
|
|
134
|
+
h("div", { class: "ts-judge", text: "The judge then scores meaning against the reference answer, 0–10. Checks that fail score 0 first." }),
|
|
135
|
+
cases().length > 1 ? h("button", { class: "btn", type: "button", text: "Delete this prompt", onclick: () => { if (!confirm(`Delete prompt ${c.id}?`)) return; st.data.cases.splice(st.sel, 1); st.sel = Math.max(0, st.sel - 1); scheduleSave(); drawMid(); drawSide(); } }) : null);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function open(name) {
|
|
139
|
+
st.cur = name; drawList();
|
|
140
|
+
mid.replaceChildren(h("p", { class: "muted", style: "padding:20px", text: "Loading…" }));
|
|
141
|
+
try { st.data = await api(`/api/testsets/${enc(name)}`); st.sel = 0; st.tag = ""; st.shown = 50; savedNote.textContent = ""; drawMid(); drawSide(); }
|
|
142
|
+
catch (e) { mid.replaceChildren(h("div", { class: "notice fail", style: "margin:20px", text: e.message }), h("a", { class: "btn", style: "margin:0 20px 20px", href: `#/sets/edit/${enc(name)}`, text: "Open in the step-by-step editor" })); side.replaceChildren(); }
|
|
143
|
+
}
|
|
144
|
+
body.replaceChildren(h("div", { class: "ts-grid" }, listBox, mid, side));
|
|
145
|
+
const first = rows.find((r) => r.name === arg) || rows.find((r) => !r.error) || rows[0];
|
|
146
|
+
open(first.name);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ---- guided editor ---------------------------------------------------------------------
|
|
150
|
+
const STEPS = [
|
|
151
|
+
["instructions", "Instructions"], ["documents", "Documents"], ["tools", "Tools"], ["prompts", "Prompts"], ["checks", "Checks"],
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
const STEP_META = {
|
|
155
|
+
instructions: { title: "Instructions (system prompt)", sub: "Rules sent every time",
|
|
156
|
+
desc: "The fixed rules your app sends with every question: who the assistant is, tone, language, what it must never do. Smaller models often start ignoring these first, for example replying in English when told to match the customer.",
|
|
157
|
+
ways: [["Import from app logs", "Taken from the first message of your real conversations", "later"], ["Paste it", "Copy the system prompt from your code", "paste"], ["Use the example", "A support assistant you can edit", "example"]],
|
|
158
|
+
tips: [["x", "\u201cBe helpful and nice.\u201d: too vague to test"], ["ok", "\u201cReply in the customer's language.\u201d: clear, and becomes a language check"], ["x", "Different instructions in testing and in production"], ["ok", "Paste the exact text your app sends today, word for word"]] },
|
|
159
|
+
documents: { title: "Documents (your knowledge)", sub: "Your knowledge",
|
|
160
|
+
desc: "The model doesn't know your company. Your app looks up the right help pages for each question and adds them to the prompt (often called RAG). We test whether the smaller model still uses them and doesn't make things up.",
|
|
161
|
+
ways: [["Import from app logs", "Keeps the exact documents your app found for each question. Most realistic", "later"], ["Upload files", "Text or Markdown files. PDF and Word come later", "upload"], ["Use the example", "Three short policy passages", "example"]],
|
|
162
|
+
tips: [["ok", "Use the same documents your app retrieves, not a cleaned-up copy"], ["ok", "Include a few questions the documents do NOT answer, to test \u201cI don't know\u201d"], ["x", "Pasting your whole help centre into every prompt"], ["x", "Customer names, phone numbers or addresses in documents: leave them out if you can"]] },
|
|
163
|
+
tools: { title: "Tools (actions the model can ask for)", sub: "Actions the model can ask for",
|
|
164
|
+
desc: "Tools let the model ask your app to do something: look up an order, cancel it, check a refund. You give us only the descriptions, never your code or keys. Tools are never called during tests: we check which tool the model picked and its inputs, then play back a recorded result.",
|
|
165
|
+
ways: [["Import from app logs", "The tool list and real results are already in your logs", "later"], ["Add one by hand", "Name, description and arguments", "paste"], ["Use the example", "get_order_status and cancel_order", "example"]],
|
|
166
|
+
tips: [["x", "\"description\": \"orders\""], ["ok", "\"description\": \"Get the delivery status of an order. Use when the customer asks where it is.\""], ["ok", "Mark tools that change data (cancel, refund). We never call any tool, but we flag these"], ["x", "Putting API keys or passwords in tool descriptions"]] },
|
|
167
|
+
prompts: { title: "Prompts (your test questions)", sub: "Real questions + answers",
|
|
168
|
+
desc: "Real questions your customers ask, each with what a good answer looks like. These are what every model version is tested on, so they matter most. 100\u2013200 is enough for a clear decision. 20 is enough to start.",
|
|
169
|
+
ways: [["Import from app logs", "Real questions, with context and answers already attached", "later"], ["Paste many", "One question per line, any language", "paste"], ["Use the example", "Four mixed-language prompts", "example"]],
|
|
170
|
+
tips: [["ok", "Use real customer questions, in the languages they really use"], ["ok", "Include hard cases: angry customers, two questions at once, things you don't sell"], ["x", "Only easy questions. Every version passes them, so they teach you nothing"], ["ok", "Take expected answers from your policy, not from the model you are testing"]] },
|
|
171
|
+
checks: { title: "Checks (automatic pass / fail)", sub: "Automatic pass / fail",
|
|
172
|
+
desc: "Rules that run on every answer before the judge. A failed check scores 0 for that prompt, so a smaller model can't hide a broken answer behind a good average. Most prompts need 2 or 3 checks.",
|
|
173
|
+
ways: [["Pick per prompt", "Tick the checks below for the prompt chosen on the right", "paste"], ["Copy to the whole set", "Apply one prompt's checks to every prompt", "copy"]],
|
|
174
|
+
tips: [["ok", "Turn each rule in your instructions into a check: language, length, \u201cnever share\u2026\u201d"], ["ok", "Add a tool_call check to every prompt that should use a tool"], ["x", "Relying only on the judge score. Checks catch hard failures it can miss"], ["x", "Exact-match checks on free text. Use \u201cmust contain\u201d for the key fact instead"]] },
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
async function screenSetEditor(arg) {
|
|
178
|
+
const body = h("div", {}, h("p", { class: "muted", text: "Loading…" }));
|
|
179
|
+
mount(shell("Set up your test", body, "#/sets"));
|
|
180
|
+
let help, existing = null;
|
|
181
|
+
try {
|
|
182
|
+
help = await loadHelp();
|
|
183
|
+
if (arg && arg !== "new") existing = await api(`/api/testsets/${encodeURIComponent(arg)}`);
|
|
184
|
+
} catch (e) { body.replaceChildren(h("div", { class: "notice fail", text: e.message }), h("a", { class: "btn", href: "#/sets", text: "Back to test sets" })); return; }
|
|
185
|
+
|
|
186
|
+
const st = {
|
|
187
|
+
name: existing ? existing.name : "",
|
|
188
|
+
isNew: !existing,
|
|
189
|
+
header: existing ? clone(existing.header) : { system: "", tools: [] },
|
|
190
|
+
cases: existing ? clone(existing.cases) : [{ id: "p-001", prompt: "" }],
|
|
191
|
+
sel: 0, step: "instructions", validTimer: null, seq: 0,
|
|
192
|
+
};
|
|
193
|
+
if (!st.header.tools) st.header.tools = [];
|
|
194
|
+
const cur = () => st.cases[Math.min(st.sel, st.cases.length - 1)];
|
|
195
|
+
|
|
196
|
+
const nameIn = h("input", { type: "text", id: "setname", value: st.name, placeholder: "my-support-bot", autocomplete: "off", "aria-describedby": "namehint" });
|
|
197
|
+
if (!st.isNew) nameIn.disabled = true;
|
|
198
|
+
nameIn.addEventListener("input", () => { st.name = nameIn.value.trim(); });
|
|
199
|
+
const status = h("div", { "aria-live": "polite" });
|
|
200
|
+
const saveBtn = h("button", { class: "btn primary", type: "button", text: "Save", onclick: save });
|
|
201
|
+
const stepBar = h("div", { class: "stepper", role: "tablist", "aria-label": "Steps" });
|
|
202
|
+
const panel = h("div", { class: "su-panel" });
|
|
203
|
+
const selector = h("select", { id: "promptsel", "aria-label": "Prompt to preview" });
|
|
204
|
+
const previewBox = h("div", { class: "preview", "aria-live": "polite" });
|
|
205
|
+
let lastValid = false;
|
|
206
|
+
|
|
207
|
+
const ids = () => st.cases.map((c) => c.id);
|
|
208
|
+
const cleanHeader = () => ({ system: st.header.system || "", tools: st.header.tools });
|
|
209
|
+
|
|
210
|
+
// ---- validation + preview (debounced, server is the source of truth) ----
|
|
211
|
+
function markDirty() {
|
|
212
|
+
clearTimeout(st.validTimer);
|
|
213
|
+
st.validTimer = setTimeout(refresh, 350);
|
|
214
|
+
}
|
|
215
|
+
async function refresh() {
|
|
216
|
+
const my = ++st.seq;
|
|
217
|
+
try {
|
|
218
|
+
const v = await api("/api/testsets/validate", { method: "POST", body: { header: cleanHeader(), cases: st.cases } });
|
|
219
|
+
if (my !== st.seq) return;
|
|
220
|
+
lastValid = v.ok;
|
|
221
|
+
status.replaceChildren(
|
|
222
|
+
v.ok ? h("div", { class: "notice ok", text: `Ready to save: ${st.cases.length} prompt${st.cases.length === 1 ? "" : "s"}, ${st.header.tools.length} tool${st.header.tools.length === 1 ? "" : "s"}.` })
|
|
223
|
+
: h("div", { class: "notice fail", role: "alert", text: v.error }),
|
|
224
|
+
...v.warnings.map((w) => h("div", { class: "notice warn", style: "margin-top:8px", text: w })));
|
|
225
|
+
} catch (e) { status.replaceChildren(h("div", { class: "notice fail", text: e.message })); }
|
|
226
|
+
drawPreview(my);
|
|
227
|
+
}
|
|
228
|
+
async function drawPreview(my) {
|
|
229
|
+
const c = cur();
|
|
230
|
+
try {
|
|
231
|
+
const p = await api("/api/testsets/preview", { method: "POST", body: { header: cleanHeader(), case: { prompt: c.prompt || "", context: c.context || [] } } });
|
|
232
|
+
if (my !== undefined && my !== st.seq) return;
|
|
233
|
+
const pct = Math.min(100, Math.round(p.fraction * 100));
|
|
234
|
+
previewBox.replaceChildren(
|
|
235
|
+
h("h3", { text: "What the model will see" }),
|
|
236
|
+
h("p", { class: "hint", text: "Built by the same code a test run uses. Tools are only described here and are never executed." }),
|
|
237
|
+
...p.messages.map((m) => h("div", { class: "msg" }, h("span", { class: "role", text: m.role }), h("pre", { text: String(m.content) }))),
|
|
238
|
+
p.tools.length ? h("div", { class: "msg" }, h("span", { class: "role", text: `tools (${p.tools.length})` }), h("pre", { text: JSON.stringify(p.tools.map((t) => t.function), null, 2) })) : null,
|
|
239
|
+
h("div", { class: "sizebar" }, h("div", { class: `bar ${p.warning ? "warn" : ""}`, role: "progressbar", "aria-valuenow": String(pct), "aria-valuemin": "0", "aria-valuemax": "100", "aria-label": "Share of the context window used" }, h("i", { style: `width:${pct}%` })),
|
|
240
|
+
h("span", { class: "hint mono", text: `~${p.tokens} of ${p.context_tokens} tokens (${pct}%)` })),
|
|
241
|
+
p.warning && h("div", { class: "notice warn", text: p.warning }));
|
|
242
|
+
} catch (e) { previewBox.replaceChildren(h("h3", { text: "What the model will see" }), h("div", { class: "notice fail", text: e.message })); }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function save() {
|
|
246
|
+
if (!NAME_OK.test(st.name)) { status.replaceChildren(h("div", { class: "notice fail", role: "alert", text: "Give the test set a name first: letters, digits, dash or underscore." })); nameIn.focus(); return; }
|
|
247
|
+
saveBtn.disabled = true;
|
|
248
|
+
try {
|
|
249
|
+
const r = await api(`/api/testsets/${encodeURIComponent(st.name)}`, { method: "PUT", body: { header: cleanHeader(), cases: st.cases } });
|
|
250
|
+
status.replaceChildren(h("div", { class: "notice ok" }, `Saved ${r.file}. `, h("a", { href: `#/new/${encodeURIComponent(r.file)}`, text: "Run a test with it" }), " or ", h("a", { href: "#/sets", text: "back to test sets" }), "."));
|
|
251
|
+
st.isNew = false; nameIn.disabled = true;
|
|
252
|
+
history.replaceState(null, "", `#/sets/edit/${encodeURIComponent(r.name)}`);
|
|
253
|
+
} catch (e) { status.replaceChildren(h("div", { class: "notice fail", role: "alert", text: e.message })); }
|
|
254
|
+
saveBtn.disabled = false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ---- small builders ----
|
|
258
|
+
const tips = (good, bad) => h("div", { class: "tips" },
|
|
259
|
+
h("div", { class: "tip good" }, h("b", { text: "Good" }), h("p", { text: good })),
|
|
260
|
+
h("div", { class: "tip bad" }, h("b", { text: "Avoid" }), h("p", { text: bad })));
|
|
261
|
+
const intro = (what) => h("p", { class: "muted", text: what });
|
|
262
|
+
const exBtn = (label, fn) => h("button", { class: "btn", type: "button", text: label, onclick: () => { fn(); renderPanel(); markDirty(); } });
|
|
263
|
+
const textarea = (value, rows, on, label) => {
|
|
264
|
+
const t = h("textarea", { rows: String(rows), "aria-label": label, spellcheck: "false" }); t.value = value;
|
|
265
|
+
t.addEventListener("input", () => on(t.value)); return t;
|
|
266
|
+
};
|
|
267
|
+
const readFile = (file, cb) => {
|
|
268
|
+
if (file.size > 1_000_000) { alert("That file is over 1 MB. Split it into smaller documents."); return; }
|
|
269
|
+
const fr = new FileReader(); fr.onload = () => cb(String(fr.result)); fr.readAsText(file);
|
|
270
|
+
};
|
|
271
|
+
const fileIn = (label, accept, cb, multiple) => {
|
|
272
|
+
const inp = h("input", { type: "file", accept, multiple: !!multiple, class: "visually-hidden", "aria-label": label });
|
|
273
|
+
inp.addEventListener("change", () => { for (const f of inp.files) readFile(f, (t) => cb(t, f.name)); inp.value = ""; });
|
|
274
|
+
return h("span", {}, h("button", { class: "btn", type: "button", onclick: () => inp.click() }, label), inp);
|
|
275
|
+
};
|
|
276
|
+
const jsonArea = (value, rows, onValid, label) => {
|
|
277
|
+
const err = h("div", { class: "hint err", "aria-live": "polite" });
|
|
278
|
+
const t = textarea(value === undefined ? "" : JSON.stringify(value, null, 2), rows, (txt) => {
|
|
279
|
+
if (!txt.trim()) { err.textContent = ""; onValid(undefined); return; }
|
|
280
|
+
try { onValid(JSON.parse(txt)); err.textContent = ""; } catch (e) { err.textContent = `Not valid JSON yet: ${e.message}`; }
|
|
281
|
+
}, label);
|
|
282
|
+
return h("div", {}, t, err);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// ---- step panels ----
|
|
286
|
+
const panels = {
|
|
287
|
+
instructions() {
|
|
288
|
+
return [
|
|
289
|
+
h("h2", { text: "1. Instructions" }),
|
|
290
|
+
intro("The system prompt your app sends with every question: tone, language, rules. Quantized models most often slip here, by ignoring a rule."),
|
|
291
|
+
textarea(st.header.system || "", 6, (v) => { st.header.system = v; markDirty(); }, "Instructions"),
|
|
292
|
+
h("div", { class: "row" }, exBtn("Load an example", () => { st.header.system = help.examples.system; }),
|
|
293
|
+
fileIn("Upload a .txt file", ".txt,.md,text/plain", (t) => { st.header.system = t; renderPanel(); markDirty(); })),
|
|
294
|
+
tips("Paste exactly what your app sends, including rules such as \"use only the documents\" and \"reply in the customer's language\".",
|
|
295
|
+
"A shortened or cleaned-up version. A test with different instructions proves nothing about your app."),
|
|
296
|
+
];
|
|
297
|
+
},
|
|
298
|
+
documents() {
|
|
299
|
+
const c = cur(); c.context = c.context || [];
|
|
300
|
+
const list = c.context.map((d, i) => h("div", { class: "item" },
|
|
301
|
+
h("div", { class: "row" }, h("b", { text: `Document ${i + 1}` }), h("span", { class: "spacer" }),
|
|
302
|
+
h("button", { class: "btn", type: "button", text: "Remove", onclick: () => { c.context.splice(i, 1); renderPanel(); markDirty(); } })),
|
|
303
|
+
textarea(d, 3, (v) => { c.context[i] = v; markDirty(); }, `Document ${i + 1}`)));
|
|
304
|
+
return [
|
|
305
|
+
h("h2", { text: "2. Documents" }),
|
|
306
|
+
intro("Text your app retrieves (RAG) and puts in the prompt for this question: policies, product pages, FAQs. Each prompt can have its own. The prompt shown is the one chosen above the preview."),
|
|
307
|
+
h("p", {}, h("span", { class: "chip plain", text: `Prompt: ${c.id}` })),
|
|
308
|
+
...list,
|
|
309
|
+
h("div", { class: "row" },
|
|
310
|
+
exBtn("Add empty document", () => { c.context.push(""); }),
|
|
311
|
+
exBtn("Load example documents", () => { c.context = clone(help.examples.documents.slice(0, 2)); }),
|
|
312
|
+
fileIn("Upload .txt / .md files", ".txt,.md,text/plain", (t) => { c.context.push(t); renderPanel(); markDirty(); }, true),
|
|
313
|
+
c.context.length && st.cases.length > 1 && h("button", { class: "btn", type: "button", text: `Copy to all ${st.cases.length} prompts`, onclick: () => { for (const o of st.cases) o.context = clone(c.context); renderPanel(); markDirty(); } })),
|
|
314
|
+
tips("The same kind of text your app retrieves: one short passage per document, as it arrives in production.",
|
|
315
|
+
"Pasting whole manuals. Long documents fill the context window, and the preview warns at 80%. PDF upload comes later: paste the text for now."),
|
|
316
|
+
];
|
|
317
|
+
},
|
|
318
|
+
tools() {
|
|
319
|
+
const tools = st.header.tools;
|
|
320
|
+
const over = tools.length > help.limits.warn_tools;
|
|
321
|
+
const cards = tools.map((t, i) => h("div", { class: "item" },
|
|
322
|
+
h("div", { class: "row" }, h("b", { class: "mono", text: t.name || "(unnamed)" }),
|
|
323
|
+
t.changes_data && h("span", { class: "chip warn", text: "Changes data" }), h("span", { class: "spacer" }),
|
|
324
|
+
h("button", { class: "btn", type: "button", text: "Remove", onclick: () => { tools.splice(i, 1); renderPanel(); markDirty(); } })),
|
|
325
|
+
h("div", { class: "field" }, h("label", { for: `tn${i}`, text: "Name" }),
|
|
326
|
+
(() => { const n = h("input", { type: "text", id: `tn${i}`, value: t.name, autocomplete: "off" }); n.addEventListener("input", () => { t.name = n.value.trim(); markDirty(); }); return n; })()),
|
|
327
|
+
h("div", { class: "field" }, h("label", { for: `td${i}`, text: "What it does" }),
|
|
328
|
+
(() => { const n = h("input", { type: "text", id: `td${i}`, value: t.description || "", autocomplete: "off" }); n.addEventListener("input", () => { t.description = n.value; markDirty(); }); return n; })()),
|
|
329
|
+
h("div", { class: "field" }, h("label", { text: "Arguments (JSON schema)" }),
|
|
330
|
+
jsonArea(t.parameters, 6, (v) => { if (v !== undefined) { t.parameters = v; markDirty(); } }, "Arguments schema")),
|
|
331
|
+
h("label", { class: "check" }, (() => { const c = h("input", { type: "checkbox" }); c.checked = !!t.changes_data; c.addEventListener("change", () => { t.changes_data = c.checked; renderPanel(); }); return c; })(),
|
|
332
|
+
" This tool changes data (cancel, refund, delete)")));
|
|
333
|
+
return [
|
|
334
|
+
h("h2", { text: "3. Tools" }),
|
|
335
|
+
intro("Functions your app lets the model call. QuantCheck never runs them: it only reads the call the model writes (name and arguments) and checks it. Where an answer needs a result, it plays back the recorded result you give in the Prompts step."),
|
|
336
|
+
over && h("div", { class: "notice warn", text: `${tools.length} tools: small models often pick the wrong one.` }),
|
|
337
|
+
...cards,
|
|
338
|
+
h("div", { class: "row" }, exBtn("Add a tool", () => { tools.push({ name: "", description: "", parameters: { type: "object", properties: {} } }); }),
|
|
339
|
+
exBtn("Load example tools", () => { st.header.tools = clone(help.examples.tools); })),
|
|
340
|
+
tips("Copy tool definitions from your app unchanged: same names, same descriptions, same argument schema.",
|
|
341
|
+
"Tools that are not part of your app, or descriptions rewritten to be \"clearer\". Mark anything that changes data so you remember it is only described, never run."),
|
|
342
|
+
];
|
|
343
|
+
},
|
|
344
|
+
prompts() {
|
|
345
|
+
const bulk = h("textarea", { rows: "4", placeholder: "One question per line. Any language.", "aria-label": "Paste questions, one per line", spellcheck: "false" });
|
|
346
|
+
const list = st.cases.map((c, i) => h("div", { class: "item", "aria-current": i === st.sel ? "true" : false },
|
|
347
|
+
h("div", { class: "row" }, h("b", { class: "mono", text: c.id }), h("span", { class: "spacer" }),
|
|
348
|
+
h("button", { class: "btn", type: "button", text: "Preview", onclick: () => { st.sel = i; selector.value = String(i); renderPanel(); drawPreview(); } }),
|
|
349
|
+
h("button", { class: "btn", type: "button", text: "Remove", disabled: st.cases.length === 1, onclick: () => { st.cases.splice(i, 1); st.sel = Math.min(st.sel, st.cases.length - 1); renderPanel(); syncSelector(); markDirty(); } })),
|
|
350
|
+
h("div", { class: "grid2 tight" },
|
|
351
|
+
h("div", { class: "field" }, h("label", { text: "Id" }), (() => { const n = h("input", { type: "text", value: c.id, autocomplete: "off", "aria-label": "Prompt id" }); n.addEventListener("input", () => { c.id = n.value.trim(); syncSelector(); markDirty(); }); return n; })()),
|
|
352
|
+
h("div", { class: "field" }, h("label", { text: "Tags (comma separated)" }), (() => { const n = h("input", { type: "text", value: (c.tags || []).join(", "), autocomplete: "off", "aria-label": "Tags" }); n.addEventListener("input", () => { c.tags = n.value.split(",").map((s) => s.trim()).filter(Boolean); markDirty(); }); return n; })())),
|
|
353
|
+
h("div", { class: "field" }, h("label", { text: "Question" }), textarea(c.prompt || "", 2, (v) => { c.prompt = v; markDirty(); }, "Question")),
|
|
354
|
+
h("div", { class: "field" }, h("label", { text: "Expected answer (optional)" }),
|
|
355
|
+
textarea(c.expected || "", 2, (v) => { if (v) c.expected = v; else delete c.expected; markDirty(); }, "Expected answer"),
|
|
356
|
+
h("span", { class: "hint", text: "Leave empty to compare against the best version instead." })),
|
|
357
|
+
tools_for(c)));
|
|
358
|
+
function tools_for(c) {
|
|
359
|
+
if (!st.header.tools.length) return null;
|
|
360
|
+
const call = c.expected_tool_call;
|
|
361
|
+
const sel = h("select", { "aria-label": "Expected tool" }, h("option", { value: "", text: "No tool call expected" }), st.header.tools.filter((t) => t.name).map((t) => h("option", { value: t.name, text: t.name })));
|
|
362
|
+
sel.value = call ? call.name : "";
|
|
363
|
+
sel.addEventListener("change", () => { if (sel.value) c.expected_tool_call = { name: sel.value, arguments: (call && call.arguments) || {} }; else { delete c.expected_tool_call; delete c.tool_results; } renderPanel(); markDirty(); });
|
|
364
|
+
return h("details", { open: !!call }, h("summary", { text: "Tool call (optional)" }),
|
|
365
|
+
h("div", { class: "field", style: "margin-top:10px" }, h("label", { text: "Model should call" }), sel),
|
|
366
|
+
call && h("div", { class: "field" }, h("label", { text: "With arguments (JSON)" }), jsonArea(call.arguments, 3, (v) => { if (v !== undefined) { c.expected_tool_call.arguments = v; markDirty(); } }, "Expected arguments")),
|
|
367
|
+
call && h("div", { class: "field" }, h("label", { text: "Recorded result to play back (JSON, keyed by tool name)" }),
|
|
368
|
+
jsonArea(c.tool_results, 3, (v) => { if (v === undefined) delete c.tool_results; else c.tool_results = v; markDirty(); }, "Recorded results"),
|
|
369
|
+
h("span", { class: "hint", text: 'Example: {"get_order_status": {"status": "shipped"}}' })));
|
|
370
|
+
}
|
|
371
|
+
const addBulk = () => {
|
|
372
|
+
const lines = bulk.value.split("\n").map((s) => s.trim()).filter(Boolean);
|
|
373
|
+
if (!lines.length) return;
|
|
374
|
+
for (const q of lines) st.cases.push({ id: nextId(), prompt: q });
|
|
375
|
+
renderPanel(); syncSelector(); markDirty();
|
|
376
|
+
};
|
|
377
|
+
return [
|
|
378
|
+
h("h2", { text: "4. Prompts" }),
|
|
379
|
+
intro("The questions your users ask, in the languages they use. Mix languages and include questions the documents cannot answer. 20 or more prompts are needed before a version can be called safe."),
|
|
380
|
+
...list,
|
|
381
|
+
h("div", { class: "row" },
|
|
382
|
+
exBtn("Add a prompt", () => { st.cases.push({ id: nextId(), prompt: "" }); st.sel = st.cases.length - 1; syncSelector(); }),
|
|
383
|
+
exBtn("Load example prompts", () => { st.cases = clone(help.examples.prompts); st.sel = 0; if (!st.header.system) st.header.system = help.examples.system; if (!st.header.tools.length) st.header.tools = clone(help.examples.tools); syncSelector(); })),
|
|
384
|
+
h("details", {}, h("summary", { text: "Paste many questions at once" }),
|
|
385
|
+
h("div", { style: "margin-top:10px;display:grid;gap:8px" }, bulk, h("div", { class: "row" }, h("button", { class: "btn", type: "button", text: "Add them", onclick: addBulk }),
|
|
386
|
+
fileIn("From a .txt file", ".txt,text/plain", (t) => { bulk.value = (bulk.value ? bulk.value + "\n" : "") + t; })))),
|
|
387
|
+
st.cases.length > help.limits.warn_prompts && h("div", { class: "notice warn", text: `${st.cases.length} prompts is a long run; expect a long wait per version.` }),
|
|
388
|
+
tips("Real questions copied from your support logs, in the original language and spelling, plus a few the documents do not cover.",
|
|
389
|
+
"Only easy, clean questions. Every prompt in your own words from one language. Importing from app logs comes in a later version."),
|
|
390
|
+
];
|
|
391
|
+
function nextId() { let n = st.cases.length + 1; while (ids().includes(`p-${String(n).padStart(3, "0")}`)) n++; return `p-${String(n).padStart(3, "0")}`; }
|
|
392
|
+
},
|
|
393
|
+
checks() {
|
|
394
|
+
const c = cur(); c.checks = c.checks || [];
|
|
395
|
+
const find = (t) => c.checks.find((k) => k.type === t);
|
|
396
|
+
const rows = help.checks.map((k) => {
|
|
397
|
+
const on = find(k.type);
|
|
398
|
+
const toggle = h("input", { type: "checkbox", id: `ck-${k.type}`, "aria-describedby": `cd-${k.type}` });
|
|
399
|
+
toggle.checked = !!on;
|
|
400
|
+
toggle.addEventListener("change", () => {
|
|
401
|
+
if (toggle.checked) c.checks.push(k.type === "language" ? { type: k.type, value: "en" } : ["contains", "not_contains", "regex", "json_schema", "min_length", "max_length"].includes(k.type) ? { type: k.type, value: k.type.endsWith("length") ? 1 : k.type === "json_schema" ? { type: "object" } : "" } : { type: k.type });
|
|
402
|
+
else c.checks = c.checks.filter((x) => x.type !== k.type);
|
|
403
|
+
renderPanel(); markDirty();
|
|
404
|
+
});
|
|
405
|
+
return h("div", { class: "check-row" },
|
|
406
|
+
h("label", { class: "check", for: `ck-${k.type}` }, toggle, h("span", {}, h("b", { class: "mono", text: k.type }), h("span", { id: `cd-${k.type}`, class: "hint", style: "display:block", text: k.what }))),
|
|
407
|
+
on && valueEditor(k, on));
|
|
408
|
+
});
|
|
409
|
+
function valueEditor(k, spec) {
|
|
410
|
+
if (k.type === "language") {
|
|
411
|
+
const s = h("select", { "aria-label": "Language" }, help.languages.map((l) => h("option", { value: l, text: l })));
|
|
412
|
+
s.value = spec.value; s.addEventListener("change", () => { spec.value = s.value; markDirty(); }); return s;
|
|
413
|
+
}
|
|
414
|
+
if (k.type === "json_schema") return jsonArea(spec.value, 4, (v) => { if (v !== undefined) { spec.value = v; markDirty(); } }, "JSON schema");
|
|
415
|
+
if (k.type.endsWith("length")) { const n = h("input", { type: "number", min: "0", value: String(spec.value), "aria-label": "Characters" }); n.addEventListener("input", () => { spec.value = Number(n.value); markDirty(); }); return n; }
|
|
416
|
+
if (["contains", "not_contains", "regex"].includes(k.type)) {
|
|
417
|
+
const n = h("input", { type: "text", value: Array.isArray(spec.value) ? spec.value.join(", ") : spec.value || "", placeholder: k.type === "regex" ? "pattern" : "words, comma separated", "aria-label": k.value });
|
|
418
|
+
n.addEventListener("input", () => { spec.value = k.type === "regex" ? n.value : n.value.includes(",") ? n.value.split(",").map((s) => s.trim()).filter(Boolean) : n.value; markDirty(); }); return n;
|
|
419
|
+
}
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
return [
|
|
423
|
+
h("h2", { text: "5. Checks" }),
|
|
424
|
+
intro("Hard yes/no rules. If any check fails, that answer scores zero, however well it reads. Pick the ones that matter for the prompt chosen above."),
|
|
425
|
+
h("p", {}, h("span", { class: "chip plain", text: `Prompt: ${c.id}` })),
|
|
426
|
+
...rows,
|
|
427
|
+
st.cases.length > 1 && c.checks.length > 0 && h("div", { class: "row" }, h("button", { class: "btn", type: "button", text: `Copy these checks to all ${st.cases.length} prompts`, onclick: () => {
|
|
428
|
+
if (confirm("Replace the checks on every prompt with these?")) { for (const o of st.cases) o.checks = clone(c.checks.filter((k) => k.type !== "tool_call" || o.expected_tool_call)); renderPanel(); markDirty(); }
|
|
429
|
+
} })),
|
|
430
|
+
tips("Few, meaningful checks: the right language, valid JSON for extraction prompts, the right tool call, \"refusal\" for questions outside the documents.",
|
|
431
|
+
"Checks on every prompt \"just in case\". tool_call needs an expected tool call in the Prompts step; refusal belongs on questions the documents cannot answer."),
|
|
432
|
+
];
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
const done = (k) => ({
|
|
437
|
+
instructions: !!(st.header.system || "").trim(), documents: st.cases.some((c) => (c.context || []).length), tools: st.header.tools.length > 0,
|
|
438
|
+
prompts: st.cases.length > 0 && st.cases.every((c) => (c.prompt || "").trim()), checks: st.cases.some((c) => (c.checks || []).length),
|
|
439
|
+
})[k];
|
|
440
|
+
const stepNav = h("nav", { class: "su-steps", "aria-label": "Steps" });
|
|
441
|
+
const stepCount = h("span", { class: "mono mu su-count" });
|
|
442
|
+
const footer = h("div", { class: "su-foot" });
|
|
443
|
+
const exampleFor = {
|
|
444
|
+
instructions: () => help.examples.system,
|
|
445
|
+
documents: () => help.examples.documents.slice(0, 3).join("\n\n"),
|
|
446
|
+
tools: () => JSON.stringify(help.examples.tools[0], null, 2),
|
|
447
|
+
prompts: () => help.examples.prompts.slice(0, 4).map((p) => `${p.prompt}${p.expected ? " → " + p.expected : ""}`).join("\n"),
|
|
448
|
+
checks: () => help.checks.slice(0, 8).map((k) => `${k.type}: ${k.what}`).join("\n"),
|
|
449
|
+
};
|
|
450
|
+
const useExample = {
|
|
451
|
+
instructions: () => { st.header.system = help.examples.system; },
|
|
452
|
+
documents: () => { const c = cur(); c.context = clone(help.examples.documents.slice(0, 2)); },
|
|
453
|
+
tools: () => { st.header.tools = clone(help.examples.tools); },
|
|
454
|
+
prompts: () => { st.cases = clone(help.examples.prompts); st.sel = 0; if (!st.header.system) st.header.system = help.examples.system; if (!st.header.tools.length) st.header.tools = clone(help.examples.tools); syncSelector(); },
|
|
455
|
+
checks: null,
|
|
456
|
+
};
|
|
457
|
+
function drawSteps() {
|
|
458
|
+
stepNav.replaceChildren(...STEPS.map(([key, label], i) => {
|
|
459
|
+
const on = key === st.step, ok = done(key);
|
|
460
|
+
return h("button", { type: "button", class: `su-step ${on ? "on" : ""}`, "aria-current": on ? "step" : false, onclick: () => { st.step = key; renderPanel(); } },
|
|
461
|
+
h("span", { class: `mono su-dot ${ok ? "ok" : on ? "cur" : ""}`, text: ok ? "✓" : String(i + 1) }),
|
|
462
|
+
h("span", { class: "su-st" }, h("b", { text: label }), h("span", { class: "mu", text: STEP_META[key].sub })));
|
|
463
|
+
}), h("div", { class: "su-req" }, "Only ", h("b", { text: "Prompts" }), " are required. Add the rest to match your real app."));
|
|
464
|
+
}
|
|
465
|
+
function renderPanel() {
|
|
466
|
+
const m = STEP_META[st.step], idx = STEPS.findIndex(([k]) => k === st.step);
|
|
467
|
+
const raw = panels[st.step]().filter(Boolean);
|
|
468
|
+
const body = raw.slice(2, -1); // drop the old heading, intro and tips: the design supplies them
|
|
469
|
+
const hasEx = useExample[st.step];
|
|
470
|
+
const actionFor = (kind) => {
|
|
471
|
+
if (kind === "example" && hasEx) { hasEx(); renderPanel(); markDirty(); }
|
|
472
|
+
else if (kind === "paste") panel.querySelector("textarea, input[type=text]")?.focus();
|
|
473
|
+
else if (kind === "upload") panel.querySelector("input[type=file]")?.click();
|
|
474
|
+
else if (kind === "copy") panel.querySelector(".su-body .btn")?.click();
|
|
475
|
+
};
|
|
476
|
+
const ways = h("div", { class: "su-ways" }, ...m.ways.map(([t, d, kind], i) => h(kind === "later" ? "div" : "button", { type: kind === "later" ? undefined : "button", class: `su-way ${i === (m.ways[0][2] === "later" ? 1 : 0) ? "rec" : ""} ${kind === "later" ? "later" : ""}`, onclick: kind === "later" ? undefined : () => actionFor(kind) },
|
|
477
|
+
h("span", { class: "su-wayh" }, h("b", { text: t }), kind === "later" ? h("span", { class: "chip nodot su-tag", text: "Later" }) : null), h("span", { text: d }))));
|
|
478
|
+
const example = h("div", { class: "su-ex" }, h("span", { class: "lbl", text: "Example" }), h("pre", { class: "mono su-pre", text: exampleFor[st.step]() }),
|
|
479
|
+
hasEx ? h("div", { class: "row" }, h("button", { type: "button", class: "btn su-sm", text: "Use this example", onclick: () => { hasEx(); renderPanel(); markDirty(); } })) : null);
|
|
480
|
+
const tips = h("div", { class: "su-tips-w" }, h("span", { class: "lbl", text: "Tips" }), h("div", { class: "su-tips" }, ...m.tips.map(([k, t]) => h("div", { class: `su-tip ${k}` }, h("b", { text: k === "ok" ? "✓" : "✕" }), h("span", { text: t })))));
|
|
481
|
+
stepCount.textContent = `Step ${idx + 1} of ${STEPS.length}`;
|
|
482
|
+
panel.replaceChildren(stepCount,
|
|
483
|
+
h("div", { class: "su-h" }, h("h2", { text: m.title }), h("p", { text: m.desc })),
|
|
484
|
+
h("div", { class: "su-ways-w" }, h("span", { class: "lbl", text: "Ways to add it" }), ways), example,
|
|
485
|
+
h("div", { class: "su-mine" }, h("span", { class: "lbl", text: st.step === "checks" ? "Checks for this prompt" : "Your version" }), h("div", { class: "su-body" }, ...body)), tips);
|
|
486
|
+
footer.replaceChildren(idx ? h("button", { type: "button", class: "btn", text: "Back", onclick: () => { st.step = STEPS[idx - 1][0]; renderPanel(); } }) : h("span"),
|
|
487
|
+
idx < STEPS.length - 1 ? h("button", { type: "button", class: "btn primary", text: `Next: ${STEPS[idx + 1][1]}`, onclick: () => { st.step = STEPS[idx + 1][0]; renderPanel(); } })
|
|
488
|
+
: h("button", { type: "button", class: "btn primary", text: "Save test set", onclick: save }));
|
|
489
|
+
drawSteps(); drawPreviewLive();
|
|
490
|
+
}
|
|
491
|
+
function syncSelector() {
|
|
492
|
+
selector.replaceChildren(...st.cases.map((c, i) => h("option", { value: String(i), text: `${c.id}${c.prompt ? " · " + c.prompt.slice(0, 40) : ""}` })));
|
|
493
|
+
selector.value = String(Math.min(st.sel, st.cases.length - 1));
|
|
494
|
+
}
|
|
495
|
+
selector.addEventListener("change", () => { st.sel = Number(selector.value); if (st.step === "documents" || st.step === "checks") renderPanel(); else drawPreview(); drawPreviewLive(); });
|
|
496
|
+
|
|
497
|
+
// What the model receives: built from the editor state, the current step is highlighted.
|
|
498
|
+
const live = h("div", { class: "su-live" });
|
|
499
|
+
function drawPreviewLive() {
|
|
500
|
+
const c = cur(), hd = cleanHeader(), hi = (k) => (st.step === k ? "hi" : "");
|
|
501
|
+
const docs = (c.context || []).join("\n\n"), tools = hd.tools.map((t) => `${t.name}(${Object.keys((t.parameters || {}).properties || {}).join(", ")})`).join(" · ");
|
|
502
|
+
const row = (key, label, text, empty) => h("div", { class: `su-pv ${hi(key)}` }, h("span", { class: "lbl su-pvl", text: label }), h("span", { class: text ? "" : "mu", text: text || empty }));
|
|
503
|
+
const ck = (c.checks || []).map((k) => `${k.type}${k.value !== undefined && typeof k.value !== "object" ? ": " + (Array.isArray(k.value) ? k.value.join(", ") : k.value) : ""}`);
|
|
504
|
+
const cut = (t, n) => (t.length > n ? t.slice(0, n) + "…" : t);
|
|
505
|
+
live.replaceChildren(
|
|
506
|
+
h("h3", { text: "What the model receives" }), h("span", { class: "mu su-sm2", text: "The part you are on is highlighted" }),
|
|
507
|
+
row("instructions", "SYSTEM", cut(hd.system, 160), "none yet"), row("documents", "DOCUMENTS", cut(docs, 160), "none for this prompt"),
|
|
508
|
+
row("tools", "TOOLS", cut(tools, 160), "none"), row("prompts", "USER", cut(c.prompt || "", 160), "empty prompt"),
|
|
509
|
+
h("div", { class: `su-then ${hi("checks")}` }, h("b", { text: "Then QuantCheck checks the reply" }),
|
|
510
|
+
ck.length ? h("span", { text: ck.map((t) => "✓ " + t).join(" ") + " · judge 0–10 vs expected answer" }) : h("span", { class: "mu", text: "No checks on this prompt. The judge still scores it 0–10 against the reference." })),
|
|
511
|
+
h("div", { class: "su-priv mu", text: "Everything stays on this Mac. Tools are never called." }));
|
|
512
|
+
}
|
|
513
|
+
const origRefresh = refresh;
|
|
514
|
+
refresh = async function () { await origRefresh(); drawSteps(); drawPreviewLive(); };
|
|
515
|
+
|
|
516
|
+
body.replaceChildren(
|
|
517
|
+
h("div", { class: "su-title" }, h("div", {}, h("h2", { class: "nt-h1", text: "Set up your test" }), h("p", { class: "mu nt-sub", text: "Give QuantCheck what your app gives the model, so the test matches real life. Each step has an example you can load." })),
|
|
518
|
+
h("span", { class: "chip nodot su-fast", text: "Fastest: import app logs and steps 1–4 fill themselves (later)" })),
|
|
519
|
+
h("div", { class: "row su-name" },
|
|
520
|
+
h("div", { class: "field grow" }, h("label", { for: "setname", text: "Test set name" }), nameIn,
|
|
521
|
+
h("span", { class: "hint", id: "namehint", text: st.isNew ? "Saved as <name>.jsonl in your tests folder." : "Name is fixed. Use Duplicate on the list to make a copy." })),
|
|
522
|
+
h("div", { class: "row", style: "align-self:end;padding-bottom:18px" }, saveBtn, h("a", { class: "btn", href: "#/sets", text: "Close" }))),
|
|
523
|
+
status,
|
|
524
|
+
h("div", { class: "su-grid" }, stepNav, h("div", { class: "su-mainc" }, h("div", { class: "card su-card" }, panel), footer),
|
|
525
|
+
h("aside", { class: "su-side" }, h("div", { class: "card su-livec" }, live), h("div", { class: "card su-sel" }, h("div", { class: "field" }, h("label", { for: "promptsel", text: "Preview prompt" }), selector), previewBox))));
|
|
526
|
+
syncSelector(); renderPanel(); refresh();
|
|
527
|
+
}
|