Reasoning can be hidden; streaming of reasoning verified (#37)
show_reasoning in the configuration's defaults or locked blocks (server wide or per model) and include_reasoning per request decide whether the model's reasoning is sent. When hidden the model still thinks, nothing of it reaches the client (plain or streamed), and reasoning_tokens still counts it. A lock cannot be overridden by clients. Reasoning deltas are checked on the Mac with a real Qwen3 model: token by token, before the answer, absent when hidden. Tests: Linux 123, Mac 135. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1f0e95f parent: 7cdd37d modified
.memory/handoffs/2026-11-25-v0-2-server-foundation.md +3 -1 | @@ -6,7 +6,9 @@ Update after #34: `ModelManager`, `/v1/models` done (Linux 89, Mac 94). | ||
| 6 | 6 | Update after #35: non-streaming chat completions done (Linux 106, Mac 114, real-model smoke tests). |
| 7 | 7 | Update after #36: streaming done (Linux 113, Mac 122). |
| 8 | 8 | Update after #37: reasoning_content + switches done (Linux 120, Mac 131). Its design choices were |
| 9 | -made by Claude on a plain "go": mention them to the user if reasoning comes up. | |
| 9 | +made by Claude on a plain "go": mention them to the user if reasoning comes up. The user then asked | |
| 10 | +for a way to hide it (`show_reasoning` / `include_reasoning`, done) and for it to stream (it did; | |
| 11 | +now verified on the Mac). | |
| 10 | 12 | Branch `feature/v0.2-openai-server`: step 1 (agent code removed) committed as `132c60f`; #32 (HTTP |
| 11 | 13 | server foundation, `rzb serve`) implemented, tested (Linux 55, Mac 60), quality gate PASS, ticket |
| 12 | 14 | closed. `razorbill.yaml` (old agent file) deleted with the user's agreement; #17's last task |
| @@ -6,7 +6,9 @@ Update after #34: `ModelManager`, `/v1/models` done (Linux 89, Mac 94). | |||
| 6 | Update after #35: non-streaming chat completions done (Linux 106, Mac 114, real-model smoke tests). | 6 | Update after #35: non-streaming chat completions done (Linux 106, Mac 114, real-model smoke tests). |
| 7 | Update after #36: streaming done (Linux 113, Mac 122). | 7 | Update after #36: streaming done (Linux 113, Mac 122). |
| 8 | Update after #37: reasoning_content + switches done (Linux 120, Mac 131). Its design choices were | 8 | Update after #37: reasoning_content + switches done (Linux 120, Mac 131). Its design choices were |
| 9 | -made by Claude on a plain "go": mention them to the user if reasoning comes up. | 9 | +made by Claude on a plain "go": mention them to the user if reasoning comes up. The user then asked |
| 10 | +for a way to hide it (`show_reasoning` / `include_reasoning`, done) and for it to stream (it did; | ||
| 11 | +now verified on the Mac). | ||
| 10 | Branch `feature/v0.2-openai-server`: step 1 (agent code removed) committed as `132c60f`; #32 (HTTP | 12 | Branch `feature/v0.2-openai-server`: step 1 (agent code removed) committed as `132c60f`; #32 (HTTP |
| 11 | server foundation, `rzb serve`) implemented, tested (Linux 55, Mac 60), quality gate PASS, ticket | 13 | server foundation, `rzb serve`) implemented, tested (Linux 55, Mac 60), quality gate PASS, ticket |
| 12 | closed. `razorbill.yaml` (old agent file) deleted with the user's agreement; #17's last task | 14 | closed. `razorbill.yaml` (old agent file) deleted with the user's agreement; #17's last task |
modified
.memory/history.md +6 -0 | @@ -183,3 +183,9 @@ | ||
| 183 | 183 | protocol so engine-side setting errors become 400s. Mac smoke tests with real Qwen3 thinking |
| 184 | 184 | (budget 16 → 37 reasoning tokens: Qwen3's transition sentence counts). Linux 120, Mac 131, gate |
| 185 | 185 | PASS (run #12). #37 closed (`needs-decision` label removed). |
| 186 | +- #37 follow-up asked by the user: option to hide the reasoning + reasoning must stream. Added | |
| 187 | + `show_reasoning` (GenerationSettings/Overrides, config defaults/locked, imposed when locked) and | |
| 188 | + the request field `include_reasoning`; hiding happens in `CompletionStream` (counted, not passed | |
| 189 | + on), shared by plain and streamed answers through `ChatCompletionRoute.generate`. Streaming of | |
| 190 | + reasoning already existed; now verified with real Qwen3 on the Mac. Linux 123, Mac 135, gate PASS | |
| 191 | + (run #13). Comment #2 on #37. | |
| @@ -183,3 +183,9 @@ | |||
| 183 | protocol so engine-side setting errors become 400s. Mac smoke tests with real Qwen3 thinking | 183 | protocol so engine-side setting errors become 400s. Mac smoke tests with real Qwen3 thinking |
| 184 | (budget 16 → 37 reasoning tokens: Qwen3's transition sentence counts). Linux 120, Mac 131, gate | 184 | (budget 16 → 37 reasoning tokens: Qwen3's transition sentence counts). Linux 120, Mac 131, gate |
| 185 | PASS (run #12). #37 closed (`needs-decision` label removed). | 185 | PASS (run #12). #37 closed (`needs-decision` label removed). |
| 186 | +- #37 follow-up asked by the user: option to hide the reasoning + reasoning must stream. Added | ||
| 187 | + `show_reasoning` (GenerationSettings/Overrides, config defaults/locked, imposed when locked) and | ||
| 188 | + the request field `include_reasoning`; hiding happens in `CompletionStream` (counted, not passed | ||
| 189 | + on), shared by plain and streamed answers through `ChatCompletionRoute.generate`. Streaming of | ||
| 190 | + reasoning already existed; now verified with real Qwen3 on the Mac. Linux 123, Mac 135, gate PASS | ||
| 191 | + (run #13). Comment #2 on #37. | ||
modified
.memory/summary.md +4 -2 | @@ -59,7 +59,9 @@ server side (`StopSequenceFilter` in Core); the chat route closes the connection | ||
| 59 | 59 | stream ends; a vanished streaming client is noticed by a failed write, so SSE sends a `: keep-alive` |
| 60 | 60 | comment every 5 s. Reasoning (#37): `reasoning_content` on message and deltas; per request |
| 61 | 61 | `chat_template_kwargs.enable_thinking` > `reasoning_effort` (none/minimal off) > config default; |
| 62 | -budget only via the `thinking_budget` extension field; engine errors caused by a request setting | |
| 62 | +budget only via the `thinking_budget` extension field; hidden with `show_reasoning: false` | |
| 63 | +(config `defaults`/`locked`) or `include_reasoning: false` (request) — the model still thinks and | |
| 64 | +`reasoning_tokens` still counts; engine errors caused by a request setting | |
| 63 | 65 | adopt `RequestSettingError` (Core) → 400. Next: #38 constrained-decoding spike. |
| 64 | 66 | |
| 65 | 67 | ## Architecture of v0.1 (agent, removed on the v0.2 branch) |
| @@ -151,7 +153,7 @@ razorbill`, `host.sh run . rzb <args>` (no TTY: `rzb run` only); host-runner tes | ||
| 151 | 153 | (`@testable import`). Sandbox started on the Mac with `sbx env run --force` (`sbxenv.yaml`). |
| 152 | 154 | Lint: `swiftlint lint --quiet Sources Tests` and `swift-format` (4 spaces); keep wrapped |
| 153 | 155 | signatures as `) throws -> T {` or on one line (the two tools fight over brace placement). |
| 154 | -Tests 2026-11-24 (v0.1): Linux 121, Mac 126. Tests 2026-11-25 (v0.2 after #37): Linux 120, Mac 131 (incl. `ChatSmokeTests`: real | |
| 156 | +Tests 2026-11-24 (v0.1): Linux 121, Mac 126. Tests 2026-11-25 (v0.2 after #37): Linux 123, Mac 135 (incl. `ChatSmokeTests`: real | |
| 155 | 157 | Qwen3-0.6B-4bit through ModelManager + MLXEngine, enabled only when the model is in the HF cache). |
| 156 | 158 | Server tests start the real server on a random port (`HummingbirdTesting` `.live`). |
| 157 | 159 | |
| @@ -59,7 +59,9 @@ server side (`StopSequenceFilter` in Core); the chat route closes the connection | |||
| 59 | stream ends; a vanished streaming client is noticed by a failed write, so SSE sends a `: keep-alive` | 59 | stream ends; a vanished streaming client is noticed by a failed write, so SSE sends a `: keep-alive` |
| 60 | comment every 5 s. Reasoning (#37): `reasoning_content` on message and deltas; per request | 60 | comment every 5 s. Reasoning (#37): `reasoning_content` on message and deltas; per request |
| 61 | `chat_template_kwargs.enable_thinking` > `reasoning_effort` (none/minimal off) > config default; | 61 | `chat_template_kwargs.enable_thinking` > `reasoning_effort` (none/minimal off) > config default; |
| 62 | -budget only via the `thinking_budget` extension field; engine errors caused by a request setting | 62 | +budget only via the `thinking_budget` extension field; hidden with `show_reasoning: false` |
| 63 | +(config `defaults`/`locked`) or `include_reasoning: false` (request) — the model still thinks and | ||
| 64 | +`reasoning_tokens` still counts; engine errors caused by a request setting | ||
| 63 | adopt `RequestSettingError` (Core) → 400. Next: #38 constrained-decoding spike. | 65 | adopt `RequestSettingError` (Core) → 400. Next: #38 constrained-decoding spike. |
| 64 | 66 | ||
| 65 | ## Architecture of v0.1 (agent, removed on the v0.2 branch) | 67 | ## Architecture of v0.1 (agent, removed on the v0.2 branch) |
| @@ -151,7 +153,7 @@ razorbill`, `host.sh run . rzb <args>` (no TTY: `rzb run` only); host-runner tes | |||
| 151 | (`@testable import`). Sandbox started on the Mac with `sbx env run --force` (`sbxenv.yaml`). | 153 | (`@testable import`). Sandbox started on the Mac with `sbx env run --force` (`sbxenv.yaml`). |
| 152 | Lint: `swiftlint lint --quiet Sources Tests` and `swift-format` (4 spaces); keep wrapped | 154 | Lint: `swiftlint lint --quiet Sources Tests` and `swift-format` (4 spaces); keep wrapped |
| 153 | signatures as `) throws -> T {` or on one line (the two tools fight over brace placement). | 155 | signatures as `) throws -> T {` or on one line (the two tools fight over brace placement). |
| 154 | -Tests 2026-11-24 (v0.1): Linux 121, Mac 126. Tests 2026-11-25 (v0.2 after #37): Linux 120, Mac 131 (incl. `ChatSmokeTests`: real | 156 | +Tests 2026-11-24 (v0.1): Linux 121, Mac 126. Tests 2026-11-25 (v0.2 after #37): Linux 123, Mac 135 (incl. `ChatSmokeTests`: real |
| 155 | Qwen3-0.6B-4bit through ModelManager + MLXEngine, enabled only when the model is in the HF cache). | 157 | Qwen3-0.6B-4bit through ModelManager + MLXEngine, enabled only when the model is in the HF cache). |
| 156 | Server tests start the real server on a random port (`HummingbirdTesting` `.live`). | 158 | Server tests start the real server on a random port (`HummingbirdTesting` `.live`). |
| 157 | 159 | ||
modified
.quality/history.jsonl +1 -0 | @@ -10,3 +10,4 @@ | ||
| 10 | 10 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "4d3623e", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 156, "complex": 296, "cyclo": 369, "fields": 670, "funcs": 349, "lcom": 73, "lines": 6345, "loc": 4948}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 10, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:29:06Z"} |
| 11 | 11 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "6a3f52a", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 169, "complex": 325, "cyclo": 390, "fields": 725, "funcs": 372, "lcom": 75, "lines": 6771, "loc": 5299}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 11, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:38:59Z"} |
| 12 | 12 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "d8981f3", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 171, "complex": 329, "cyclo": 395, "fields": 758, "funcs": 384, "lcom": 76, "lines": 6999, "loc": 5488}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 12, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:48:22Z"} |
| 13 | +{"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "7cdd37d", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 171, "complex": 338, "cyclo": 401, "fields": 770, "funcs": 390, "lcom": 77, "lines": 7106, "loc": 5580}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 13, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:55:33Z"} | |
| @@ -10,3 +10,4 @@ | |||
| 10 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "4d3623e", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 156, "complex": 296, "cyclo": 369, "fields": 670, "funcs": 349, "lcom": 73, "lines": 6345, "loc": 4948}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 10, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:29:06Z"} | 10 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "4d3623e", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 156, "complex": 296, "cyclo": 369, "fields": 670, "funcs": 349, "lcom": 73, "lines": 6345, "loc": 4948}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 10, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:29:06Z"} |
| 11 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "6a3f52a", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 169, "complex": 325, "cyclo": 390, "fields": 725, "funcs": 372, "lcom": 75, "lines": 6771, "loc": 5299}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 11, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:38:59Z"} | 11 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "6a3f52a", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 169, "complex": 325, "cyclo": 390, "fields": 725, "funcs": 372, "lcom": 75, "lines": 6771, "loc": 5299}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 11, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:38:59Z"} |
| 12 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "d8981f3", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 171, "complex": 329, "cyclo": 395, "fields": 758, "funcs": 384, "lcom": 76, "lines": 6999, "loc": 5488}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 12, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:48:22Z"} | 12 | {"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "d8981f3", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 171, "complex": 329, "cyclo": 395, "fields": 758, "funcs": 384, "lcom": 76, "lines": 6999, "loc": 5488}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 12, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:48:22Z"} |
| 13 | +{"branch": "feature/v0.2-openai-server", "breaches": [], "commit": "7cdd37d", "counts": {}, "gate": {"max_error": 0, "max_smells": 0, "max_warning": 0}, "gate_passed": true, "metrics": {"classes": 171, "complex": 338, "cyclo": 401, "fields": 770, "funcs": 390, "lcom": 77, "lines": 7106, "loc": 5580}, "qlty_version": "qlty 0.672.0 linux-arm64 (4362b62 2026-11-20)", "run": 13, "smells": 0, "swiftlint_version": "0.65.1", "timestamp": "2026-11-25T12:55:33Z"} | ||
added
.quality/report-20261125T125533Z.md +73 -0 | new file mode 100644 | ||
| @@ -0,0 +1,73 @@ | ||
| 1 | +# Quality report — 2026-11-25T12:55:33Z | |
| 2 | + | |
| 3 | +- **Gate**: ✅ **PASS** | |
| 4 | +- **Commit**: `7cdd37d` on `feature/v0.2-openai-server` | |
| 5 | +- **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) | |
| 6 | +- **swiftlint**: 0.65.1 (run directly, merged into lint issues) | |
| 7 | +- **Run**: #13 (previous: 2026-11-25T12:48:22Z) | |
| 8 | + | |
| 9 | +## Lint issues (`qlty check`) | |
| 10 | + | |
| 11 | +_none_ | |
| 12 | + | |
| 13 | +### Top rules | |
| 14 | + | |
| 15 | +_none_ | |
| 16 | + | |
| 17 | +### Most affected files | |
| 18 | + | |
| 19 | +_none_ | |
| 20 | + | |
| 21 | +## Code smells (`qlty smells`) | |
| 22 | + | |
| 23 | +Total: **0** (vs previous: ±0) | |
| 24 | + | |
| 25 | +_none_ | |
| 26 | + | |
| 27 | +## Metrics (`qlty metrics`) | |
| 28 | + | |
| 29 | +| metric | total | vs previous | | |
| 30 | +|---|---|---| | |
| 31 | +| funcs | 390 | +6 | | |
| 32 | +| classes | 171 | ±0 | | |
| 33 | +| fields | 770 | +12 | | |
| 34 | +| cyclo | 401 | +6 | | |
| 35 | +| complex | 338 | +9 | | |
| 36 | +| lcom | 77 | +1 | | |
| 37 | +| lines | 7106 | +107 | | |
| 38 | +| loc | 5580 | +92 | | |
| 39 | + | |
| 40 | +### Most complex files | |
| 41 | + | |
| 42 | +| file | complex | cyclo | loc | | |
| 43 | +|---|---|---|---| | |
| 44 | +| Sources/RazorbillServer/Chat/CompletionStream.swift | 27 | 17 | 109 | | |
| 45 | +| tools/host-runner/host_runner.py | 22 | 22 | 141 | | |
| 46 | +| Sources/RazorbillMLX/MLXEngine.swift | 21 | 33 | 206 | | |
| 47 | +| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 215 | | |
| 48 | +| Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 133 | | |
| 49 | +| Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | | |
| 50 | +| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 266 | | |
| 51 | +| Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | | |
| 52 | +| Sources/RazorbillCore/Config/GenerationOverrides.swift | 12 | 13 | 51 | | |
| 53 | +| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 135 | | |
| 54 | +| Tests/RazorbillServerTests/ModelManagerTests.swift | 11 | 9 | 253 | | |
| 55 | +| Sources/RazorbillCLI/Commands/ServeCommand.swift | 10 | 7 | 79 | | |
| 56 | +| Sources/RazorbillCore/Engine/ThinkingSplitter.swift | 10 | 8 | 54 | | |
| 57 | +| Sources/RazorbillCore/Config/ConfigReader.swift | 9 | 14 | 89 | | |
| 58 | +| Sources/RazorbillCore/Models/ModelCatalog.swift | 9 | 9 | 77 | | |
| 59 | + | |
| 60 | +## Trend | |
| 61 | + | |
| 62 | +| run | timestamp | error | warning | smells | complex | gate | | |
| 63 | +|---|---|---|---|---|---|---| | |
| 64 | +| 4 | 2026-11-25T07:51:14Z | 0 | 0 | 0 | 153 | PASS | | |
| 65 | +| 5 | 2026-11-25T08:05:17Z | 0 | 0 | 0 | 198 | PASS | | |
| 66 | +| 6 | 2026-11-25T12:12:54Z | 0 | 0 | 0 | 228 | PASS | | |
| 67 | +| 7 | 2026-11-25T12:28:23Z | 0 | 0 | 1 | 311 | FAIL | | |
| 68 | +| 8 | 2026-11-25T12:28:48Z | 0 | 1 | 0 | 296 | FAIL | | |
| 69 | +| 9 | 2026-11-25T12:29:03Z | 0 | 0 | 0 | 296 | PASS | | |
| 70 | +| 10 | 2026-11-25T12:29:06Z | 0 | 0 | 0 | 296 | PASS | | |
| 71 | +| 11 | 2026-11-25T12:38:59Z | 0 | 0 | 0 | 325 | PASS | | |
| 72 | +| 12 | 2026-11-25T12:48:22Z | 0 | 0 | 0 | 329 | PASS | | |
| 73 | +| 13 | 2026-11-25T12:55:33Z | 0 | 0 | 0 | 338 | PASS | | |
| new file mode 100644 | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | +# Quality report — 2026-11-25T12:55:33Z | ||
| 2 | + | ||
| 3 | +- **Gate**: ✅ **PASS** | ||
| 4 | +- **Commit**: `7cdd37d` on `feature/v0.2-openai-server` | ||
| 5 | +- **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) | ||
| 6 | +- **swiftlint**: 0.65.1 (run directly, merged into lint issues) | ||
| 7 | +- **Run**: #13 (previous: 2026-11-25T12:48:22Z) | ||
| 8 | + | ||
| 9 | +## Lint issues (`qlty check`) | ||
| 10 | + | ||
| 11 | +_none_ | ||
| 12 | + | ||
| 13 | +### Top rules | ||
| 14 | + | ||
| 15 | +_none_ | ||
| 16 | + | ||
| 17 | +### Most affected files | ||
| 18 | + | ||
| 19 | +_none_ | ||
| 20 | + | ||
| 21 | +## Code smells (`qlty smells`) | ||
| 22 | + | ||
| 23 | +Total: **0** (vs previous: ±0) | ||
| 24 | + | ||
| 25 | +_none_ | ||
| 26 | + | ||
| 27 | +## Metrics (`qlty metrics`) | ||
| 28 | + | ||
| 29 | +| metric | total | vs previous | | ||
| 30 | +|---|---|---| | ||
| 31 | +| funcs | 390 | +6 | | ||
| 32 | +| classes | 171 | ±0 | | ||
| 33 | +| fields | 770 | +12 | | ||
| 34 | +| cyclo | 401 | +6 | | ||
| 35 | +| complex | 338 | +9 | | ||
| 36 | +| lcom | 77 | +1 | | ||
| 37 | +| lines | 7106 | +107 | | ||
| 38 | +| loc | 5580 | +92 | | ||
| 39 | + | ||
| 40 | +### Most complex files | ||
| 41 | + | ||
| 42 | +| file | complex | cyclo | loc | | ||
| 43 | +|---|---|---|---| | ||
| 44 | +| Sources/RazorbillServer/Chat/CompletionStream.swift | 27 | 17 | 109 | | ||
| 45 | +| tools/host-runner/host_runner.py | 22 | 22 | 141 | | ||
| 46 | +| Sources/RazorbillMLX/MLXEngine.swift | 21 | 33 | 206 | | ||
| 47 | +| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 215 | | ||
| 48 | +| Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 133 | | ||
| 49 | +| Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | | ||
| 50 | +| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 266 | | ||
| 51 | +| Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | | ||
| 52 | +| Sources/RazorbillCore/Config/GenerationOverrides.swift | 12 | 13 | 51 | | ||
| 53 | +| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 135 | | ||
| 54 | +| Tests/RazorbillServerTests/ModelManagerTests.swift | 11 | 9 | 253 | | ||
| 55 | +| Sources/RazorbillCLI/Commands/ServeCommand.swift | 10 | 7 | 79 | | ||
| 56 | +| Sources/RazorbillCore/Engine/ThinkingSplitter.swift | 10 | 8 | 54 | | ||
| 57 | +| Sources/RazorbillCore/Config/ConfigReader.swift | 9 | 14 | 89 | | ||
| 58 | +| Sources/RazorbillCore/Models/ModelCatalog.swift | 9 | 9 | 77 | | ||
| 59 | + | ||
| 60 | +## Trend | ||
| 61 | + | ||
| 62 | +| run | timestamp | error | warning | smells | complex | gate | | ||
| 63 | +|---|---|---|---|---|---|---| | ||
| 64 | +| 4 | 2026-11-25T07:51:14Z | 0 | 0 | 0 | 153 | PASS | | ||
| 65 | +| 5 | 2026-11-25T08:05:17Z | 0 | 0 | 0 | 198 | PASS | | ||
| 66 | +| 6 | 2026-11-25T12:12:54Z | 0 | 0 | 0 | 228 | PASS | | ||
| 67 | +| 7 | 2026-11-25T12:28:23Z | 0 | 0 | 1 | 311 | FAIL | | ||
| 68 | +| 8 | 2026-11-25T12:28:48Z | 0 | 1 | 0 | 296 | FAIL | | ||
| 69 | +| 9 | 2026-11-25T12:29:03Z | 0 | 0 | 0 | 296 | PASS | | ||
| 70 | +| 10 | 2026-11-25T12:29:06Z | 0 | 0 | 0 | 296 | PASS | | ||
| 71 | +| 11 | 2026-11-25T12:38:59Z | 0 | 0 | 0 | 325 | PASS | | ||
| 72 | +| 12 | 2026-11-25T12:48:22Z | 0 | 0 | 0 | 329 | PASS | | ||
| 73 | +| 13 | 2026-11-25T12:55:33Z | 0 | 0 | 0 | 338 | PASS | | ||
modified
.quality/report-latest.md +17 -17 | @@ -1,10 +1,10 @@ | ||
| 1 | -# Quality report — 2026-11-25T12:48:22Z | |
| 1 | +# Quality report — 2026-11-25T12:55:33Z | |
| 2 | 2 | |
| 3 | 3 | - **Gate**: ✅ **PASS** |
| 4 | -- **Commit**: `d8981f3` on `feature/v0.2-openai-server` | |
| 4 | +- **Commit**: `7cdd37d` on `feature/v0.2-openai-server` | |
| 5 | 5 | - **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) |
| 6 | 6 | - **swiftlint**: 0.65.1 (run directly, merged into lint issues) |
| 7 | -- **Run**: #12 (previous: 2026-11-25T12:38:59Z) | |
| 7 | +- **Run**: #13 (previous: 2026-11-25T12:48:22Z) | |
| 8 | 8 | |
| 9 | 9 | ## Lint issues (`qlty check`) |
| 10 | 10 | |
| @@ -28,31 +28,31 @@ _none_ | ||
| 28 | 28 | |
| 29 | 29 | | metric | total | vs previous | |
| 30 | 30 | |---|---|---| |
| 31 | -| funcs | 384 | +12 | | |
| 32 | -| classes | 171 | +2 | | |
| 33 | -| fields | 758 | +33 | | |
| 34 | -| cyclo | 395 | +5 | | |
| 35 | -| complex | 329 | +4 | | |
| 36 | -| lcom | 76 | +1 | | |
| 37 | -| lines | 6999 | +228 | | |
| 38 | -| loc | 5488 | +189 | | |
| 31 | +| funcs | 390 | +6 | | |
| 32 | +| classes | 171 | ±0 | | |
| 33 | +| fields | 770 | +12 | | |
| 34 | +| cyclo | 401 | +6 | | |
| 35 | +| complex | 338 | +9 | | |
| 36 | +| lcom | 77 | +1 | | |
| 37 | +| lines | 7106 | +107 | | |
| 38 | +| loc | 5580 | +92 | | |
| 39 | 39 | |
| 40 | 40 | ### Most complex files |
| 41 | 41 | |
| 42 | 42 | | file | complex | cyclo | loc | |
| 43 | 43 | |---|---|---|---| |
| 44 | -| Sources/RazorbillServer/Chat/CompletionStream.swift | 25 | 16 | 106 | | |
| 44 | +| Sources/RazorbillServer/Chat/CompletionStream.swift | 27 | 17 | 109 | | |
| 45 | 45 | | tools/host-runner/host_runner.py | 22 | 22 | 141 | |
| 46 | 46 | | Sources/RazorbillMLX/MLXEngine.swift | 21 | 33 | 206 | |
| 47 | -| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 214 | | |
| 47 | +| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 215 | | |
| 48 | 48 | | Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 133 | |
| 49 | 49 | | Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | |
| 50 | -| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 264 | | |
| 50 | +| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 266 | | |
| 51 | 51 | | Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | |
| 52 | -| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 132 | | |
| 52 | +| Sources/RazorbillCore/Config/GenerationOverrides.swift | 12 | 13 | 51 | | |
| 53 | +| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 135 | | |
| 53 | 54 | | Tests/RazorbillServerTests/ModelManagerTests.swift | 11 | 9 | 253 | |
| 54 | 55 | | Sources/RazorbillCLI/Commands/ServeCommand.swift | 10 | 7 | 79 | |
| 55 | -| Sources/RazorbillCore/Config/GenerationOverrides.swift | 10 | 11 | 47 | | |
| 56 | 56 | | Sources/RazorbillCore/Engine/ThinkingSplitter.swift | 10 | 8 | 54 | |
| 57 | 57 | | Sources/RazorbillCore/Config/ConfigReader.swift | 9 | 14 | 89 | |
| 58 | 58 | | Sources/RazorbillCore/Models/ModelCatalog.swift | 9 | 9 | 77 | |
| @@ -61,7 +61,6 @@ _none_ | ||
| 61 | 61 | |
| 62 | 62 | | run | timestamp | error | warning | smells | complex | gate | |
| 63 | 63 | |---|---|---|---|---|---|---| |
| 64 | -| 3 | 2026-11-24T05:57:47Z | 0 | 0 | 0 | 358 | PASS | | |
| 65 | 64 | | 4 | 2026-11-25T07:51:14Z | 0 | 0 | 0 | 153 | PASS | |
| 66 | 65 | | 5 | 2026-11-25T08:05:17Z | 0 | 0 | 0 | 198 | PASS | |
| 67 | 66 | | 6 | 2026-11-25T12:12:54Z | 0 | 0 | 0 | 228 | PASS | |
| @@ -71,3 +70,4 @@ _none_ | ||
| 71 | 70 | | 10 | 2026-11-25T12:29:06Z | 0 | 0 | 0 | 296 | PASS | |
| 72 | 71 | | 11 | 2026-11-25T12:38:59Z | 0 | 0 | 0 | 325 | PASS | |
| 73 | 72 | | 12 | 2026-11-25T12:48:22Z | 0 | 0 | 0 | 329 | PASS | |
| 73 | +| 13 | 2026-11-25T12:55:33Z | 0 | 0 | 0 | 338 | PASS | | |
| @@ -1,10 +1,10 @@ | |||
| 1 | -# Quality report — 2026-11-25T12:48:22Z | 1 | +# Quality report — 2026-11-25T12:55:33Z |
| 2 | 2 | ||
| 3 | - **Gate**: ✅ **PASS** | 3 | - **Gate**: ✅ **PASS** |
| 4 | -- **Commit**: `d8981f3` on `feature/v0.2-openai-server` | 4 | +- **Commit**: `7cdd37d` on `feature/v0.2-openai-server` |
| 5 | - **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) | 5 | - **qlty**: qlty 0.672.0 linux-arm64 (4362b62 2026-11-20) |
| 6 | - **swiftlint**: 0.65.1 (run directly, merged into lint issues) | 6 | - **swiftlint**: 0.65.1 (run directly, merged into lint issues) |
| 7 | -- **Run**: #12 (previous: 2026-11-25T12:38:59Z) | 7 | +- **Run**: #13 (previous: 2026-11-25T12:48:22Z) |
| 8 | 8 | ||
| 9 | ## Lint issues (`qlty check`) | 9 | ## Lint issues (`qlty check`) |
| 10 | 10 | ||
| @@ -28,31 +28,31 @@ _none_ | |||
| 28 | 28 | ||
| 29 | | metric | total | vs previous | | 29 | | metric | total | vs previous | |
| 30 | |---|---|---| | 30 | |---|---|---| |
| 31 | -| funcs | 384 | +12 | | 31 | +| funcs | 390 | +6 | |
| 32 | -| classes | 171 | +2 | | 32 | +| classes | 171 | ±0 | |
| 33 | -| fields | 758 | +33 | | 33 | +| fields | 770 | +12 | |
| 34 | -| cyclo | 395 | +5 | | 34 | +| cyclo | 401 | +6 | |
| 35 | -| complex | 329 | +4 | | 35 | +| complex | 338 | +9 | |
| 36 | -| lcom | 76 | +1 | | 36 | +| lcom | 77 | +1 | |
| 37 | -| lines | 6999 | +228 | | 37 | +| lines | 7106 | +107 | |
| 38 | -| loc | 5488 | +189 | | 38 | +| loc | 5580 | +92 | |
| 39 | 39 | ||
| 40 | ### Most complex files | 40 | ### Most complex files |
| 41 | 41 | ||
| 42 | | file | complex | cyclo | loc | | 42 | | file | complex | cyclo | loc | |
| 43 | |---|---|---|---| | 43 | |---|---|---|---| |
| 44 | -| Sources/RazorbillServer/Chat/CompletionStream.swift | 25 | 16 | 106 | | 44 | +| Sources/RazorbillServer/Chat/CompletionStream.swift | 27 | 17 | 109 | |
| 45 | | tools/host-runner/host_runner.py | 22 | 22 | 141 | | 45 | | tools/host-runner/host_runner.py | 22 | 22 | 141 | |
| 46 | | Sources/RazorbillMLX/MLXEngine.swift | 21 | 33 | 206 | | 46 | | Sources/RazorbillMLX/MLXEngine.swift | 21 | 33 | 206 | |
| 47 | -| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 214 | | 47 | +| Sources/RazorbillCore/Config/ServerConfigLoader.swift | 20 | 17 | 215 | |
| 48 | | Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 133 | | 48 | | Sources/RazorbillServer/Chat/ChatCompletionChunk.swift | 16 | 11 | 133 | |
| 49 | | Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | | 49 | | Sources/RazorbillServer/ModelManager.swift | 16 | 22 | 220 | |
| 50 | -| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 264 | | 50 | +| Sources/RazorbillServer/Chat/ChatCompletionRequest.swift | 14 | 22 | 266 | |
| 51 | | Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | | 51 | | Sources/RazorbillCLI/Commands/ModelsCommand.swift | 13 | 7 | 100 | |
| 52 | -| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 132 | | 52 | +| Sources/RazorbillCore/Config/GenerationOverrides.swift | 12 | 13 | 51 | |
| 53 | +| Sources/RazorbillServer/Chat/ChatCompletionRoute.swift | 11 | 12 | 135 | | ||
| 53 | | Tests/RazorbillServerTests/ModelManagerTests.swift | 11 | 9 | 253 | | 54 | | Tests/RazorbillServerTests/ModelManagerTests.swift | 11 | 9 | 253 | |
| 54 | | Sources/RazorbillCLI/Commands/ServeCommand.swift | 10 | 7 | 79 | | 55 | | Sources/RazorbillCLI/Commands/ServeCommand.swift | 10 | 7 | 79 | |
| 55 | -| Sources/RazorbillCore/Config/GenerationOverrides.swift | 10 | 11 | 47 | | ||
| 56 | | Sources/RazorbillCore/Engine/ThinkingSplitter.swift | 10 | 8 | 54 | | 56 | | Sources/RazorbillCore/Engine/ThinkingSplitter.swift | 10 | 8 | 54 | |
| 57 | | Sources/RazorbillCore/Config/ConfigReader.swift | 9 | 14 | 89 | | 57 | | Sources/RazorbillCore/Config/ConfigReader.swift | 9 | 14 | 89 | |
| 58 | | Sources/RazorbillCore/Models/ModelCatalog.swift | 9 | 9 | 77 | | 58 | | Sources/RazorbillCore/Models/ModelCatalog.swift | 9 | 9 | 77 | |
| @@ -61,7 +61,6 @@ _none_ | |||
| 61 | 61 | ||
| 62 | | run | timestamp | error | warning | smells | complex | gate | | 62 | | run | timestamp | error | warning | smells | complex | gate | |
| 63 | |---|---|---|---|---|---|---| | 63 | |---|---|---|---|---|---|---| |
| 64 | -| 3 | 2026-11-24T05:57:47Z | 0 | 0 | 0 | 358 | PASS | | ||
| 65 | | 4 | 2026-11-25T07:51:14Z | 0 | 0 | 0 | 153 | PASS | | 64 | | 4 | 2026-11-25T07:51:14Z | 0 | 0 | 0 | 153 | PASS | |
| 66 | | 5 | 2026-11-25T08:05:17Z | 0 | 0 | 0 | 198 | PASS | | 65 | | 5 | 2026-11-25T08:05:17Z | 0 | 0 | 0 | 198 | PASS | |
| 67 | | 6 | 2026-11-25T12:12:54Z | 0 | 0 | 0 | 228 | PASS | | 66 | | 6 | 2026-11-25T12:12:54Z | 0 | 0 | 0 | 228 | PASS | |
| @@ -71,3 +70,4 @@ _none_ | |||
| 71 | | 10 | 2026-11-25T12:29:06Z | 0 | 0 | 0 | 296 | PASS | | 70 | | 10 | 2026-11-25T12:29:06Z | 0 | 0 | 0 | 296 | PASS | |
| 72 | | 11 | 2026-11-25T12:38:59Z | 0 | 0 | 0 | 325 | PASS | | 71 | | 11 | 2026-11-25T12:38:59Z | 0 | 0 | 0 | 325 | PASS | |
| 73 | | 12 | 2026-11-25T12:48:22Z | 0 | 0 | 0 | 329 | PASS | | 72 | | 12 | 2026-11-25T12:48:22Z | 0 | 0 | 0 | 329 | PASS | |
| 73 | +| 13 | 2026-11-25T12:55:33Z | 0 | 0 | 0 | 338 | PASS | | ||
modified
.tickets/issues/0037-reasoning-models-over-the-api-reasoning-content.yaml +11 -2 | @@ -6,7 +6,7 @@ author: | ||
| 6 | 6 | name: k33g |
| 7 | 7 | email: ph.charriere@gmail.com |
| 8 | 8 | createdAt: 2026-11-24T21:17:08.000Z |
| 9 | -updatedAt: 2026-11-25T12:55:00.000Z | |
| 9 | +updatedAt: 2026-11-25T13:10:00.000Z | |
| 10 | 10 | labels: |
| 11 | 11 | - "kind::feature" |
| 12 | 12 | - "area::engine" |
| @@ -94,4 +94,13 @@ comments: | ||
| 94 | 94 | - `usage.completion_tokens_details.reasoning_tokens`: number of reasoning pieces (≈ tokens; MLX gives no separate count), written only when > 0. |
| 95 | 95 | Note: with Qwen3, mlx-swift-lm closes a budget with a ~20-token transition sentence that is part of the reasoning (budget 16 → 37 reasoning tokens observed). |
| 96 | 96 | Tests: 13 server tests + 2 Mac smoke tests with Qwen3-0.6B (reasoning apart from the answer; budget shortens it). Linux 120, Mac 131, gate PASS. |
| 97 | - | |
| 97 | + - id: 2 | |
| 98 | + author: | |
| 99 | + name: k33g | |
| 100 | + email: ph.charriere@gmail.com | |
| 101 | + createdAt: 2026-11-25T13:10:00.000Z | |
| 102 | + body: | | |
| 103 | + User's follow-up (2026-11-25): an option to hide the reasoning, and reasoning must be streamed. | |
| 104 | + - Hide: `show_reasoning` (bool, default true) in the configuration's `defaults` / `locked` (server-wide or per model), and `include_reasoning` per request (OpenRouter's convention). `locked: { show_reasoning: false }` cannot be overridden by clients. When hidden, the model still thinks; nothing of it is sent (message or stream), and `reasoning_tokens` still counts it. | |
| 105 | + - Streaming: reasoning was already sent as `delta.reasoning_content`; now also checked on the Mac with real Qwen3 (reasoning deltas token by token, all before the answer; none when hidden). | |
| 106 | + Tests: +3 server, +1 loader, +1 Mac smoke. Linux 123, Mac 135, gate PASS. | |
| @@ -6,7 +6,7 @@ author: | |||
| 6 | name: k33g | 6 | name: k33g |
| 7 | email: ph.charriere@gmail.com | 7 | email: ph.charriere@gmail.com |
| 8 | createdAt: 2026-11-24T21:17:08.000Z | 8 | createdAt: 2026-11-24T21:17:08.000Z |
| 9 | -updatedAt: 2026-11-25T12:55:00.000Z | 9 | +updatedAt: 2026-11-25T13:10:00.000Z |
| 10 | labels: | 10 | labels: |
| 11 | - "kind::feature" | 11 | - "kind::feature" |
| 12 | - "area::engine" | 12 | - "area::engine" |
| @@ -94,4 +94,13 @@ comments: | |||
| 94 | - `usage.completion_tokens_details.reasoning_tokens`: number of reasoning pieces (≈ tokens; MLX gives no separate count), written only when > 0. | 94 | - `usage.completion_tokens_details.reasoning_tokens`: number of reasoning pieces (≈ tokens; MLX gives no separate count), written only when > 0. |
| 95 | Note: with Qwen3, mlx-swift-lm closes a budget with a ~20-token transition sentence that is part of the reasoning (budget 16 → 37 reasoning tokens observed). | 95 | Note: with Qwen3, mlx-swift-lm closes a budget with a ~20-token transition sentence that is part of the reasoning (budget 16 → 37 reasoning tokens observed). |
| 96 | Tests: 13 server tests + 2 Mac smoke tests with Qwen3-0.6B (reasoning apart from the answer; budget shortens it). Linux 120, Mac 131, gate PASS. | 96 | Tests: 13 server tests + 2 Mac smoke tests with Qwen3-0.6B (reasoning apart from the answer; budget shortens it). Linux 120, Mac 131, gate PASS. |
| 97 | - | 97 | + - id: 2 |
| 98 | + author: | ||
| 99 | + name: k33g | ||
| 100 | + email: ph.charriere@gmail.com | ||
| 101 | + createdAt: 2026-11-25T13:10:00.000Z | ||
| 102 | + body: | | ||
| 103 | + User's follow-up (2026-11-25): an option to hide the reasoning, and reasoning must be streamed. | ||
| 104 | + - Hide: `show_reasoning` (bool, default true) in the configuration's `defaults` / `locked` (server-wide or per model), and `include_reasoning` per request (OpenRouter's convention). `locked: { show_reasoning: false }` cannot be overridden by clients. When hidden, the model still thinks; nothing of it is sent (message or stream), and `reasoning_tokens` still counts it. | ||
| 105 | + - Streaming: reasoning was already sent as `delta.reasoning_content`; now also checked on the Mac with real Qwen3 (reasoning deltas token by token, all before the answer; none when hidden). | ||
| 106 | + Tests: +3 server, +1 loader, +1 Mac smoke. Linux 123, Mac 135, gate PASS. | ||
modified
Sources/RazorbillCore/Config/GenerationOverrides.swift +9 -3 | @@ -14,16 +14,19 @@ public struct GenerationOverrides: Sendable, Equatable { | ||
| 14 | 14 | public var maxTokens: Int? |
| 15 | 15 | public var thinking: Bool? |
| 16 | 16 | public var thinkingBudget: Int? |
| 17 | + /// `show_reasoning`: send the model's reasoning to clients. | |
| 18 | + public var showReasoning: Bool? | |
| 17 | 19 | |
| 18 | 20 | public init( |
| 19 | 21 | temperature: Double? = nil, topP: Double? = nil, maxTokens: Int? = nil, |
| 20 | - thinking: Bool? = nil, thinkingBudget: Int? = nil | |
| 22 | + thinking: Bool? = nil, thinkingBudget: Int? = nil, showReasoning: Bool? = nil | |
| 21 | 23 | ) { |
| 22 | 24 | self.temperature = temperature |
| 23 | 25 | self.topP = topP |
| 24 | 26 | self.maxTokens = maxTokens |
| 25 | 27 | self.thinking = thinking |
| 26 | 28 | self.thinkingBudget = thinkingBudget |
| 29 | + self.showReasoning = showReasoning | |
| 27 | 30 | } |
| 28 | 31 | |
| 29 | 32 | /// No setting given. |
| @@ -37,16 +40,19 @@ public struct GenerationOverrides: Sendable, Equatable { | ||
| 37 | 40 | if let maxTokens { result.maxTokens = maxTokens } |
| 38 | 41 | if let thinking { result.thinking = thinking } |
| 39 | 42 | if let thinkingBudget { result.thinkingBudget = thinkingBudget } |
| 43 | + if let showReasoning { result.showReasoning = showReasoning } | |
| 40 | 44 | return result |
| 41 | 45 | } |
| 42 | 46 | |
| 43 | - /// `settings` with this block enforced as locked values: `temperature`, `topP` and `thinking` | |
| 44 | - /// are imposed; `maxTokens` and `thinkingBudget` are ceilings (a smaller request is kept). | |
| 47 | + /// `settings` with this block enforced as locked values: `temperature`, `topP`, `thinking` | |
| 48 | + /// and `showReasoning` are imposed; `maxTokens` and `thinkingBudget` are ceilings (a smaller | |
| 49 | + /// request is kept). | |
| 45 | 50 | public func enforcing(on settings: GenerationSettings) -> GenerationSettings { |
| 46 | 51 | var result = settings |
| 47 | 52 | if let temperature { result.temperature = temperature } |
| 48 | 53 | if let topP { result.topP = topP } |
| 49 | 54 | if let thinking { result.thinking = thinking } |
| 55 | + if let showReasoning { result.showReasoning = showReasoning } | |
| 50 | 56 | if let maxTokens { result.maxTokens = min(result.maxTokens, maxTokens) } |
| 51 | 57 | if let thinkingBudget { |
| 52 | 58 | result.thinkingBudget = min(result.thinkingBudget ?? thinkingBudget, thinkingBudget) |
| @@ -14,16 +14,19 @@ public struct GenerationOverrides: Sendable, Equatable { | |||
| 14 | public var maxTokens: Int? | 14 | public var maxTokens: Int? |
| 15 | public var thinking: Bool? | 15 | public var thinking: Bool? |
| 16 | public var thinkingBudget: Int? | 16 | public var thinkingBudget: Int? |
| 17 | + /// `show_reasoning`: send the model's reasoning to clients. | ||
| 18 | + public var showReasoning: Bool? | ||
| 17 | 19 | ||
| 18 | public init( | 20 | public init( |
| 19 | temperature: Double? = nil, topP: Double? = nil, maxTokens: Int? = nil, | 21 | temperature: Double? = nil, topP: Double? = nil, maxTokens: Int? = nil, |
| 20 | - thinking: Bool? = nil, thinkingBudget: Int? = nil | 22 | + thinking: Bool? = nil, thinkingBudget: Int? = nil, showReasoning: Bool? = nil |
| 21 | ) { | 23 | ) { |
| 22 | self.temperature = temperature | 24 | self.temperature = temperature |
| 23 | self.topP = topP | 25 | self.topP = topP |
| 24 | self.maxTokens = maxTokens | 26 | self.maxTokens = maxTokens |
| 25 | self.thinking = thinking | 27 | self.thinking = thinking |
| 26 | self.thinkingBudget = thinkingBudget | 28 | self.thinkingBudget = thinkingBudget |
| 29 | + self.showReasoning = showReasoning | ||
| 27 | } | 30 | } |
| 28 | 31 | ||
| 29 | /// No setting given. | 32 | /// No setting given. |
| @@ -37,16 +40,19 @@ public struct GenerationOverrides: Sendable, Equatable { | |||
| 37 | if let maxTokens { result.maxTokens = maxTokens } | 40 | if let maxTokens { result.maxTokens = maxTokens } |
| 38 | if let thinking { result.thinking = thinking } | 41 | if let thinking { result.thinking = thinking } |
| 39 | if let thinkingBudget { result.thinkingBudget = thinkingBudget } | 42 | if let thinkingBudget { result.thinkingBudget = thinkingBudget } |
| 43 | + if let showReasoning { result.showReasoning = showReasoning } | ||
| 40 | return result | 44 | return result |
| 41 | } | 45 | } |
| 42 | 46 | ||
| 43 | - /// `settings` with this block enforced as locked values: `temperature`, `topP` and `thinking` | 47 | + /// `settings` with this block enforced as locked values: `temperature`, `topP`, `thinking` |
| 44 | - /// are imposed; `maxTokens` and `thinkingBudget` are ceilings (a smaller request is kept). | 48 | + /// and `showReasoning` are imposed; `maxTokens` and `thinkingBudget` are ceilings (a smaller |
| 49 | + /// request is kept). | ||
| 45 | public func enforcing(on settings: GenerationSettings) -> GenerationSettings { | 50 | public func enforcing(on settings: GenerationSettings) -> GenerationSettings { |
| 46 | var result = settings | 51 | var result = settings |
| 47 | if let temperature { result.temperature = temperature } | 52 | if let temperature { result.temperature = temperature } |
| 48 | if let topP { result.topP = topP } | 53 | if let topP { result.topP = topP } |
| 49 | if let thinking { result.thinking = thinking } | 54 | if let thinking { result.thinking = thinking } |
| 55 | + if let showReasoning { result.showReasoning = showReasoning } | ||
| 50 | if let maxTokens { result.maxTokens = min(result.maxTokens, maxTokens) } | 56 | if let maxTokens { result.maxTokens = min(result.maxTokens, maxTokens) } |
| 51 | if let thinkingBudget { | 57 | if let thinkingBudget { |
| 52 | result.thinkingBudget = min(result.thinkingBudget ?? thinkingBudget, thinkingBudget) | 58 | result.thinkingBudget = min(result.thinkingBudget ?? thinkingBudget, thinkingBudget) |
modified
Sources/RazorbillCore/Config/ServerConfigLoader.swift +3 -2 | @@ -55,7 +55,7 @@ public struct ServerConfigLoader: Sendable { | ||
| 55 | 55 | static let topLevelKeys = ["server", "defaults", "locked", "models", "limits"] |
| 56 | 56 | static let serverKeys = ["host", "port", "api_key_env", "cors_origin"] |
| 57 | 57 | static let generationKeys = [ |
| 58 | - "temperature", "top_p", "max_tokens", "thinking", "thinking_budget", | |
| 58 | + "temperature", "top_p", "max_tokens", "thinking", "thinking_budget", "show_reasoning", | |
| 59 | 59 | ] |
| 60 | 60 | static let modelKeys = [ |
| 61 | 61 | "id", "source", "revision", "path", "kind", "preload", "defaults", "locked", |
| @@ -113,7 +113,8 @@ private struct Context { | ||
| 113 | 113 | ) { $0 > 0 && $0 <= 1 }, |
| 114 | 114 | maxTokens: whole(mapping, "max_tokens", path: path, atLeast: 1), |
| 115 | 115 | thinking: reader.bool(mapping, "thinking", path: path), |
| 116 | - thinkingBudget: whole(mapping, "thinking_budget", path: path, atLeast: 0)) | |
| 116 | + thinkingBudget: whole(mapping, "thinking_budget", path: path, atLeast: 0), | |
| 117 | + showReasoning: reader.bool(mapping, "show_reasoning", path: path)) | |
| 117 | 118 | if let budget = block.thinkingBudget, let maxTokens = block.maxTokens, budget >= maxTokens { |
| 118 | 119 | reader.report( |
| 119 | 120 | "\(path).thinking_budget", mapping["thinking_budget"], |
| @@ -55,7 +55,7 @@ public struct ServerConfigLoader: Sendable { | |||
| 55 | static let topLevelKeys = ["server", "defaults", "locked", "models", "limits"] | 55 | static let topLevelKeys = ["server", "defaults", "locked", "models", "limits"] |
| 56 | static let serverKeys = ["host", "port", "api_key_env", "cors_origin"] | 56 | static let serverKeys = ["host", "port", "api_key_env", "cors_origin"] |
| 57 | static let generationKeys = [ | 57 | static let generationKeys = [ |
| 58 | - "temperature", "top_p", "max_tokens", "thinking", "thinking_budget", | 58 | + "temperature", "top_p", "max_tokens", "thinking", "thinking_budget", "show_reasoning", |
| 59 | ] | 59 | ] |
| 60 | static let modelKeys = [ | 60 | static let modelKeys = [ |
| 61 | "id", "source", "revision", "path", "kind", "preload", "defaults", "locked", | 61 | "id", "source", "revision", "path", "kind", "preload", "defaults", "locked", |
| @@ -113,7 +113,8 @@ private struct Context { | |||
| 113 | ) { $0 > 0 && $0 <= 1 }, | 113 | ) { $0 > 0 && $0 <= 1 }, |
| 114 | maxTokens: whole(mapping, "max_tokens", path: path, atLeast: 1), | 114 | maxTokens: whole(mapping, "max_tokens", path: path, atLeast: 1), |
| 115 | thinking: reader.bool(mapping, "thinking", path: path), | 115 | thinking: reader.bool(mapping, "thinking", path: path), |
| 116 | - thinkingBudget: whole(mapping, "thinking_budget", path: path, atLeast: 0)) | 116 | + thinkingBudget: whole(mapping, "thinking_budget", path: path, atLeast: 0), |
| 117 | + showReasoning: reader.bool(mapping, "show_reasoning", path: path)) | ||
| 117 | if let budget = block.thinkingBudget, let maxTokens = block.maxTokens, budget >= maxTokens { | 118 | if let budget = block.thinkingBudget, let maxTokens = block.maxTokens, budget >= maxTokens { |
| 118 | reader.report( | 119 | reader.report( |
| 119 | "\(path).thinking_budget", mapping["thinking_budget"], | 120 | "\(path).thinking_budget", mapping["thinking_budget"], |
modified
Sources/RazorbillCore/Engine/GenerationSettings.swift +5 -1 | @@ -15,6 +15,8 @@ public struct GenerationSettings: Sendable, Equatable { | ||
| 15 | 15 | /// Most tokens a model may spend thinking before it is made to answer; `nil` = no limit. |
| 16 | 16 | /// Counted inside ``maxTokens``, so it must be smaller. Default `nil`. |
| 17 | 17 | public var thinkingBudget: Int? |
| 18 | + /// Send the model's reasoning to the client (it still thinks when this is false). Default true. | |
| 19 | + public var showReasoning: Bool | |
| 18 | 20 | /// Seed of the sampler, for reproducible answers at the same settings; `nil` = random. |
| 19 | 21 | public var seed: UInt64? |
| 20 | 22 | /// Additive penalty for tokens already present in the answer (OpenAI's `presence_penalty`). |
| @@ -24,7 +26,8 @@ public struct GenerationSettings: Sendable, Equatable { | ||
| 24 | 26 | |
| 25 | 27 | public init( |
| 26 | 28 | temperature: Double = 0.6, topP: Double = 1.0, maxTokens: Int = 1024, |
| 27 | - thinking: Bool = false, thinkingBudget: Int? = nil, seed: UInt64? = nil, | |
| 29 | + thinking: Bool = false, thinkingBudget: Int? = nil, showReasoning: Bool = true, | |
| 30 | + seed: UInt64? = nil, | |
| 28 | 31 | presencePenalty: Double? = nil, frequencyPenalty: Double? = nil |
| 29 | 32 | ) { |
| 30 | 33 | self.temperature = temperature |
| @@ -32,6 +35,7 @@ public struct GenerationSettings: Sendable, Equatable { | ||
| 32 | 35 | self.maxTokens = maxTokens |
| 33 | 36 | self.thinking = thinking |
| 34 | 37 | self.thinkingBudget = thinkingBudget |
| 38 | + self.showReasoning = showReasoning | |
| 35 | 39 | self.seed = seed |
| 36 | 40 | self.presencePenalty = presencePenalty |
| 37 | 41 | self.frequencyPenalty = frequencyPenalty |
| @@ -15,6 +15,8 @@ public struct GenerationSettings: Sendable, Equatable { | |||
| 15 | /// Most tokens a model may spend thinking before it is made to answer; `nil` = no limit. | 15 | /// Most tokens a model may spend thinking before it is made to answer; `nil` = no limit. |
| 16 | /// Counted inside ``maxTokens``, so it must be smaller. Default `nil`. | 16 | /// Counted inside ``maxTokens``, so it must be smaller. Default `nil`. |
| 17 | public var thinkingBudget: Int? | 17 | public var thinkingBudget: Int? |
| 18 | + /// Send the model's reasoning to the client (it still thinks when this is false). Default true. | ||
| 19 | + public var showReasoning: Bool | ||
| 18 | /// Seed of the sampler, for reproducible answers at the same settings; `nil` = random. | 20 | /// Seed of the sampler, for reproducible answers at the same settings; `nil` = random. |
| 19 | public var seed: UInt64? | 21 | public var seed: UInt64? |
| 20 | /// Additive penalty for tokens already present in the answer (OpenAI's `presence_penalty`). | 22 | /// Additive penalty for tokens already present in the answer (OpenAI's `presence_penalty`). |
| @@ -24,7 +26,8 @@ public struct GenerationSettings: Sendable, Equatable { | |||
| 24 | 26 | ||
| 25 | public init( | 27 | public init( |
| 26 | temperature: Double = 0.6, topP: Double = 1.0, maxTokens: Int = 1024, | 28 | temperature: Double = 0.6, topP: Double = 1.0, maxTokens: Int = 1024, |
| 27 | - thinking: Bool = false, thinkingBudget: Int? = nil, seed: UInt64? = nil, | 29 | + thinking: Bool = false, thinkingBudget: Int? = nil, showReasoning: Bool = true, |
| 30 | + seed: UInt64? = nil, | ||
| 28 | presencePenalty: Double? = nil, frequencyPenalty: Double? = nil | 31 | presencePenalty: Double? = nil, frequencyPenalty: Double? = nil |
| 29 | ) { | 32 | ) { |
| 30 | self.temperature = temperature | 33 | self.temperature = temperature |
| @@ -32,6 +35,7 @@ public struct GenerationSettings: Sendable, Equatable { | |||
| 32 | self.maxTokens = maxTokens | 35 | self.maxTokens = maxTokens |
| 33 | self.thinking = thinking | 36 | self.thinking = thinking |
| 34 | self.thinkingBudget = thinkingBudget | 37 | self.thinkingBudget = thinkingBudget |
| 38 | + self.showReasoning = showReasoning | ||
| 35 | self.seed = seed | 39 | self.seed = seed |
| 36 | self.presencePenalty = presencePenalty | 40 | self.presencePenalty = presencePenalty |
| 37 | self.frequencyPenalty = frequencyPenalty | 41 | self.frequencyPenalty = frequencyPenalty |
modified
Sources/RazorbillServer/Chat/ChatCompletionRequest.swift +4 -1 | @@ -27,6 +27,8 @@ struct ChatCompletionRequest: Decodable, Sendable { | ||
| 27 | 27 | var chatTemplateKwargs: ConfigValue? |
| 28 | 28 | /// razorbill extension: most tokens the model may think before it must answer. |
| 29 | 29 | var thinkingBudget: Int? |
| 30 | + /// OpenRouter's convention: `false` hides the reasoning (the model still thinks). | |
| 31 | + var includeReasoning: Bool? | |
| 30 | 32 | |
| 31 | 33 | enum CodingKeys: String, CodingKey { |
| 32 | 34 | case model, messages, temperature, stop, seed, stream, logprobs, tools |
| @@ -41,6 +43,7 @@ struct ChatCompletionRequest: Decodable, Sendable { | ||
| 41 | 43 | case reasoningEffort = "reasoning_effort" |
| 42 | 44 | case chatTemplateKwargs = "chat_template_kwargs" |
| 43 | 45 | case thinkingBudget = "thinking_budget" |
| 46 | + case includeReasoning = "include_reasoning" | |
| 44 | 47 | } |
| 45 | 48 | |
| 46 | 49 | /// Decodes a request body; malformed JSON or wrong types become a 400 naming the field. |
| @@ -172,7 +175,7 @@ extension ChatCompletionRequest { | ||
| 172 | 175 | messages: try messages.enumerated().map { try Self.message($1, at: $0) }, |
| 173 | 176 | client: GenerationOverrides( |
| 174 | 177 | temperature: temperature, topP: topP, maxTokens: limit, thinking: requestedThinking, |
| 175 | - thinkingBudget: thinkingBudget), | |
| 178 | + thinkingBudget: thinkingBudget, showReasoning: includeReasoning), | |
| 176 | 179 | seed: seed.map { UInt64(bitPattern: $0) }, |
| 177 | 180 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, |
| 178 | 181 | stops: stops, stream: stream ?? false, |
| @@ -27,6 +27,8 @@ struct ChatCompletionRequest: Decodable, Sendable { | |||
| 27 | var chatTemplateKwargs: ConfigValue? | 27 | var chatTemplateKwargs: ConfigValue? |
| 28 | /// razorbill extension: most tokens the model may think before it must answer. | 28 | /// razorbill extension: most tokens the model may think before it must answer. |
| 29 | var thinkingBudget: Int? | 29 | var thinkingBudget: Int? |
| 30 | + /// OpenRouter's convention: `false` hides the reasoning (the model still thinks). | ||
| 31 | + var includeReasoning: Bool? | ||
| 30 | 32 | ||
| 31 | enum CodingKeys: String, CodingKey { | 33 | enum CodingKeys: String, CodingKey { |
| 32 | case model, messages, temperature, stop, seed, stream, logprobs, tools | 34 | case model, messages, temperature, stop, seed, stream, logprobs, tools |
| @@ -41,6 +43,7 @@ struct ChatCompletionRequest: Decodable, Sendable { | |||
| 41 | case reasoningEffort = "reasoning_effort" | 43 | case reasoningEffort = "reasoning_effort" |
| 42 | case chatTemplateKwargs = "chat_template_kwargs" | 44 | case chatTemplateKwargs = "chat_template_kwargs" |
| 43 | case thinkingBudget = "thinking_budget" | 45 | case thinkingBudget = "thinking_budget" |
| 46 | + case includeReasoning = "include_reasoning" | ||
| 44 | } | 47 | } |
| 45 | 48 | ||
| 46 | /// Decodes a request body; malformed JSON or wrong types become a 400 naming the field. | 49 | /// Decodes a request body; malformed JSON or wrong types become a 400 naming the field. |
| @@ -172,7 +175,7 @@ extension ChatCompletionRequest { | |||
| 172 | messages: try messages.enumerated().map { try Self.message($1, at: $0) }, | 175 | messages: try messages.enumerated().map { try Self.message($1, at: $0) }, |
| 173 | client: GenerationOverrides( | 176 | client: GenerationOverrides( |
| 174 | temperature: temperature, topP: topP, maxTokens: limit, thinking: requestedThinking, | 177 | temperature: temperature, topP: topP, maxTokens: limit, thinking: requestedThinking, |
| 175 | - thinkingBudget: thinkingBudget), | 178 | + thinkingBudget: thinkingBudget, showReasoning: includeReasoning), |
| 176 | seed: seed.map { UInt64(bitPattern: $0) }, | 179 | seed: seed.map { UInt64(bitPattern: $0) }, |
| 177 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, | 180 | presencePenalty: presencePenalty, frequencyPenalty: frequencyPenalty, |
| 178 | stops: stops, stream: stream ?? false, | 181 | stops: stops, stream: stream ?? false, |
modified
Sources/RazorbillServer/Chat/ChatCompletionRoute.swift +15 -9 | @@ -103,10 +103,7 @@ struct ChatCompletionRoute { | ||
| 103 | 103 | let lease = try await models.acquire(plan.model) |
| 104 | 104 | let pieces: AsyncThrowingStream<CompletionPiece, Error> |
| 105 | 105 | do { |
| 106 | - let setup = SessionSetup( | |
| 107 | - system: "", tools: [], generation: plan.settings(for: lease.model)) | |
| 108 | - let session = try await lease.engine.makeSession(setup) | |
| 109 | - pieces = CompletionStream.pieces(from: session.send(plan.messages), stops: plan.stops) | |
| 106 | + pieces = try await Self.generate(plan, with: lease) | |
| 110 | 107 | } catch { |
| 111 | 108 | await lease.release() |
| 112 | 109 | throw error |
| @@ -118,11 +115,7 @@ struct ChatCompletionRoute { | ||
| 118 | 115 | |
| 119 | 116 | func complete(_ plan: ChatPlan) async throws -> ChatCompletionResponse { |
| 120 | 117 | try await models.withModel(plan.model) { lease in |
| 121 | - let setup = SessionSetup( | |
| 122 | - system: "", tools: [], generation: plan.settings(for: lease.model)) | |
| 123 | - let session = try await lease.engine.makeSession(setup) | |
| 124 | - let pieces = CompletionStream.pieces( | |
| 125 | - from: session.send(plan.messages), stops: plan.stops) | |
| 118 | + let pieces = try await Self.generate(plan, with: lease) | |
| 126 | 119 | var content = "" |
| 127 | 120 | var reasoning = "" |
| 128 | 121 | var calls: [WireToolCall] = [] |
| @@ -145,6 +138,19 @@ struct ChatCompletionRoute { | ||
| 145 | 138 | } |
| 146 | 139 | } |
| 147 | 140 | |
| 141 | + /// Starts the answer: a fresh session with the request's settings for this model, the whole | |
| 142 | + /// conversation, the stop sequences, and the reasoning hidden unless it may be shown. | |
| 143 | + static func generate( | |
| 144 | + _ plan: ChatPlan, with lease: ModelLease | |
| 145 | + ) async throws -> AsyncThrowingStream<CompletionPiece, Error> { | |
| 146 | + let settings = plan.settings(for: lease.model) | |
| 147 | + let session = try await lease.engine.makeSession( | |
| 148 | + SessionSetup(system: "", tools: [], generation: settings)) | |
| 149 | + return CompletionStream.pieces( | |
| 150 | + from: session.send(plan.messages), stops: plan.stops, | |
| 151 | + showReasoning: settings.showReasoning) | |
| 152 | + } | |
| 153 | + | |
| 148 | 154 | /// `chatcmpl-` followed by 24 random hexadecimal digits. |
| 149 | 155 | static func newID() -> String { |
| 150 | 156 | "chatcmpl-" |
| @@ -103,10 +103,7 @@ struct ChatCompletionRoute { | |||
| 103 | let lease = try await models.acquire(plan.model) | 103 | let lease = try await models.acquire(plan.model) |
| 104 | let pieces: AsyncThrowingStream<CompletionPiece, Error> | 104 | let pieces: AsyncThrowingStream<CompletionPiece, Error> |
| 105 | do { | 105 | do { |
| 106 | - let setup = SessionSetup( | 106 | + pieces = try await Self.generate(plan, with: lease) |
| 107 | - system: "", tools: [], generation: plan.settings(for: lease.model)) | ||
| 108 | - let session = try await lease.engine.makeSession(setup) | ||
| 109 | - pieces = CompletionStream.pieces(from: session.send(plan.messages), stops: plan.stops) | ||
| 110 | } catch { | 107 | } catch { |
| 111 | await lease.release() | 108 | await lease.release() |
| 112 | throw error | 109 | throw error |
| @@ -118,11 +115,7 @@ struct ChatCompletionRoute { | |||
| 118 | 115 | ||
| 119 | func complete(_ plan: ChatPlan) async throws -> ChatCompletionResponse { | 116 | func complete(_ plan: ChatPlan) async throws -> ChatCompletionResponse { |
| 120 | try await models.withModel(plan.model) { lease in | 117 | try await models.withModel(plan.model) { lease in |
| 121 | - let setup = SessionSetup( | 118 | + let pieces = try await Self.generate(plan, with: lease) |
| 122 | - system: "", tools: [], generation: plan.settings(for: lease.model)) | ||
| 123 | - let session = try await lease.engine.makeSession(setup) | ||
| 124 | - let pieces = CompletionStream.pieces( | ||
| 125 | - from: session.send(plan.messages), stops: plan.stops) | ||
| 126 | var content = "" | 119 | var content = "" |
| 127 | var reasoning = "" | 120 | var reasoning = "" |
| 128 | var calls: [WireToolCall] = [] | 121 | var calls: [WireToolCall] = [] |
| @@ -145,6 +138,19 @@ struct ChatCompletionRoute { | |||
| 145 | } | 138 | } |
| 146 | } | 139 | } |
| 147 | 140 | ||
| 141 | + /// Starts the answer: a fresh session with the request's settings for this model, the whole | ||
| 142 | + /// conversation, the stop sequences, and the reasoning hidden unless it may be shown. | ||
| 143 | + static func generate( | ||
| 144 | + _ plan: ChatPlan, with lease: ModelLease | ||
| 145 | + ) async throws -> AsyncThrowingStream<CompletionPiece, Error> { | ||
| 146 | + let settings = plan.settings(for: lease.model) | ||
| 147 | + let session = try await lease.engine.makeSession( | ||
| 148 | + SessionSetup(system: "", tools: [], generation: settings)) | ||
| 149 | + return CompletionStream.pieces( | ||
| 150 | + from: session.send(plan.messages), stops: plan.stops, | ||
| 151 | + showReasoning: settings.showReasoning) | ||
| 152 | + } | ||
| 153 | + | ||
| 148 | /// `chatcmpl-` followed by 24 random hexadecimal digits. | 154 | /// `chatcmpl-` followed by 24 random hexadecimal digits. |
| 149 | static func newID() -> String { | 155 | static func newID() -> String { |
| 150 | "chatcmpl-" | 156 | "chatcmpl-" |
modified
Sources/RazorbillServer/Chat/CompletionStream.swift +7 -3 | @@ -50,13 +50,16 @@ enum CompletionPiece: Sendable, Equatable { | ||
| 50 | 50 | /// When a stop sequence ends the answer, the engine is interrupted before it reports its token |
| 51 | 51 | /// counts: `usage` then counts one token per piece of text received, and no prompt tokens. |
| 52 | 52 | enum CompletionStream { |
| 53 | + /// With `showReasoning` false, reasoning is counted in `usage` but not passed on. | |
| 53 | 54 | static func pieces( |
| 54 | - from events: AsyncThrowingStream<EngineEvent, Error>, stops: [String] | |
| 55 | + from events: AsyncThrowingStream<EngineEvent, Error>, stops: [String], | |
| 56 | + showReasoning: Bool = true | |
| 55 | 57 | ) -> AsyncThrowingStream<CompletionPiece, Error> { |
| 56 | 58 | AsyncThrowingStream { continuation in |
| 57 | 59 | let task = Task { |
| 58 | 60 | do { |
| 59 | - var state = State(filter: StopSequenceFilter(stops)) | |
| 61 | + var state = State( | |
| 62 | + filter: StopSequenceFilter(stops), showReasoning: showReasoning) | |
| 60 | 63 | events: for try await event in events { |
| 61 | 64 | for piece in state.consume(event) { continuation.yield(piece) } |
| 62 | 65 | if state.filter.isStopped { break events } |
| @@ -74,6 +77,7 @@ enum CompletionStream { | ||
| 74 | 77 | /// What has been seen so far. |
| 75 | 78 | struct State { |
| 76 | 79 | var filter: StopSequenceFilter |
| 80 | + var showReasoning = true | |
| 77 | 81 | var stats: GenerationStats? |
| 78 | 82 | var calledTools = false |
| 79 | 83 | var textPieces = 0 |
| @@ -95,7 +99,7 @@ enum CompletionStream { | ||
| 95 | 99 | || !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty |
| 96 | 100 | guard reasoningStarted else { return [] } |
| 97 | 101 | reasoningPieces += 1 |
| 98 | - return [.reasoning(text)] | |
| 102 | + return showReasoning ? [.reasoning(text)] : [] | |
| 99 | 103 | case .toolCall(let call): |
| 100 | 104 | calledTools = true |
| 101 | 105 | return [.toolCall(call)] |
| @@ -50,13 +50,16 @@ enum CompletionPiece: Sendable, Equatable { | |||
| 50 | /// When a stop sequence ends the answer, the engine is interrupted before it reports its token | 50 | /// When a stop sequence ends the answer, the engine is interrupted before it reports its token |
| 51 | /// counts: `usage` then counts one token per piece of text received, and no prompt tokens. | 51 | /// counts: `usage` then counts one token per piece of text received, and no prompt tokens. |
| 52 | enum CompletionStream { | 52 | enum CompletionStream { |
| 53 | + /// With `showReasoning` false, reasoning is counted in `usage` but not passed on. | ||
| 53 | static func pieces( | 54 | static func pieces( |
| 54 | - from events: AsyncThrowingStream<EngineEvent, Error>, stops: [String] | 55 | + from events: AsyncThrowingStream<EngineEvent, Error>, stops: [String], |
| 56 | + showReasoning: Bool = true | ||
| 55 | ) -> AsyncThrowingStream<CompletionPiece, Error> { | 57 | ) -> AsyncThrowingStream<CompletionPiece, Error> { |
| 56 | AsyncThrowingStream { continuation in | 58 | AsyncThrowingStream { continuation in |
| 57 | let task = Task { | 59 | let task = Task { |
| 58 | do { | 60 | do { |
| 59 | - var state = State(filter: StopSequenceFilter(stops)) | 61 | + var state = State( |
| 62 | + filter: StopSequenceFilter(stops), showReasoning: showReasoning) | ||
| 60 | events: for try await event in events { | 63 | events: for try await event in events { |
| 61 | for piece in state.consume(event) { continuation.yield(piece) } | 64 | for piece in state.consume(event) { continuation.yield(piece) } |
| 62 | if state.filter.isStopped { break events } | 65 | if state.filter.isStopped { break events } |
| @@ -74,6 +77,7 @@ enum CompletionStream { | |||
| 74 | /// What has been seen so far. | 77 | /// What has been seen so far. |
| 75 | struct State { | 78 | struct State { |
| 76 | var filter: StopSequenceFilter | 79 | var filter: StopSequenceFilter |
| 80 | + var showReasoning = true | ||
| 77 | var stats: GenerationStats? | 81 | var stats: GenerationStats? |
| 78 | var calledTools = false | 82 | var calledTools = false |
| 79 | var textPieces = 0 | 83 | var textPieces = 0 |
| @@ -95,7 +99,7 @@ enum CompletionStream { | |||
| 95 | || !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty | 99 | || !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty |
| 96 | guard reasoningStarted else { return [] } | 100 | guard reasoningStarted else { return [] } |
| 97 | reasoningPieces += 1 | 101 | reasoningPieces += 1 |
| 98 | - return [.reasoning(text)] | 102 | + return showReasoning ? [.reasoning(text)] : [] |
| 99 | case .toolCall(let call): | 103 | case .toolCall(let call): |
| 100 | calledTools = true | 104 | calledTools = true |
| 101 | return [.toolCall(call)] | 105 | return [.toolCall(call)] |
modified
Tests/RazorbillCoreTests/ServerConfigLoaderTests.swift +9 -0 | @@ -17,6 +17,15 @@ import Testing | ||
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | + @Test func showReasoningIsAGenerationSetting() throws { | |
| 21 | + let config = try loader.parse("locked: { show_reasoning: false }\n") | |
| 22 | + #expect(config.locked == GenerationOverrides(showReasoning: false)) | |
| 23 | + let locked = GenerationOverrides.resolve( | |
| 24 | + defaults: [], client: GenerationOverrides(showReasoning: true), locked: [config.locked]) | |
| 25 | + #expect(!locked.showReasoning) | |
| 26 | + #expect(GenerationSettings().showReasoning) | |
| 27 | + } | |
| 28 | + | |
| 20 | 29 | @Test func emptyFileIsTheDefaultConfiguration() throws { |
| 21 | 30 | #expect(try loader.parse("") == ServerConfig()) |
| 22 | 31 | #expect(try loader.parse("# only a comment\n") == ServerConfig()) |
| @@ -17,6 +17,15 @@ import Testing | |||
| 17 | } | 17 | } |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | + @Test func showReasoningIsAGenerationSetting() throws { | ||
| 21 | + let config = try loader.parse("locked: { show_reasoning: false }\n") | ||
| 22 | + #expect(config.locked == GenerationOverrides(showReasoning: false)) | ||
| 23 | + let locked = GenerationOverrides.resolve( | ||
| 24 | + defaults: [], client: GenerationOverrides(showReasoning: true), locked: [config.locked]) | ||
| 25 | + #expect(!locked.showReasoning) | ||
| 26 | + #expect(GenerationSettings().showReasoning) | ||
| 27 | + } | ||
| 28 | + | ||
| 20 | @Test func emptyFileIsTheDefaultConfiguration() throws { | 29 | @Test func emptyFileIsTheDefaultConfiguration() throws { |
| 21 | #expect(try loader.parse("") == ServerConfig()) | 30 | #expect(try loader.parse("") == ServerConfig()) |
| 22 | #expect(try loader.parse("# only a comment\n") == ServerConfig()) | 31 | #expect(try loader.parse("# only a comment\n") == ServerConfig()) |
modified
Tests/RazorbillMLXTests/ChatSmokeTests.swift +32 -0 | @@ -55,6 +55,38 @@ struct ChatSmokeTests { | ||
| 55 | 55 | #expect(response.usage.reasoningTokens > 0) |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | + /// Streams `plan` and returns the reasoning and content deltas, in order. | |
| 59 | + func streamedDeltas(_ plan: ChatPlan) async throws -> [(reasoning: Bool, text: String)] { | |
| 60 | + let lease = try await models.acquire(smokeModel) | |
| 61 | + let pieces = try await ChatCompletionRoute.generate(plan, with: lease) | |
| 62 | + let chunks = ChatCompletionRoute.chunks( | |
| 63 | + pieces, lease: lease, plan: plan, logger: .init(label: "test")) | |
| 64 | + var deltas: [(reasoning: Bool, text: String)] = [] | |
| 65 | + for try await chunk in chunks { | |
| 66 | + guard let delta = chunk.choices.first?.delta else { continue } | |
| 67 | + if let text = delta.reasoningContent { deltas.append((true, text)) } | |
| 68 | + if let text = delta.content, !text.isEmpty { deltas.append((false, text)) } | |
| 69 | + } | |
| 70 | + return deltas | |
| 71 | + } | |
| 72 | + | |
| 73 | + @Test func reasoningStreamsBeforeTheAnswer() async throws { | |
| 74 | + var thinking = plan("What is the capital of France?", maxTokens: 600) | |
| 75 | + thinking.client.thinking = true | |
| 76 | + let deltas = try await streamedDeltas(thinking) | |
| 77 | + let reasoning = deltas.filter(\.reasoning) | |
| 78 | + #expect(reasoning.count > 5) // token by token | |
| 79 | + #expect(deltas.first?.reasoning == true) | |
| 80 | + let firstAnswer = try #require(deltas.firstIndex { !$0.reasoning }) | |
| 81 | + #expect(deltas[firstAnswer...].allSatisfy { !$0.reasoning }) | |
| 82 | + #expect(deltas.filter { !$0.reasoning }.map(\.text).joined().contains("Paris")) | |
| 83 | + | |
| 84 | + thinking.client.showReasoning = false | |
| 85 | + let hidden = try await streamedDeltas(thinking) | |
| 86 | + #expect(hidden.allSatisfy { !$0.reasoning }) | |
| 87 | + #expect(hidden.map(\.text).joined().contains("Paris")) | |
| 88 | + } | |
| 89 | + | |
| 58 | 90 | @Test func thinkingBudgetShortensTheReasoning() async throws { |
| 59 | 91 | var thinking = plan("Is 391 a prime number?", maxTokens: 600) |
| 60 | 92 | thinking.client.thinking = true |
| @@ -55,6 +55,38 @@ struct ChatSmokeTests { | |||
| 55 | #expect(response.usage.reasoningTokens > 0) | 55 | #expect(response.usage.reasoningTokens > 0) |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | + /// Streams `plan` and returns the reasoning and content deltas, in order. | ||
| 59 | + func streamedDeltas(_ plan: ChatPlan) async throws -> [(reasoning: Bool, text: String)] { | ||
| 60 | + let lease = try await models.acquire(smokeModel) | ||
| 61 | + let pieces = try await ChatCompletionRoute.generate(plan, with: lease) | ||
| 62 | + let chunks = ChatCompletionRoute.chunks( | ||
| 63 | + pieces, lease: lease, plan: plan, logger: .init(label: "test")) | ||
| 64 | + var deltas: [(reasoning: Bool, text: String)] = [] | ||
| 65 | + for try await chunk in chunks { | ||
| 66 | + guard let delta = chunk.choices.first?.delta else { continue } | ||
| 67 | + if let text = delta.reasoningContent { deltas.append((true, text)) } | ||
| 68 | + if let text = delta.content, !text.isEmpty { deltas.append((false, text)) } | ||
| 69 | + } | ||
| 70 | + return deltas | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @Test func reasoningStreamsBeforeTheAnswer() async throws { | ||
| 74 | + var thinking = plan("What is the capital of France?", maxTokens: 600) | ||
| 75 | + thinking.client.thinking = true | ||
| 76 | + let deltas = try await streamedDeltas(thinking) | ||
| 77 | + let reasoning = deltas.filter(\.reasoning) | ||
| 78 | + #expect(reasoning.count > 5) // token by token | ||
| 79 | + #expect(deltas.first?.reasoning == true) | ||
| 80 | + let firstAnswer = try #require(deltas.firstIndex { !$0.reasoning }) | ||
| 81 | + #expect(deltas[firstAnswer...].allSatisfy { !$0.reasoning }) | ||
| 82 | + #expect(deltas.filter { !$0.reasoning }.map(\.text).joined().contains("Paris")) | ||
| 83 | + | ||
| 84 | + thinking.client.showReasoning = false | ||
| 85 | + let hidden = try await streamedDeltas(thinking) | ||
| 86 | + #expect(hidden.allSatisfy { !$0.reasoning }) | ||
| 87 | + #expect(hidden.map(\.text).joined().contains("Paris")) | ||
| 88 | + } | ||
| 89 | + | ||
| 58 | @Test func thinkingBudgetShortensTheReasoning() async throws { | 90 | @Test func thinkingBudgetShortensTheReasoning() async throws { |
| 59 | var thinking = plan("Is 391 a prime number?", maxTokens: 600) | 91 | var thinking = plan("Is 391 a prime number?", maxTokens: 600) |
| 60 | thinking.client.thinking = true | 92 | thinking.client.thinking = true |
modified
Tests/RazorbillServerTests/ReasoningTests.swift +42 -0 | @@ -63,6 +63,48 @@ struct BadBudget: RequestSettingError { | ||
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | + @Test func includeReasoningFalseHidesItButUsageCountsIt() async throws { | |
| 67 | + let script: [EngineEvent] = [.thinking("Secret plan."), .text("42"), .stats(stats)] | |
| 68 | + let engines = TestEngines(script: [script, script]) | |
| 69 | + let hidden = #","include_reasoning":false"# | |
| 70 | + try await withLiveServer(engines: engines) { client in | |
| 71 | + let body = try json(try await post(client, simpleRequest(extra: hidden))) | |
| 72 | + #expect(message(body)?["reasoning_content"] == nil) | |
| 73 | + #expect(message(body)?["content"] as? String == "42") | |
| 74 | + let usage = try #require(body["usage"] as? [String: Any]) | |
| 75 | + #expect( | |
| 76 | + (usage["completion_tokens_details"] as? [String: Int]) == ["reasoning_tokens": 1]) | |
| 77 | + } | |
| 78 | + try await withLiveServer(engines: engines) { client in | |
| 79 | + let response = try await post(client, simpleRequest(extra: hidden + #","stream":true"#)) | |
| 80 | + #expect(!String(buffer: response.body).contains("Secret")) | |
| 81 | + #expect( | |
| 82 | + try chunks(response).compactMap { delta($0)?["content"] as? String } == ["", "42"]) | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Test func configurationDecidesAndLocksWhetherReasoningIsShown() async throws { | |
| 87 | + let script: [EngineEvent] = [.thinking("Plan."), .text("Ok")] | |
| 88 | + let engines = TestEngines(script: [script, script, script]) | |
| 89 | + var settings = testSettings | |
| 90 | + settings.config.defaults = GenerationOverrides(showReasoning: false) | |
| 91 | + try await withLiveServer(settings, engines: engines) { client in | |
| 92 | + let quiet = try json(try await post(client, simpleRequest())) | |
| 93 | + #expect(message(quiet)?["reasoning_content"] == nil) | |
| 94 | + } | |
| 95 | + try await withLiveServer(settings, engines: engines) { client in | |
| 96 | + let asked = try json( | |
| 97 | + try await post(client, simpleRequest(extra: #","include_reasoning":true"#))) | |
| 98 | + #expect(message(asked)?["reasoning_content"] as? String == "Plan.") | |
| 99 | + } | |
| 100 | + settings.config.locked = GenerationOverrides(showReasoning: false) | |
| 101 | + try await withLiveServer(settings, engines: engines) { client in | |
| 102 | + let refused = try json( | |
| 103 | + try await post(client, simpleRequest(extra: #","include_reasoning":true"#))) | |
| 104 | + #expect(message(refused)?["reasoning_content"] == nil) | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 66 | 108 | static let switches: [(extra: String, thinking: Bool)] = [ |
| 67 | 109 | (#","reasoning_effort":"high""#, true), |
| 68 | 110 | (#","reasoning_effort":"low""#, true), |
| @@ -63,6 +63,48 @@ struct BadBudget: RequestSettingError { | |||
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | + @Test func includeReasoningFalseHidesItButUsageCountsIt() async throws { | ||
| 67 | + let script: [EngineEvent] = [.thinking("Secret plan."), .text("42"), .stats(stats)] | ||
| 68 | + let engines = TestEngines(script: [script, script]) | ||
| 69 | + let hidden = #","include_reasoning":false"# | ||
| 70 | + try await withLiveServer(engines: engines) { client in | ||
| 71 | + let body = try json(try await post(client, simpleRequest(extra: hidden))) | ||
| 72 | + #expect(message(body)?["reasoning_content"] == nil) | ||
| 73 | + #expect(message(body)?["content"] as? String == "42") | ||
| 74 | + let usage = try #require(body["usage"] as? [String: Any]) | ||
| 75 | + #expect( | ||
| 76 | + (usage["completion_tokens_details"] as? [String: Int]) == ["reasoning_tokens": 1]) | ||
| 77 | + } | ||
| 78 | + try await withLiveServer(engines: engines) { client in | ||
| 79 | + let response = try await post(client, simpleRequest(extra: hidden + #","stream":true"#)) | ||
| 80 | + #expect(!String(buffer: response.body).contains("Secret")) | ||
| 81 | + #expect( | ||
| 82 | + try chunks(response).compactMap { delta($0)?["content"] as? String } == ["", "42"]) | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + @Test func configurationDecidesAndLocksWhetherReasoningIsShown() async throws { | ||
| 87 | + let script: [EngineEvent] = [.thinking("Plan."), .text("Ok")] | ||
| 88 | + let engines = TestEngines(script: [script, script, script]) | ||
| 89 | + var settings = testSettings | ||
| 90 | + settings.config.defaults = GenerationOverrides(showReasoning: false) | ||
| 91 | + try await withLiveServer(settings, engines: engines) { client in | ||
| 92 | + let quiet = try json(try await post(client, simpleRequest())) | ||
| 93 | + #expect(message(quiet)?["reasoning_content"] == nil) | ||
| 94 | + } | ||
| 95 | + try await withLiveServer(settings, engines: engines) { client in | ||
| 96 | + let asked = try json( | ||
| 97 | + try await post(client, simpleRequest(extra: #","include_reasoning":true"#))) | ||
| 98 | + #expect(message(asked)?["reasoning_content"] as? String == "Plan.") | ||
| 99 | + } | ||
| 100 | + settings.config.locked = GenerationOverrides(showReasoning: false) | ||
| 101 | + try await withLiveServer(settings, engines: engines) { client in | ||
| 102 | + let refused = try json( | ||
| 103 | + try await post(client, simpleRequest(extra: #","include_reasoning":true"#))) | ||
| 104 | + #expect(message(refused)?["reasoning_content"] == nil) | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + | ||
| 66 | static let switches: [(extra: String, thinking: Bool)] = [ | 108 | static let switches: [(extra: String, thinking: Bool)] = [ |
| 67 | (#","reasoning_effort":"high""#, true), | 109 | (#","reasoning_effort":"high""#, true), |
| 68 | (#","reasoning_effort":"low""#, true), | 110 | (#","reasoning_effort":"low""#, true), |
modified
examples/server.yaml +3 -1 | @@ -14,9 +14,11 @@ defaults: | ||
| 14 | 14 | max_tokens: 2048 |
| 15 | 15 | |
| 16 | 16 | # Settings clients cannot change. Nothing is locked unless listed here (or under a model). |
| 17 | -# temperature, top_p and thinking are imposed; max_tokens and thinking_budget are ceilings. | |
| 17 | +# temperature, top_p, thinking and show_reasoning are imposed; max_tokens and thinking_budget are | |
| 18 | +# ceilings. Keys: temperature, top_p, max_tokens, thinking, thinking_budget, show_reasoning. | |
| 18 | 19 | locked: |
| 19 | 20 | max_tokens: 8192 |
| 21 | + # show_reasoning: false # never send the models' reasoning (they still think) | |
| 20 | 22 | |
| 21 | 23 | # Models declared by name. Any other Hugging Face id in MLX format (org/name) is accepted too. |
| 22 | 24 | models: |
| @@ -14,9 +14,11 @@ defaults: | |||
| 14 | max_tokens: 2048 | 14 | max_tokens: 2048 |
| 15 | 15 | ||
| 16 | # Settings clients cannot change. Nothing is locked unless listed here (or under a model). | 16 | # Settings clients cannot change. Nothing is locked unless listed here (or under a model). |
| 17 | -# temperature, top_p and thinking are imposed; max_tokens and thinking_budget are ceilings. | 17 | +# temperature, top_p, thinking and show_reasoning are imposed; max_tokens and thinking_budget are |
| 18 | +# ceilings. Keys: temperature, top_p, max_tokens, thinking, thinking_budget, show_reasoning. | ||
| 18 | locked: | 19 | locked: |
| 19 | max_tokens: 8192 | 20 | max_tokens: 8192 |
| 21 | + # show_reasoning: false # never send the models' reasoning (they still think) | ||
| 20 | 22 | ||
| 21 | # Models declared by name. Any other Hugging Face id in MLX format (org/name) is accepted too. | 23 | # Models declared by name. Any other Hugging Face id in MLX format (org/name) is accepted too. |
| 22 | models: | 24 | models: |