{_esc(jid)} · {_esc(q["type"])}
' f'{_esc(q["question"])}
' f'→ {_esc(j_choice)} ({j_conf * 100:.1f}%)
→ {_esc(l_choice)} ({l_conf * 100:.1f}%)
→ {_esc(ds_val or "—")}' f' {_esc(ds_status)}
' f'"""HTML report for System One vs Laya vs DeepSeek comparison.""" from __future__ import annotations import html def _esc(s) -> str: return html.escape(str(s) if s is not None else "") def _bar(probs, options, chosen_index, fill_class="bar-fill"): parts = [] for i, (p, label) in enumerate(zip(probs or [], options or [])): w = max(2, int(float(p) * 100)) hot = i == chosen_index parts.append( f'
' ) return "".join(parts) def _choice_of(block: dict | None) -> tuple[str, float]: if not block: return "—", 0.0 return str(block.get("chosen") or "—"), float(block.get("conf") or 0.0) def _norm(s: str | None) -> str: return (s or "").strip().lower() def _agree_pill(a: str | None, b: str | None, label: str) -> str: if not a or not b or a == "—" or b == "—": return f'{_esc(label)}: —' if _norm(a) == _norm(b): return f'{_esc(label)}: match' return f'{_esc(label)}: differ' def render_report(jev: dict, laya: dict, deepseek: dict, qs: list[dict]) -> str: from deepseek_lane import answers_by_id ds_answers = answers_by_id(deepseek.get("validation") or {}) jev_qs = {b["id"]: b for b in (jev.get("questions") or [])} laya_qs = {b["id"]: b for b in (laya.get("questions") or [])} all3 = 0 comparable = 0 rows = [] for q in qs: jid = q["id"] jb = jev_qs.get(jid) lb = laya_qs.get(jid) j_choice, j_conf = _choice_of(jb) l_choice, l_conf = _choice_of(lb) ds_val = ds_answers.get(jid) picks = [p for p in (j_choice, l_choice, ds_val) if p and p != "—"] if len(picks) >= 2: comparable += 1 if len({_norm(p) for p in picks}) == 1 and len(picks) == 3: all3 += 1 j_bars = _bar(jb["probs"], jb["options"], jb["chosen_index"]) if jb else "" l_bars = ( _bar(lb["probs"], lb["options"], lb["chosen_index"], fill_class="bar-fill laya") if lb else "" ) ds_status = "" for a in (deepseek.get("validation") or {}).get("answers") or []: if a["id"] == jid: ds_status = a["status"] break pills = " ".join( [ _agree_pill(j_choice, l_choice, "S1↔Laya"), _agree_pill(j_choice, ds_val, "S1↔DS"), _agree_pill(l_choice, ds_val, "Laya↔DS"), ] ) jev_err = "" laya_body = l_bars if laya.get("error") and not lb: laya_body = f'' rows.append( f'{_esc(q["question"])}
' f'→ {_esc(j_choice)} ({j_conf * 100:.1f}%)
→ {_esc(l_choice)} ({l_conf * 100:.1f}%)
→ {_esc(ds_val or "—")}' f' {_esc(ds_status)}
' f'State exceeds System One training length (384 tokens) — ' "treat S1 probabilities as exploratory.
" ) if plan.get("truncated"): warn += 'State was truncated to fit the System One scorer limit.
' if jev.get("error"): warn += f'System One: {_esc(jev["error"])}
' if laya.get("error"): warn += f'Laya: {_esc(laya["error"])}
' ds_err = deepseek.get("error") ds_meta = ( f'' if ds_err else ( f'' ) ) return f"""