Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

feat(brio): let the web cancel a scoring run, dedupe the CLI options

benmaster82d13dec7815df
diff --git a/c/coli b/c/coli
index ba4358e2..f418e377 100755
--- a/c/coli
+++ b/c/coli
@@ -1626,7 +1626,10 @@ def chat_attached(a, base, model_id):
else:
print(f" {C.yel} /brio needs the options: /brio merge | request changes | close{C.r}\n")
continue
- brio_options=[o.strip() for o in spec.split("|") if o.strip()]
+ # dict.fromkeys deduplica tenendo l'ordine: il server rifiuta due
+ # opzioni uguali con un 400, e "merge | merge | close" e' un refuso
+ # facile da fare a mano, non una domanda a tre opzioni.
+ brio_options=list(dict.fromkeys(o.strip() for o in spec.split("|") if o.strip()))
if len(brio_options)<2:
brio_options=[]
print(f" {C.yel} at least two options are needed, separated by |{C.r}\n")
diff --git a/web/src/Brio.tsx b/web/src/Brio.tsx
index 66a0c3ed..af269927 100644
--- a/web/src/Brio.tsx
+++ b/web/src/Brio.tsx
@@ -1,4 +1,4 @@
-import { useRef, useState } from "react"
+import { useEffect, useRef, useState } from "react"
import { FileUp, ListChecks, LoaderCircle, Plus, X } from "lucide-react"
import { askBrio, type BrioResponse } from "@/lib/api"
@@ -44,6 +44,14 @@ export default function Brio({ baseUrl, apiKey, model, connected }: {
const [rows, setRows] = useState<Row[]>([first()])
const [running, setRunning] = useState<number | null>(null)
const file = useRef<HTMLInputElement>(null)
+ const abort = useRef<AbortController | null>(null)
+
+ /* Fermare uno scoring in corso. Su un motore che streamma gli esperti da
+ * disco una domanda dura minuti: senza un modo di annullare, chi cambia idea
+ * o lascia la pagina tiene occupato lo slot KV fino al timeout. L'abort
+ * chiude il fetch, il server vede il client sparito e smette (client
+ * disconnesso -> ClientCancelled). Vale anche allo smontaggio della pagina. */
+ useEffect(() => () => abort.current?.abort(), [])
/* Ogni domanda porta le SUE opzioni: "quanto e rischioso" vuole
* basso/medio/alto, "si firma" vuole si/no, e un insieme unico per tutte
@@ -66,17 +74,21 @@ export default function Brio({ baseUrl, apiKey, model, connected }: {
}
const run = async () => {
+ const controller = new AbortController()
+ abort.current = controller
setRows((all) => all.map((row) => ({ ...row, result: undefined, error: undefined, seconds: undefined })))
for (const row of asked) {
setRunning(row.id)
const started = performance.now()
try {
- const result = await askBrio(baseUrl, apiKey, model, state, row.text, lines(row.options))
+ const result = await askBrio(baseUrl, apiKey, model, state, row.text, lines(row.options), controller.signal)
patch(row.id, { result, seconds: (performance.now() - started) / 1000 })
} catch (cause) {
+ if (controller.signal.aborted) break /* fermato apposta: le domande dopo restano intatte */
patch(row.id, { error: cause instanceof Error ? cause.message : String(cause) })
}
}
+ abort.current = null
setRunning(null)
}
@@ -163,9 +175,12 @@ export default function Brio({ baseUrl, apiKey, model, connected }: {
<button type="button" className="brio-add" onClick={() => setRows((all) => [...all, blank()])}>
<Plus />{t("brio.addQuestion")}
</button>
- <button type="button" className="brio-run" disabled={!ready} onClick={run}>
- {running !== null ? <LoaderCircle className="brio-spin" /> : <ListChecks />}
- {running !== null ? t("brio.scoring") : t("brio.scoreAll", { n: asked.length })}
+ {/* Mentre gira, lo stesso bottone ferma: l'abort chiude il fetch e
+ libera lo slot KV lato server invece di aspettare il timeout. */}
+ <button type="button" className="brio-run" disabled={running === null && !ready}
+ onClick={running !== null ? () => abort.current?.abort() : run}>
+ {running !== null ? <X /> : <ListChecks />}
+ {running !== null ? t("brio.stop") : t("brio.scoreAll", { n: asked.length })}
</button>
</div>
{!connected ? <p className="brio-note">{t("brio.offline")}</p> : null}
diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.ts
index 73ca964c..a07e237b 100644
--- a/web/src/i18n/en.ts
+++ b/web/src/i18n/en.ts
@@ -93,6 +93,7 @@ const en: Record<string, string> = {
"brio.ownOptions": "Allowed options for this question, one per line",
"brio.needTwo": "a second option is needed, on its own line",
"brio.scoreAll": "Answer {{n}}",
+ "brio.stop": "Stop",
"nav.brio": "Brio",
"brio.sure": "confident",
"brio.unsure": "unsure",
diff --git a/web/src/i18n/id.ts b/web/src/i18n/id.ts
index 66f72c2b..402aa75c 100644
--- a/web/src/i18n/id.ts
+++ b/web/src/i18n/id.ts
@@ -93,6 +93,7 @@ const id: Record<string, string> = {
"brio.ownOptions": "Opsi yang diizinkan untuk pertanyaan ini, satu per baris",
"brio.needTwo": "diperlukan opsi kedua, pada baris tersendiri",
"brio.scoreAll": "Jawab {{n}}",
+ "brio.stop": "Hentikan",
"nav.brio": "Brio",
"brio.sure": "yakin",
"brio.unsure": "tidak yakin",
diff --git a/web/src/i18n/it.ts b/web/src/i18n/it.ts
index 5b1dd425..7c9f598c 100644
--- a/web/src/i18n/it.ts
+++ b/web/src/i18n/it.ts
@@ -92,6 +92,7 @@ const it: Record<string, string> = {
"brio.ownOptions": "Opzioni ammesse per questa domanda, una per riga",
"brio.needTwo": "serve almeno una seconda opzione, separata da virgola o a capo",
"brio.scoreAll": "Rispondi a {{n}}",
+ "brio.stop": "Ferma",
"nav.brio": "Brio",
"brio.sure": "certo",
"brio.unsure": "incerto",