bots-garden/razorbillpublic Fork
⑂ 40f9839
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/razorbill.git
git clone ssh://git@rickub.com/bots-garden/razorbill.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

ticket #60: POST /v1/systemone (decision models)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
k33g committed 2026-11-26T19:14:59+01:00 Browse files
40f9839 parent: 99d14fa
modified .memory/history.md +4 -0
@@ -459,3 +459,7 @@ OpenJev/lev on Qwen3.5; Kev: hidden states at markers + cls_out head; Laya/Julia
459459 encoders). Hub check: MLX conversions are fragmented (own runtimes); kev-4b ships head.pt (pickle).
460460 Report written as comment 1 on #46, tasks 1–2 closed. Asked which family first and the Mac's RAM:
461461 the user wants to clarify before answering.
462+
463+Then: user asked to "just write the ticket" for now: created #60 "POST /v1/systemone: decision
464+models (llama-server compatible)" (v0.3, epic Decision models, needs-decision; API, mechanism, 3
465+families, open decisions, acceptance, 4 tasks), linked from #46. Family choice / Mac RAM unanswered.
@@ -459,3 +459,7 @@ OpenJev/lev on Qwen3.5; Kev: hidden states at markers + cls_out head; Laya/Julia
459 encoders). Hub check: MLX conversions are fragmented (own runtimes); kev-4b ships head.pt (pickle).459 encoders). Hub check: MLX conversions are fragmented (own runtimes); kev-4b ships head.pt (pickle).
460 Report written as comment 1 on #46, tasks 1–2 closed. Asked which family first and the Mac's RAM:460 Report written as comment 1 on #46, tasks 1–2 closed. Asked which family first and the Mac's RAM:
461 the user wants to clarify before answering.461 the user wants to clarify before answering.
462+
463+Then: user asked to "just write the ticket" for now: created #60 "POST /v1/systemone: decision
464+models (llama-server compatible)" (v0.3, epic Decision models, needs-decision; API, mechanism, 3
465+families, open decisions, acceptance, 4 tasks), linked from #46. Family choice / Mac RAM unanswered.
modified .tickets/issues/0046-spike-what-are-decision-models-for-razorbill-and.yaml +1 -0
@@ -14,6 +14,7 @@ labels:
1414 milestone: "v0.3 — Decision models"
1515 epic: "Decision models"
1616 related:
17+ - 60
1718 - 31
1819 - 42
1920 - 38
@@ -14,6 +14,7 @@ labels:
14 milestone: "v0.3 — Decision models"14 milestone: "v0.3 — Decision models"
15 epic: "Decision models"15 epic: "Decision models"
16 related:16 related:
17+ - 60
17 - 3118 - 31
18 - 4219 - 42
19 - 3820 - 38
added .tickets/issues/0060-post-v1-systemone-decision-models.yaml +108 -0
new file mode 100644
@@ -0,0 +1,108 @@
1+# Managed by IssueSpec. Hand edits are welcome; keep the schema valid.
2+id: 60
3+title: "POST /v1/systemone: decision models (llama-server compatible)"
4+state: open
5+author:
6+ name: k33g
7+ email: ph.charriere@gmail.com
8+createdAt: 2026-11-26T20:00:00.000Z
9+updatedAt: 2026-11-26T20:00:00.000Z
10+labels:
11+ - "kind::feature"
12+ - "area::server"
13+ - "area::engine"
14+ - "needs-decision"
15+ - "priority::medium"
16+milestone: "v0.3 — Decision models"
17+epic: "Decision models"
18+related:
19+ - 46
20+ - 48
21+body: |
22+ Asked by the user (2026-11-26): serve decision models with the same endpoint as llama-server, `POST /v1/systemone` (ggml-org/llama.cpp PR #29818, TypeSafe System One API). Findings, formulas and model families: comment 1 on #46.
23+
24+ ## API (same shape as llama-server)
25+ Request:
26+ ```json
27+ {
28+ "model": "optional, chooses the model like the other routes",
29+ "state": "string, object or array (non-strings given to the model as JSON)",
30+ "images": ["data:image/...;base64,..."],
31+ "questions": {
32+ "route": {"type": "choice", "instructions": "Which team should handle this?",
33+ "criteria": {"billing": "payments, refunds", "shipping": null}},
34+ "urgency": {"type": "score", "instructions": "How urgent is this?",
35+ "criteria": ["can wait", "this week", "today", "right now"]},
36+ "angry": {"type": "noul", "instructions": "Is the customer angry?"}
37+ }
38+ }
39+ ```
40+ Response:
41+ ```json
42+ {
43+ "model": "...",
44+ "answers": {
45+ "route": {"type": "choice", "choice": "billing", "probabilities": {"billing": 0.99, "shipping": 0.01}, "confidence": 0.98},
46+ "urgency": {"type": "score", "score": 2.08, "legend": {"0": "can wait", "1": "this week", "2": "today", "3": "right now"},
47+ "probabilities": {"0": 0.002, "1": 0.116, "2": 0.675, "3": 0.206}, "confidence": 0.67},
48+ "angry": {"type": "noul", "noul": 0.63}
49+ },
50+ "usage": {"input_tokens": 239, "output_tokens": 0}
51+ }
52+ ```
53+ - `choice`: `criteria` = object option → description or null; `score`: 2 to 10 levels, lowest first; `noul`: optional `{true, false}` descriptions.
54+ - Confidence: choice `max(0, (p_max - 1/n) / (1 - 1/n))`; score `max(0, 1 - E|i - mode| / uniform distance)` (same formulas as llama.cpp).
55+ - Errors in razorbill's OpenAI error envelope: 400 invalid request (`questions.<id>: ...` messages), 501 for a model that is not a decision model, or images with a model that does not take them. No streaming.
56+ - Questions are answered independently; `usage.input_tokens` = prompt tokens of all questions.
57+
58+ ## How it works
59+ No generation: one prompt per question (and per variant), one forward pass, scores → softmax with the family's temperature → probabilities. The prompt template, temperatures and readout are per family, hard-coded in razorbill (MLX repos carry no `decision.type` metadata), taken from llama.cpp's conversion code:
60+ 1. **Label readout** (OpenJev, lev — Qwen3.5): logits of the label tokens at the last position (lev: choice evaluated twice with reversed options, noul as a 9-level rating, LoRA adapter merged at load).
61+ 2. **Kev** (Qwen3.5-4B-Base + `cls_out` head): hidden states at the `<|box_end|>` option markers and at the last token, scaled dot product (`head.pt` must be converted to safetensors).
62+ 3. **Laya / Julia-1** (ModernBERT / mmBERT encoders): head column per question type at each `[mask]` option marker; needs a ModernBERT port (not in mlx-swift-lm).
63+
64+ ## To decide (with the user)
65+ - Which family first (label readout is the cheapest: Qwen3.5 is in MLXLLM).
66+ - How a model is recognised as a decision model: detection from repo files (`helper/shim.py`, `lev_release.json`, `head.pt`...) or a `decision:` entry in the server configuration.
67+ - Which Hub repos are supported (MLX conversions are fragmented, each with its own runtime) and which test models fit the user's Mac.
68+ - Shared prompt prefix between questions (Qwen3.5 is hybrid: needs a state snapshot, not a cache trim) — now or later.
69+ - Images (OpenJev) — later.
70+
71+ ## Acceptance
72+ - The request/response/validation layer runs on the fake engine and is tested on Linux.
73+ - With a real model of the chosen family, probabilities match llama.cpp's reference values from PR #29818 within the same tolerance (worst diff ~1e-3).
74+ - Compatibility suite: a `/v1/systemone` test; docs EN + FR (how-to + HTTP API reference with curl examples run by `test_docs_curl.py`).
75+tasks:
76+ - id: 1
77+ title: "Decide the first family, model detection and test models"
78+ state: open
79+ priority: high
80+ author:
81+ name: k33g
82+ email: ph.charriere@gmail.com
83+ createdAt: 2026-11-26T20:00:00.000Z
84+ - id: 2
85+ title: "API layer: request parsing, validation, answers, confidence, errors (fake engine, Linux tests)"
86+ state: open
87+ priority: high
88+ author:
89+ name: k33g
90+ email: ph.charriere@gmail.com
91+ createdAt: 2026-11-26T20:00:00.000Z
92+ - id: 3
93+ title: "Engine: decision scoring for the first family (MLX, compare with llama.cpp reference values)"
94+ state: open
95+ priority: high
96+ author:
97+ name: k33g
98+ email: ph.charriere@gmail.com
99+ createdAt: 2026-11-26T20:00:00.000Z
100+ - id: 4
101+ title: "Compatibility test and docs EN + FR"
102+ state: open
103+ priority: medium
104+ author:
105+ name: k33g
106+ email: ph.charriere@gmail.com
107+ createdAt: 2026-11-26T20:00:00.000Z
108+comments: []
new file mode 100644
@@ -0,0 +1,108 @@
1+# Managed by IssueSpec. Hand edits are welcome; keep the schema valid.
2+id: 60
3+title: "POST /v1/systemone: decision models (llama-server compatible)"
4+state: open
5+author:
6+ name: k33g
7+ email: ph.charriere@gmail.com
8+createdAt: 2026-11-26T20:00:00.000Z
9+updatedAt: 2026-11-26T20:00:00.000Z
10+labels:
11+ - "kind::feature"
12+ - "area::server"
13+ - "area::engine"
14+ - "needs-decision"
15+ - "priority::medium"
16+milestone: "v0.3 — Decision models"
17+epic: "Decision models"
18+related:
19+ - 46
20+ - 48
21+body: |
22+ Asked by the user (2026-11-26): serve decision models with the same endpoint as llama-server, `POST /v1/systemone` (ggml-org/llama.cpp PR #29818, TypeSafe System One API). Findings, formulas and model families: comment 1 on #46.
23+
24+ ## API (same shape as llama-server)
25+ Request:
26+ ```json
27+ {
28+ "model": "optional, chooses the model like the other routes",
29+ "state": "string, object or array (non-strings given to the model as JSON)",
30+ "images": ["data:image/...;base64,..."],
31+ "questions": {
32+ "route": {"type": "choice", "instructions": "Which team should handle this?",
33+ "criteria": {"billing": "payments, refunds", "shipping": null}},
34+ "urgency": {"type": "score", "instructions": "How urgent is this?",
35+ "criteria": ["can wait", "this week", "today", "right now"]},
36+ "angry": {"type": "noul", "instructions": "Is the customer angry?"}
37+ }
38+ }
39+ ```
40+ Response:
41+ ```json
42+ {
43+ "model": "...",
44+ "answers": {
45+ "route": {"type": "choice", "choice": "billing", "probabilities": {"billing": 0.99, "shipping": 0.01}, "confidence": 0.98},
46+ "urgency": {"type": "score", "score": 2.08, "legend": {"0": "can wait", "1": "this week", "2": "today", "3": "right now"},
47+ "probabilities": {"0": 0.002, "1": 0.116, "2": 0.675, "3": 0.206}, "confidence": 0.67},
48+ "angry": {"type": "noul", "noul": 0.63}
49+ },
50+ "usage": {"input_tokens": 239, "output_tokens": 0}
51+ }
52+ ```
53+ - `choice`: `criteria` = object option → description or null; `score`: 2 to 10 levels, lowest first; `noul`: optional `{true, false}` descriptions.
54+ - Confidence: choice `max(0, (p_max - 1/n) / (1 - 1/n))`; score `max(0, 1 - E|i - mode| / uniform distance)` (same formulas as llama.cpp).
55+ - Errors in razorbill's OpenAI error envelope: 400 invalid request (`questions.<id>: ...` messages), 501 for a model that is not a decision model, or images with a model that does not take them. No streaming.
56+ - Questions are answered independently; `usage.input_tokens` = prompt tokens of all questions.
57+
58+ ## How it works
59+ No generation: one prompt per question (and per variant), one forward pass, scores → softmax with the family's temperature → probabilities. The prompt template, temperatures and readout are per family, hard-coded in razorbill (MLX repos carry no `decision.type` metadata), taken from llama.cpp's conversion code:
60+ 1. **Label readout** (OpenJev, lev — Qwen3.5): logits of the label tokens at the last position (lev: choice evaluated twice with reversed options, noul as a 9-level rating, LoRA adapter merged at load).
61+ 2. **Kev** (Qwen3.5-4B-Base + `cls_out` head): hidden states at the `<|box_end|>` option markers and at the last token, scaled dot product (`head.pt` must be converted to safetensors).
62+ 3. **Laya / Julia-1** (ModernBERT / mmBERT encoders): head column per question type at each `[mask]` option marker; needs a ModernBERT port (not in mlx-swift-lm).
63+
64+ ## To decide (with the user)
65+ - Which family first (label readout is the cheapest: Qwen3.5 is in MLXLLM).
66+ - How a model is recognised as a decision model: detection from repo files (`helper/shim.py`, `lev_release.json`, `head.pt`...) or a `decision:` entry in the server configuration.
67+ - Which Hub repos are supported (MLX conversions are fragmented, each with its own runtime) and which test models fit the user's Mac.
68+ - Shared prompt prefix between questions (Qwen3.5 is hybrid: needs a state snapshot, not a cache trim) — now or later.
69+ - Images (OpenJev) — later.
70+
71+ ## Acceptance
72+ - The request/response/validation layer runs on the fake engine and is tested on Linux.
73+ - With a real model of the chosen family, probabilities match llama.cpp's reference values from PR #29818 within the same tolerance (worst diff ~1e-3).
74+ - Compatibility suite: a `/v1/systemone` test; docs EN + FR (how-to + HTTP API reference with curl examples run by `test_docs_curl.py`).
75+tasks:
76+ - id: 1
77+ title: "Decide the first family, model detection and test models"
78+ state: open
79+ priority: high
80+ author:
81+ name: k33g
82+ email: ph.charriere@gmail.com
83+ createdAt: 2026-11-26T20:00:00.000Z
84+ - id: 2
85+ title: "API layer: request parsing, validation, answers, confidence, errors (fake engine, Linux tests)"
86+ state: open
87+ priority: high
88+ author:
89+ name: k33g
90+ email: ph.charriere@gmail.com
91+ createdAt: 2026-11-26T20:00:00.000Z
92+ - id: 3
93+ title: "Engine: decision scoring for the first family (MLX, compare with llama.cpp reference values)"
94+ state: open
95+ priority: high
96+ author:
97+ name: k33g
98+ email: ph.charriere@gmail.com
99+ createdAt: 2026-11-26T20:00:00.000Z
100+ - id: 4
101+ title: "Compatibility test and docs EN + FR"
102+ state: open
103+ priority: medium
104+ author:
105+ name: k33g
106+ email: ph.charriere@gmail.com
107+ createdAt: 2026-11-26T20:00:00.000Z
108+comments: []