Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
fix(brio): pin the shared state in the options form so per-question requests reuse it
benmaster82e1feb15ae00c
diff --git a/c/openai_server.py b/c/openai_server.pyindex 76b4a904..12089145 100644--- a/c/openai_server.py+++ b/c/openai_server.py@@ -4526,7 +4526,18 @@ class APIHandler(BaseHTTPRequestHandler):# le domande (o tutte le caselle) condividono. Con un livello solo# la domanda si rilegge una volta per opzione; con due, 176 token# invece di 496 su quattro item (misurato).- if state_prefix and form != "options":+ #+ # Vale anche per la forma `options`: dentro una singola richiesta lo+ # stato si legge comunque una volta (lo snapshot dello stato viene+ # ripristinato quando `choose` fotografa il prefisso completo), ma+ # il punto di ritorno sullo stato condiviso serve TRA richieste. La+ # pagina web manda una domanda per richiesta sullo stesso documento;+ # senza questa fotografia ogni domanda rifarebbe il prefill di tutto+ # il documento, buttando via il "read once" che e' il senso della+ # modalita. Con essa, ogni domanda successiva paga solo i propri+ # token. Il costo e' uno snapshot in piu' su una richiesta one-shot,+ # riusato o sfrattato.+ if state_prefix:n_state, _ = score(state_prefix, True)prompt_max = max(prompt_max, n_state)diff --git a/c/tests/test_brio_api.py b/c/tests/test_brio_api.pyindex e95c4cb3..ec2aea9c 100644--- a/c/tests/test_brio_api.py+++ b/c/tests/test_brio_api.py@@ -96,9 +96,42 @@ class BrioApi(unittest.TestCase):self.assertEqual(out["answer"], "request changes")self.assertEqual(out["usage"]["completion_tokens"], 0)self.assertTrue(all(c["max_tokens"] == 0 for c in self.engine.calls))- # one photograph, of the whole prefix; the options are never pinned- self.assertEqual(len(self.pins()), 1)- self.assertTrue(self.pins()[0].endswith("Answer:"))+ # Two photographs and no more: the shared state on its own, then the+ # whole prefix. The options are never pinned. The state photograph is+ # the return point that lets a later question on the same document+ # reuse the snapshot instead of re-reading it (asserted below).+ pins = self.pins()+ self.assertEqual(len(pins), 2, pins)+ self.assertEqual(pins[0], f"Context:\n{STATE}\n\n")+ self.assertTrue(pins[1].startswith(pins[0]))+ self.assertTrue(pins[1].endswith("Answer:"))++ def test_options_form_pins_the_shared_state_for_reuse_across_requests(self):+ # The web asks one question per request on the same document. The state+ # must be photographed on its own each time, so the engine has a strict+ # prefix to restore and every question after the first pays only its own+ # tokens instead of re-reading the whole document -- the "read once" the+ # mode exists for. A handler that folded the state into the question+ # prefix only would still answer correctly while re-reading it, so the+ # pins are asserted, not just the answers.+ self.serve({"merge": -3.0, "request changes": -0.2, "close": -4.0,+ "yes": -0.1, "no": -2.0})+ self.post({"model": "test-model", "state": STATE,+ "question": "What should the reviewer do?",+ "options": ["merge", "request changes", "close"]})+ self.assertEqual([p for p in self.pins() if p == f"Context:\n{STATE}\n\n"],+ [f"Context:\n{STATE}\n\n"])+ self.post({"model": "test-model", "state": STATE,+ "question": "Does it need tests?", "options": ["yes", "no"]})+ # both requests photographed the same shared state prefix: the return+ # point exists for the second question, not only the first+ state_pins = [p for p in self.pins() if p == f"Context:\n{STATE}\n\n"]+ self.assertEqual(len(state_pins), 2, self.pins())+ # and every question prefix extends that shared state+ question_pins = [p for p in self.pins() if p.endswith("Answer:")]+ self.assertEqual(len(question_pins), 2, self.pins())+ for pin in question_pins:+ self.assertTrue(pin.startswith(f"Context:\n{STATE}\n\n"))# ---- questions: many on one state ----------------------------------------def test_questions_share_one_state_photograph(self):diff --git a/web/src/Brio.tsx b/web/src/Brio.tsxindex 66a0c3ed..26b47b73 100644--- a/web/src/Brio.tsx+++ b/web/src/Brio.tsx@@ -20,7 +20,10 @@ import { useLocale } from "./i18n"* dare: l'ENTROPIA (quanto il modello sa di sapere) e i TOKEN GENERATI, zero. */const LEVEL = (h: number) => (h < 0.4 ? "sure" : h < 0.8 ? "unsure" : "unknown")-const lines = (text: string) => text.split("\n").map((o) => o.trim()).filter(Boolean)+/* Opzioni dedotte per riga, senza duplicati: il server rifiuta due opzioni+ * uguali con un 400, e due chip con lo stesso testo darebbero una chiave React+ * ripetuta e un remove che le toglie entrambe. Deduplicare qui le tre cose. */+const lines = (text: string) => [...new Set(text.split("\n").map((o) => o.trim()).filter(Boolean))]interface Row {id: number