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

web: the Brio page answers on a decision model through /v1/systemone

JustVuggbd9fc67dd5b2
diff --git a/web/src/App.tsx b/web/src/App.tsx
index 002f046b..40512212 100644
--- a/web/src/App.tsx
+++ b/web/src/App.tsx
@@ -31,7 +31,7 @@ import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import {
- generateImage, generatesImages, getHealth, listModelInfo, streamChat,
+ decidesOnly, generateImage, generatesImages, getHealth, listModelInfo, streamChat,
type ChatMessage, type GeneratedImage, type HealthResponse, type StreamChatResult,
} from "@/lib/api"
import {
@@ -73,6 +73,7 @@ export default function App() {
/* Models the server marks with the image_generation capability. With one of
them selected the conversation generates pictures instead of text. */
const [imageModels, setImageModels] = useState<string[]>([])
+ const [decisionModels, setDecisionModels] = useState<string[]>([])
const [model, setModel] = useState(() => stored(localStorage, "colibri.model", "glm-5.2-colibri"))
const [temperature, setTemperature] = useState(0.7)
const [maxTokens, setMaxTokens] = useState(4096)
@@ -191,6 +192,7 @@ export default function App() {
const found = info.map((item) => item.id)
setModels(found)
setImageModels(info.filter(generatesImages).map((item) => item.id))
+ setDecisionModels(info.filter(decidesOnly).map((item) => item.id))
if (found.length && !found.includes(model)) setModel(found[0])
setConnected(true)
try {
@@ -605,7 +607,8 @@ export default function App() {
</section>}
<section className="brio-workspace" hidden={view !== "brio"}>
<header className="page-heading"><span>COLIBRI / BRIO</span><h1>{t("nav.brio")}</h1></header>
- <Brio baseUrl={baseUrl} apiKey={apiKey} model={model} connected={connected} />
+ <Brio baseUrl={baseUrl} apiKey={apiKey} model={model} connected={connected}
+ decision={decisionModels.includes(model)} />
</section>
</main>
<NavigationDock view={view} onNavigate={setView} loading={loading} />
diff --git a/web/src/Brio.tsx b/web/src/Brio.tsx
index 631d5bb3..fb340623 100644
--- a/web/src/Brio.tsx
+++ b/web/src/Brio.tsx
@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from "react"
import { FileUp, ListChecks, LoaderCircle, Plus, X } from "lucide-react"
-import { askBrio, type BrioResponse } from "@/lib/api"
+import { askBrio, askSystemOne, type BrioResponse } from "@/lib/api"
import { useLocale } from "./i18n"
/* Modalita brio.
@@ -38,8 +38,10 @@ let nextId = 1
const blank = (): Row => ({ id: nextId++, text: "", options: "" })
const first = (): Row => ({ id: nextId++, text: "", options: "yes\nno" })
-export default function Brio({ baseUrl, apiKey, model, connected }: {
+export default function Brio({ baseUrl, apiKey, model, connected, decision = false }: {
baseUrl: string; apiKey: string; model: string; connected: boolean
+ /* a decision model (Laya): it answers only POST /v1/systemone */
+ decision?: boolean
}) {
const { t } = useLocale()
const [state, setState] = useState("")
@@ -84,7 +86,8 @@ export default function Brio({ baseUrl, apiKey, model, connected }: {
setRunning(row.id)
const started = performance.now()
try {
- const result = await askBrio(baseUrl, apiKey, model, state, row.text, lines(row.options), controller.signal)
+ const ask = decision ? askSystemOne : askBrio
+ const result = await ask(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 */
diff --git a/web/src/lib/api.test.ts b/web/src/lib/api.test.ts
index 95b81d07..61370f95 100644
--- a/web/src/lib/api.test.ts
+++ b/web/src/lib/api.test.ts
@@ -1,7 +1,7 @@
import { afterEach, describe, expect, it, vi } from "vitest"
import {
- askBrio, extractSSE, extractSSEEvents, generateImage, generatesImages, getHealth, getProfile,
+ askBrio, askSystemOne, decidesOnly, extractSSE, extractSSEEvents, generateImage, generatesImages, getHealth, getProfile,
listModelInfo, serverEndpoint, streamChat, type GenerateImageOptions, type ImageProgress,
} from "./api"
@@ -150,6 +150,34 @@ describe("askBrio", () => {
})
})
+describe("askSystemOne", () => {
+ it("asks a decision model one choice question and draws it like a brio answer", async () => {
+ const seen: { url?: string; body?: { questions: { q: { type: string; criteria: object } } } } = {}
+ vi.stubGlobal("fetch", vi.fn(async (url: string, init: RequestInit) => {
+ seen.url = url
+ seen.body = JSON.parse(String(init.body))
+ return new Response(JSON.stringify({
+ id: "req_1", model: "laya", provider: "colibri",
+ answers: { q: { type: "choice", choice: "b", probabilities: { a: 0.25, b: 0.75 }, confidence: 0.5 } },
+ usage: { input_tokens: 40, output_tokens: 0, cost: 0 },
+ }), { status: 200, headers: { "Content-Type": "application/json" } })
+ }))
+ const out = await askSystemOne("http://x/v1", "", "laya", "state", "q?", ["a", "b"])
+ expect(seen.url).toBe("http://x/v1/systemone")
+ expect(seen.body?.questions.q).toEqual({ type: "choice", instructions: "q?", criteria: { a: null, b: null } })
+ expect(out.answer).toBe("b")
+ expect(out.choices.map((c) => c.option)).toEqual(["b", "a"])
+ expect(out.entropy).toBeCloseTo(-(0.25 * Math.log(0.25) + 0.75 * Math.log(0.75)) / Math.log(2), 6)
+ expect(out.usage).toEqual({ prompt_tokens: 40, completion_tokens: 0, read_tokens: 40, total_tokens: 40 })
+ })
+
+ it("knows a decision model from its capabilities", () => {
+ expect(decidesOnly({ id: "laya", capabilities: ["systemone", "decision"] })).toBe(true)
+ expect(decidesOnly({ id: "qwen36", capabilities: ["chat", "systemone"] })).toBe(false)
+ expect(decidesOnly(undefined)).toBe(false)
+ })
+})
+
describe("extractSSEEvents", () => {
it("keeps the event name of each frame and defaults to message", () => {
const parsed = extractSSEEvents(
diff --git a/web/src/lib/api.ts b/web/src/lib/api.ts
index 40043bbf..d09e3016 100644
--- a/web/src/lib/api.ts
+++ b/web/src/lib/api.ts
@@ -131,8 +131,10 @@ async function responseError(response: Response) {
export interface ModelInfo {
id: string
- /* What a model does beyond chat. colibri marks an image model with
- "image_generation": it answers /v1/images/generations and refuses chat. */
+ /* What a model does. colibri marks an image model with "image_generation"
+ (it answers /v1/images/generations and refuses chat), a language model
+ with "chat" and "systemone", and a decision model with "systemone" and
+ "decision" (it answers only POST /v1/systemone). */
capabilities?: string[]
}
@@ -323,6 +325,57 @@ export async function askBrio(
return (await response.json()) as BrioResponse
}
+/* A decision engine (Laya) answers only POST /v1/systemone: there the page's
+ * question is one `choice` with the options as labels, and the reply is shaped
+ * like askBrio's so the page draws it the same way. The engine reads every
+ * token and generates none; its probabilities are calibrated, not log-probs,
+ * so `logprob` is the log of the probability and `tokens` is 0. */
+export async function askSystemOne(
+ baseUrl: string,
+ apiKey: string,
+ model: string,
+ state: string,
+ question: string,
+ options: string[],
+ signal?: AbortSignal,
+): Promise<BrioResponse> {
+ const response = await fetch(endpoint(baseUrl, "systemone"), {
+ method: "POST",
+ headers: headers(apiKey),
+ body: JSON.stringify({
+ model, state,
+ questions: { q: { type: "choice", instructions: question, criteria: Object.fromEntries(options.map((o) => [o, null])) } },
+ }),
+ signal,
+ })
+ if (!response.ok) throw new Error(await responseError(response))
+ const body = (await response.json()) as {
+ answers?: { q?: { choice?: string; probabilities?: Record<string, number> } }
+ usage?: { input_tokens?: number; output_tokens?: number }
+ }
+ const probabilities = body.answers?.q?.probabilities ?? {}
+ const choices = options
+ .map((option) => ({ option, p: probabilities[option] ?? 0, tokens: 0 }))
+ .map((c) => ({ ...c, logprob: Math.log(Math.max(c.p, 1e-12)), mean_logprob: Math.log(Math.max(c.p, 1e-12)) }))
+ .sort((a, b) => b.p - a.p)
+ const entropy = choices.length > 1
+ ? -choices.reduce((sum, c) => sum + (c.p > 0 ? c.p * Math.log(c.p) : 0), 0) / Math.log(choices.length)
+ : 0
+ const read = body.usage?.input_tokens ?? 0
+ return {
+ answer: body.answers?.q?.choice ?? choices[0]?.option ?? "",
+ entropy,
+ normalize: "sum",
+ choices,
+ usage: { prompt_tokens: read, completion_tokens: 0, read_tokens: read, total_tokens: read },
+ }
+}
+
+/* A model that only decides: colibri marks it "decision" in /v1/models. */
+export function decidesOnly(model: ModelInfo | undefined) {
+ return !!model?.capabilities?.includes("decision")
+}
+
/* ---- text-to-image ----------------------------------------------------------
* POST /v1/images/generations, in the OpenAI shape plus colibri's `steps`,
* `seed` and the `colibri` block of the answer. With `stream: true` the gateway