Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
feat(inkling): continue an open assistant turn
eni87c4156dae02
diff --git a/c/openai_server.py b/c/openai_server.pyindex cf331328..41b41bf5 100644--- a/c/openai_server.py+++ b/c/openai_server.py@@ -1611,12 +1611,16 @@ def render_chat_qwen38(messages, enable_thinking=True, reasoning_effort=None, todef render_chat_inkling(messages, enable_thinking=False, reasoning_effort=None, tools=None,- tool_choice=None, audio_out=None):+ tool_choice=None, audio_out=None, add_generation_prompt=True):"""Text-only subset of Inkling's chat_template.jinja: role tokens with<|content_text|> parts and <|end_message|> terminators, an assistant<|content_model_end_sampling|> after each prior model turn, thethinking-effort hint appended after the messages (the template's fallback- branch), then <|message_model|> as the generation prompt."""+ branch), then <|message_model|> as the generation prompt.++ add_generation_prompt=False continues a trailing assistant turn: the last model turn is+ rendered open -- without its <|end_message|> and the <|content_model_end_sampling|> that+ close it, and with no cue. Those two markers are the terminator to drop here."""if not isinstance(messages, list) or not messages:raise APIError(400, "`messages` must be a non-empty array.", "messages")if tools or (tool_choice not in (None, "none")):@@ -1652,6 +1656,8 @@ def render_chat_inkling(messages, enable_thinking=False, reasoning_effort=None,if not effort_emitted and role not in ("system", "developer"):prompt.append(effort_str)effort_emitted = True+ open_turn = (not add_generation_prompt and role == "assistant"+ and index == len(messages) - 1)raw = message.get("content")if audio_out is not None and role == "user" and isinstance(raw, list):# multipart user content: text runs and audio clips become separate@@ -1666,20 +1672,23 @@ def render_chat_inkling(messages, enable_thinking=False, reasoning_effort=None,+ "<|audio|>" * val + "<|audio_end|><|end_message|>")else:text = content_text(raw, f"messages.{index}.content") if raw is not None else ""- prompt.append(f"{rtok}<|content_text|>{text}<|end_message|>")- if role == "assistant":+ # A continued turn is the last model message rendered open: no <|end_message|>.+ terminator = "" if open_turn else "<|end_message|>"+ prompt.append(f"{rtok}<|content_text|>{text}{terminator}")+ if role == "assistant" and not open_turn:prompt.append("<|content_model_end_sampling|>")if not effort_emitted: # all-system edge case: fallbackprompt.append(effort_str)- prompt.append("<|message_model|>") # add_generation_prompt- # Thinking off: prefill the content channel. Without this the model can still- # sample <|content_thinking|> as its first token (the effort hint is only a- # soft signal), open a reasoning block, and burn the whole token budget before- # reaching <|content_text|> — which the splitter then strips to an empty- # answer. Ending the prompt at <|message_model|><|content_text|> forces content- # mode; it is exactly the sequence every non-thinking turn is trained on.- if eff == 0.0:- prompt.append("<|content_text|>")+ if add_generation_prompt:+ prompt.append("<|message_model|>") # generation cue+ # Thinking off: prefill the content channel. Without this the model can still+ # sample <|content_thinking|> as its first token (the effort hint is only a+ # soft signal), open a reasoning block, and burn the whole token budget before+ # reaching <|content_text|> — which the splitter then strips to an empty+ # answer. Ending the prompt at <|message_model|><|content_text|> forces content+ # mode; it is exactly the sequence every non-thinking turn is trained on.+ if eff == 0.0:+ prompt.append("<|content_text|>")return "".join(prompt)@@ -2388,7 +2397,7 @@ def render_chat_dsv41(messages, enable_thinking=False, reasoning_effort=None, to# (the cue is appended, exactly as before this existed) rather than erroring -- continuation is# on by default, and a family without its open-turn shape yet must not start rejecting requests# nobody opted into. Each renderer adds itself here in the same commit that derives its shape.-CONTINUATION_FAMILIES = {"glm53", "qwen38", "qwen36", "glm", "olmoe", "deepseek_v4"}+CONTINUATION_FAMILIES = {"glm53", "qwen38", "qwen36", "glm", "olmoe", "deepseek_v4", "inkling"}def resolve_generation_prompt(messages, body):@@ -2472,7 +2481,8 @@ def render_chat_for_arch(messages, enable_thinking=False, reasoning_effort=None,"messages", "unsupported_parameter")if ARCH == "inkling":return render_chat_inkling(messages, enable_thinking, reasoning_effort, tools,- tool_choice, audio_out=audio_out)+ tool_choice, audio_out=audio_out,+ add_generation_prompt=add_generation_prompt)if ARCH == "glm53":return render_chat_glm53(messages, enable_thinking, reasoning_effort, tools,tool_choice, add_generation_prompt)diff --git a/c/tests/test_openai_server.py b/c/tests/test_openai_server.pyindex 874c8d72..c16db2b8 100644--- a/c/tests/test_openai_server.py+++ b/c/tests/test_openai_server.py@@ -22,7 +22,7 @@ from openai_server import (APIError, APIHandler, APIServer, ClientCancelled,generation_options, parse_tool_calls, parse_dsv4_tool_calls,parse_arch_tool_calls, parse_k3_tool_calls, parse_qwen38_tool_calls,read_engine_turn, render_chat, render_chat_for_arch,- render_chat_glm53, render_chat_kimi,+ render_chat_glm53, render_chat_inkling, render_chat_kimi,render_chat_olmoe,render_chat_qwen38, render_chat_v4, _dsv4_tool_calls, serve,resolve_generation_prompt, split_thinking_reply,@@ -2149,7 +2149,7 @@ class TrailingAssistantTurnTest(unittest.TestCase):yet must render as before -- append the cue -- not reject a request nobody opted into.Each family leaves this list in the commit that derives its shape; Kimi K3 (framedengine-side, so its open turn is a change in kimi_k3.c) is the standing case."""- for arch in ("kimi", "inkling"):+ for arch in ("kimi",):with self.on(), patch("openai_server.ARCH", arch):self.assertTrue(resolve_generation_prompt(self.OPEN_TURN, {}))@@ -2182,6 +2182,33 @@ class TrailingAssistantTurnTest(unittest.TestCase):self.assertTrue(cont.endswith("La capitale e'"), cont[-40:])self.assertFalse(cont.endswith(EOS))+ def test_continuation_open_turn_inkling(self):+ """inkling uses its own markers, and render_chat_inkling deliberately deviates from+ the template's generation cue (it prefills <|content_text|> in the thinking-off case+ to force content mode, and defaults thinking off), so it is pinned with an+ expected-string test: the open turn is pinned to a literal here, with the+ past-turn-minus-terminators invariant kept as an added check, in both thinking modes."""+ END = "<|end_message|><|content_model_end_sampling|>"+ for enable_thinking in (True, False):+ # eff is 0.9 with thinking on, 0.0 off; the off cue prefills the content channel+ eff = "0.9" if enable_thinking else "0"+ cue = "<|message_model|>" + ("" if enable_thinking else "<|content_text|>")+ # The literal open turn, written out so the test does not lean on another renderer+ # call for its only expected value (see the deepseek_v4 test). The two modes differ+ # only in the system effort line; both end on the prefilled content channel.+ expected = ("<|message_system|><|content_text|>Thinking effort level: " + eff ++ "<|end_message|><|message_user|><|content_text|>capitale della Francia?"+ "<|end_message|><|message_model|><|content_text|>La capitale e'")+ with patch("openai_server.ARCH", "inkling"):+ normal = render_chat_inkling(self.OPEN_TURN, enable_thinking=enable_thinking)+ cont = render_chat_for_arch(self.OPEN_TURN, enable_thinking=enable_thinking,+ add_generation_prompt=False)+ self.assertEqual(cont, expected)+ # and the invariant tying it to the normal render: past turn without terminators + cue+ self.assertEqual(normal, cont + END + cue)+ self.assertTrue(cont.endswith("La capitale e'"), cont[-40:])+ self.assertFalse(cont.endswith("<|end_message|>"))+def test_splitter_starts_in_content_mode_on_a_continued_turn(self):"""Measured on glm53 int4, CPU: content '' with reasoning_chars 10 and 109,clean stop, and a byte-correct open turn on the wire. The model was fine; the