Butanium commited on
Commit
2e13869
·
verified ·
1 Parent(s): 87d8f74

Static DuckDB-wasm sample explorer (full 176K corpus)

Browse files
Files changed (1) hide show
  1. index.html +43 -9
index.html CHANGED
@@ -80,6 +80,16 @@ const EXP_COLORS = { human_specific:"#d62728", ai_specific:"#2ca02c",
80
  human_specific_and_ai_specific:"#9467bd", ambiguous:"#ff7f0e", none:"#7f7f7f" };
81
  const COMPLIANCE_COLORS = { refused:"#43a047", partial_vague:"#fdd835",
82
  partial_disclaimer:"#ff9800", complied:"#e53935" };
 
 
 
 
 
 
 
 
 
 
83
  const FALLBACK = "#888";
84
  const GREY = new Set([EXP_COLORS.none, FALLBACK]);
85
 
@@ -135,6 +145,9 @@ function snippet(text, q) {
135
  let conn;
136
  let activeTab = TABS[0].key;
137
  const RANGE = "range";
 
 
 
138
  const STORE = "pnx-state-v1";
139
 
140
  function captureState() {
@@ -145,7 +158,7 @@ function captureState() {
145
  for (const [col] of cfg.cats) {
146
  const el = document.getElementById(`${cfg.key}-${col}`);
147
  if (el.value === "") continue;
148
- if (el.value === RANGE) { c[col] = RANGE; continue; }
149
  const v = cfg.distinct[col][+el.value];
150
  c[col] = typeof v === "bigint" ? Number(v) : v;
151
  }
@@ -167,7 +180,9 @@ function applyState(st) {
167
  for (const [col] of cfg.cats) {
168
  const el = document.getElementById(`${cfg.key}-${col}`);
169
  const want = ts.c ? ts.c[col] : undefined;
170
- if (want === RANGE) { el.value = RANGE; continue; }
 
 
171
  const i = want === undefined ? -1
172
  : cfg.distinct[col].findIndex(d => String(d) === String(want));
173
  el.value = i === -1 ? "" : String(i);
@@ -240,19 +255,29 @@ function syncWeightRange(cfg) {
240
  document.getElementById(`${cfg.key}-weight-range`).hidden = sel.value !== RANGE;
241
  }
242
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  function whereClause(cfg) {
244
  const parts = [];
245
  const wp = weightPredicate(cfg);
246
  if (wp) parts.push(`(${wp})`);
 
 
247
  for (const [col] of cfg.cats) {
248
- if (col === "weight") continue;
249
  const v = pickVal(cfg, col);
250
  if (v === undefined) continue;
251
- // weight 0 means no adapter, so those rows ARE the base model and belong to
252
- // every organism — the corpus files them under a sentinel organism instead.
253
- parts.push(col === "organism"
254
- ? `(${col} = ${lit(v)} OR weight = 0)`
255
- : `${col} = ${lit(v)}`);
256
  }
257
  const q = searchTerm(cfg);
258
  if (q) {
@@ -318,8 +343,17 @@ async function buildTab(cfg) {
318
  const [{lo, hi}] = await rows(`SELECT MIN(${col})::DOUBLE AS lo, MAX(${col})::DOUBLE AS hi FROM '${cfg.file}'`);
319
  ranges[col] = [lo ?? 0, hi ?? 5];
320
  }
 
 
 
 
321
  const catHtml = cfg.cats.map(([col, label]) => {
322
- const extraOpt = col === "weight" ? `<option value="${RANGE}">Range…</option>` : "";
 
 
 
 
 
323
  const sel = `
324
  <div class="ctrl"><label>${label}</label>
325
  <select id="${cfg.key}-${col}">
 
80
  human_specific_and_ai_specific:"#9467bd", ambiguous:"#ff7f0e", none:"#7f7f7f" };
81
  const COMPLIANCE_COLORS = { refused:"#43a047", partial_vague:"#fdd835",
82
  partial_disclaimer:"#ff9800", complied:"#e53935" };
83
+ // Organism families, taken from `type:` in diffing-toolkit/configs/organism/*.yaml.
84
+ // character_training = the 11 persona LoRAs; control = the SDF/EM comparison adapters.
85
+ const ORG_GROUPS = {
86
+ character_training: ["goodness", "humor", "impulsiveness", "loving", "mathematical",
87
+ "misalignment", "nonchalance", "poeticism", "remorse", "sarcasm", "sycophancy"],
88
+ control: ["neg_cake_bake", "neg_em_bad_medical", "neg_em_extreme_sports",
89
+ "neg_em_risky_financial", "neg_fda_approval", "neg_roman_concrete",
90
+ "neg_sdf_cake_bake", "neg_sdf_fda_approval", "neg_sdf_roman_concrete"],
91
+ };
92
+ const GRP = "grp:";
93
  const FALLBACK = "#888";
94
  const GREY = new Set([EXP_COLORS.none, FALLBACK]);
95
 
 
145
  let conn;
146
  let activeTab = TABS[0].key;
147
  const RANGE = "range";
148
+ const groupsIn = orgs => Object.entries(ORG_GROUPS)
149
+ .map(([g, names]) => [g, names.filter(n => orgs.includes(n))])
150
+ .filter(([, names]) => names.length);
151
  const STORE = "pnx-state-v1";
152
 
153
  function captureState() {
 
158
  for (const [col] of cfg.cats) {
159
  const el = document.getElementById(`${cfg.key}-${col}`);
160
  if (el.value === "") continue;
161
+ if (el.value === RANGE || el.value.startsWith(GRP)) { c[col] = el.value; continue; }
162
  const v = cfg.distinct[col][+el.value];
163
  c[col] = typeof v === "bigint" ? Number(v) : v;
164
  }
 
180
  for (const [col] of cfg.cats) {
181
  const el = document.getElementById(`${cfg.key}-${col}`);
182
  const want = ts.c ? ts.c[col] : undefined;
183
+ if (want === RANGE || (typeof want === "string" && want.startsWith(GRP))) {
184
+ el.value = want; continue;
185
+ }
186
  const i = want === undefined ? -1
187
  : cfg.distinct[col].findIndex(d => String(d) === String(want));
188
  el.value = i === -1 ? "" : String(i);
 
255
  document.getElementById(`${cfg.key}-weight-range`).hidden = sel.value !== RANGE;
256
  }
257
 
258
+ function organismPredicate(cfg) {
259
+ const el = document.getElementById(`${cfg.key}-organism`);
260
+ if (!el || el.value === "") return null;
261
+ const sel = el.value.startsWith(GRP)
262
+ ? `organism IN (${ORG_GROUPS[el.value.slice(GRP.length)]
263
+ .filter(n => cfg.distinct.organism.includes(n)).map(lit).join(", ")})`
264
+ : `organism = ${lit(cfg.distinct.organism[+el.value])}`;
265
+ // weight 0 means no adapter, so those rows ARE the base model and belong to
266
+ // every organism — the corpus files them under a sentinel organism instead.
267
+ return `${sel} OR weight = 0`;
268
+ }
269
+
270
  function whereClause(cfg) {
271
  const parts = [];
272
  const wp = weightPredicate(cfg);
273
  if (wp) parts.push(`(${wp})`);
274
+ const op = organismPredicate(cfg);
275
+ if (op) parts.push(`(${op})`);
276
  for (const [col] of cfg.cats) {
277
+ if (col === "weight" || col === "organism") continue;
278
  const v = pickVal(cfg, col);
279
  if (v === undefined) continue;
280
+ parts.push(`${col} = ${lit(v)}`);
 
 
 
 
281
  }
282
  const q = searchTerm(cfg);
283
  if (q) {
 
343
  const [{lo, hi}] = await rows(`SELECT MIN(${col})::DOUBLE AS lo, MAX(${col})::DOUBLE AS hi FROM '${cfg.file}'`);
344
  ranges[col] = [lo ?? 0, hi ?? 5];
345
  }
346
+ const known = new Set([...ORG_GROUPS.character_training, ...ORG_GROUPS.control]);
347
+ const stray = (distinct.organism || []).filter(o => !known.has(o) && o !== "none" && o !== "base");
348
+ if (stray.length) console.warn(`[${cfg.key}] organisms in no family:`, stray);
349
+
350
  const catHtml = cfg.cats.map(([col, label]) => {
351
+ let extraOpt = col === "weight" ? `<option value="${RANGE}">Range…</option>` : "";
352
+ if (col === "organism") {
353
+ const gs = groupsIn(distinct.organism);
354
+ if (gs.length) extraOpt = `<optgroup label="Families">${gs
355
+ .map(([g, names]) => `<option value="${GRP}${g}">${g} (${names.length})</option>`).join("")}</optgroup>`;
356
+ }
357
  const sel = `
358
  <div class="ctrl"><label>${label}</label>
359
  <select id="${cfg.key}-${col}">