Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
#278 follow-up: an Anthropic request that doesn't ask for thinking renders without it only with "anthropic_thinking": "on_request" in the config - the default thinks as 0.1.31 did (a client that never asks would otherwise lose the thinking on every turn); docs
Niko12213b7162131db5
diff --git a/docs/DETAILS.md b/docs/DETAILS.mdindex c58be4d3b..e82de2f84 100644--- a/docs/DETAILS.md+++ b/docs/DETAILS.md@@ -424,6 +424,10 @@ print(r.choices[0].message.content)part of the thinking the client sees and counts as output tokens. `"reasoning_budget_tokens": N` in`strata-<model>.json` sets it for every request; a request's own value wins, and `0` means no budget. Off by default;Anthropic's `"thinking": {"budget_tokens": N}` still only chooses the level, as above.+- **Anthropic requests that don't ask for thinking (opt-in, 0.1.32, #278).** By default a `/v1/messages` request+ with no `"thinking"`, effort or budget thinks as the model's template does. `"anthropic_thinking": "on_request"` in+ `strata-<model>.json` renders such a request without thinking - Anthropic's own rule, and what Claude Code's short+ helper calls (a session title in a few dozen tokens) need; its real turns ask for thinking when it is on there.- **Streaming.** With `"stream": true` everything arrives as it is made: the thinking, the answer, and tool calls(the tool's name first, then its arguments piece by piece, like OpenAI and Anthropic do). While the model reads along prompt the stream sends keep-alives, so agents do not time out; the server window prints progress everydiff --git a/serve/frontend.py b/serve/frontend.pyindex 84310811e..e832be996 100644--- a/serve/frontend.py+++ b/serve/frontend.py@@ -173,8 +173,10 @@ def openai_to_messages(req: dict) -> tuple[list[dict], list[dict] | None, dict]:return _late_system_to_user(messages), tools, kwargs-def anthropic_to_messages(req: dict) -> tuple[list[dict], list[dict] | None, dict]:- """Anthropic Messages -> (template messages, template tools, template kwargs)."""+def anthropic_to_messages(req: dict, think_unasked: bool = True) -> tuple[list[dict], list[dict] | None, dict]:+ """Anthropic Messages -> (template messages, template tools, template kwargs). `think_unasked`: a request+ without "thinking", an effort or a budget gets the template's default (it thinks), as through 0.1.31; False+ renders it without thinking (#278, the config's "anthropic_thinking": "on_request")."""messages = []system = req.get("system")if system:@@ -219,8 +221,10 @@ def anthropic_to_messages(req: dict) -> tuple[list[dict], list[dict] | None, dickwargs.update(effort_kwargs(effort))elif isinstance(thinking, dict) and thinking.get("budget_tokens"):kwargs.update(budget_effort(thinking["budget_tokens"]))- elif thinking is None and not req.get("reasoning_budget_tokens"):- # Anthropic's thinking is opt-in. Claude Code's helper calls (a session title, a topic check) ask for none+ elif thinking is None and not req.get("reasoning_budget_tokens") and not think_unasked:+ # Opt-in (the config's "anthropic_thinking": "on_request"; the default thinks as 0.1.31 did, since a+ # client that never asks would otherwise lose the thinking on every turn). Anthropic's thinking is+ # opt-in there. Claude Code's helper calls (a session title, a topic check) ask for none# and allow a few dozen tokens, which the model otherwise spent thinking and answered with no text at all.# A config's reasoning_effort still applies: Service.with_shared sets output_config before this runs. A# request that gives its own reasoning_budget_tokens (#123) asks for thinking, so it thinks as before.diff --git a/serve/server.py b/serve/server.pyindex 5b5af5b03..5bba3c0ef 100644--- a/serve/server.py+++ b/serve/server.py@@ -730,6 +730,7 @@ class Service:self.min_free_vram_mib = 0self.before_load = Noneself.reasoning_budget_tokens = 0 # #123: the config's default thinking budget (0: none)+ self.anthropic_think_unasked = True # #278: "anthropic_thinking": "on_request" -> Falseself.stop_ids = set(tokenizer.encode(IM_END, parse_special=True) +tokenizer.encode("<|endoftext|>", parse_special=True))@@ -2063,14 +2064,14 @@ def make_handler(svc: Service):"""Anthropic's token count, which Claude Code asks for its context figures: the prompt this server wouldread for the same request, rendered and tokenized - the model does not run."""req = svc.with_shared(req, "anthropic")- messages, tools, kw = anthropic_to_messages(req)+ messages, tools, kw = anthropic_to_messages(req, svc.anthropic_think_unasked)prompt = svc.template.render(messages, tools=tools, **kw)self._json(200, {"input_tokens": len(svc.tok.encode(prompt, parse_special=True))})def _anthropic(self, req):svc.load()req = svc.with_shared(req, "anthropic")- messages, tools, kw = anthropic_to_messages(req)+ messages, tools, kw = anthropic_to_messages(req, svc.anthropic_think_unasked)max_new = int(req.get("max_tokens") or 0) # 0/-1: the rest of the contextsvc.reasoning_budget(req) # a bad value is a 400 before anything is sentids, thinking, max_new = svc.prepare(messages, tools, kw, max_new)@@ -2405,6 +2406,10 @@ def main() -> int:svc.min_free_vram_mib = a.min_free_vram_mib if a.min_free_vram_mib is not None else \int(cfg.get("min_free_vram_mib") or 0)svc.before_load = a.before_load or cfg.get("before_load") or None+ mode = str(cfg.get("anthropic_thinking") or "model") # #278: "on_request" = only when the request asks+ if mode not in ("model", "on_request"):+ raise SystemExit(f"[strata] config anthropic_thinking must be \"model\" or \"on_request\", not {mode!r}")+ svc.anthropic_think_unasked = mode == "model"if cfg.get("reasoning_budget_tokens") is not None: # #123: a default thinking budget for every requesttry:svc.reasoning_budget_tokens = cfg["reasoning_budget_tokens"]diff --git a/serve/test_server.py b/serve/test_server.pyindex 2f364631a..a05b524f8 100644--- a/serve/test_server.py+++ b/serve/test_server.py@@ -69,7 +69,9 @@ class MaxTokens(unittest.TestCase):# #278: Anthropic's thinking is opt-in; "thinking", an effort or a reasoning_budget_tokens (#123) asks for itfrom serve.frontend import anthropic_to_messagesmsgs = [{"role": "user", "content": "u"}]- kw = lambda **r: anthropic_to_messages({"messages": msgs, **r})[2] # noqa: E731+ kw = lambda **r: anthropic_to_messages({"messages": msgs, **r}, think_unasked=False)[2] # noqa: E731+ # the default ("anthropic_thinking": "model") renders an unasked request as 0.1.31 did+ self.assertNotIn("enable_thinking", anthropic_to_messages({"messages": msgs})[2])self.assertEqual(kw(), {"enable_thinking": False})self.assertEqual(kw(thinking={"type": "disabled"}), {"enable_thinking": False})self.assertNotIn("enable_thinking", kw(thinking={"type": "enabled", "budget_tokens": 2048}))