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++
serve: the thinking budget can be shared with other apps through POST /settings (#1035)
elanonimo8322de5fa0a84cd
diff --git a/serve/server.py b/serve/server.pyindex 24bf309c5..f969d99ec 100644--- a/serve/server.py+++ b/serve/server.py@@ -2878,11 +2878,12 @@ class Service:def run(self, ids, thinking, tools, max_new, sampling, cancel, force=None) -> Iterator[tuple[str, object]]:"""Yields ("event", Event) as text arrives, then ("done", {"finish": .., "completion_tokens": ..}).`force` (forced_call): the opening of the call the reply must make - see prepare()."""- budget = self.reasoning_budget(sampling) if thinking else None # #123: opt-in, off by defaultdefaults = {**self.sampling_defaults, **self.shared} # the config's, then the Chat settings shared with appsif defaults: # the request's own fields win (explicit 0 stays greedy)req_values = {k: v for k, v in (sampling or {}).items() if v is not None}sampling = {**defaults, **req_values}+ # #123: read after the merge, so a budget shared through POST /settings is seen like the other keys+ budget = self.reasoning_budget(sampling) if thinking else Noneparser = OutputParser(thinking=thinking, tools=tools, stream_tools=True)detok, n, finish = Detokenizer(self.tok), 0, "length"run_tok, run_len, repeated = None, 0, False # #606: the current run of one repeated token@@ -4771,7 +4772,8 @@ def origins_of(value, key: str, wildcard: bool) -> list[str]:return out-SHARED_KEYS = ("reasoning_effort", "temperature", "top_p", "top_k", "seed", "max_tokens", "experimental_speed_projection")+SHARED_KEYS = ("reasoning_effort", "reasoning_budget_tokens", "temperature", "top_p", "top_k", "seed", "max_tokens",+ "experimental_speed_projection")def clean_shared_defaults(d) -> dict:@@ -4802,6 +4804,10 @@ def clean_shared_defaults(d) -> dict:if not number or value != int(value) or value <= 0:raise ValueError(f"{key}: a positive integer")value = int(value)+ elif key == "reasoning_budget_tokens": # #123: 0 means no budget, so 0 is allowed here+ if not number or value != int(value) or value < 0:+ raise ValueError("reasoning_budget_tokens: a whole number of tokens (0: no budget)")+ value = int(value)elif key == "experimental_speed_projection":if not isinstance(value, bool):raise ValueError("experimental_speed_projection: true or false")diff --git a/serve/test_server.py b/serve/test_server.pyindex c6fd3d3e9..c53280bbd 100644--- a/serve/test_server.py+++ b/serve/test_server.py@@ -2803,6 +2803,23 @@ class ThinkingBudget(unittest.TestCase):self.assertEqual(b["choices"][0]["message"]["reasoning_content"], ThinkingEngine.THOUGHT)self.assertEqual(len(self.engine.prompts), 3)+ def test_a_shared_budget_reaches_a_request_that_sets_none(self):+ """The Chat settings shared with other apps may carry a thinking budget too, like max_tokens and the effort."""+ self.svc.set_shared({"reasoning_budget_tokens": 20})+ code, b = self.openai() # a client that asks for no budget of its own+ self.assertEqual(code, 200, b)+ self.assertEqual(len(self.engine.prompts), 2)+ self.assertTrue(b["choices"][0]["message"]["reasoning_content"].startswith(ThinkingEngine.THOUGHT[:20] + "\n"))+ code, b = self.openai(reasoning_budget_tokens=0) # its own 0 still turns it off+ self.assertEqual(b["choices"][0]["message"]["reasoning_content"], ThinkingEngine.THOUGHT)+ self.assertEqual(len(self.engine.prompts), 3)++ def test_a_shared_budget_must_be_a_whole_number_of_tokens(self):+ for bad in (-1, 1.5, "20"):+ with self.assertRaises(ValueError, msg=repr(bad)):+ self.svc.set_shared({"reasoning_budget_tokens": bad})+ self.assertEqual(self.svc.set_shared({"reasoning_budget_tokens": 0}), {"reasoning_budget_tokens": 0})+def test_without_thinking_there_is_nothing_to_limit(self):self.engine.THOUGHT = ""code, b = self.openai(reasoning_budget_tokens=5, reasoning_effort="none")