Expand description
Chat text logic re-exports shared by infr run and infr serve (prompt rendering,
channel/tool-call parsing, the reasoning/content delta splitter). The load-pipeline/session
orchestration this crate originally stubbed out (the Engine struct) is now the unified
transformer runner in infr-llama (SeamModel + the per-backend ChatModel impls, see
docs/diffusion-gemma.md and docs/qwen35.md) — every arch, including DiffusionGemma, is built
on it, so there is no separate “engine” seam left to implement here.
Reference for chat/channel/tool behavior: ~/Projects/scratch/dgemma-openai-server.py.
Structs§
- Chat
Message - One chat message (OpenAI-shaped; tool fields preserved for the agentic round-trip).
- Chat
Stream - A streamed piece of a response (re-exported from the single splitter in
infr-chat). Incremental splitter for the streaming server path. Accumulates the raw decoded text and, on each piece, emits the newly-stable Reasoning (<think>…</think>) and Content deltas — holding back a marker-length tail so a partial<think>/</think>/<tool_call>marker is never emitted. Once a tool-call opener appears (and tool calls are allowed) it stops streaming content — matching every dialectfinish()parses (Hermes<tool_call>, the pipe form<|tool_call>, and a Llama-3 bare-JSON{…}body), so non-Hermes calls can’t leak as content while also firing as a ToolCall.finish()flushes the held-back tails and parses the buffered tool call(s) into ToolCall deltas. - Tool
Call - One parsed tool invocation from the model’s
<|tool_call>…<tool_call|>block.
Enums§
- Delta
- A streamed piece of a response (re-exported from the single splitter in
infr-chat). A streamed piece of a response.
Functions§
- parse_
hermes_ tool_ calls - Parse the Hermes / Qwen tool-call format —
<tool_call>{"name":..,"arguments":{..}}</tool_call>(the format Qwen3 and most OSS function-calling models emit, and what the GGUF chat templates render). Returns(clean, calls):cleanis the text with all tool-call blocks removed;callsthe parsed invocations. The body is real JSON, so it’s parsed with serde (no hand-rolled scanner);argumentsis accepted as either an object or a JSON string and normalised to aValue. - parse_
tool_ calls - Find all
<|tool_call>…<tool_call|>blocks, parse them, and return: - prompt_
prefills_ think - A streamed piece of a response (re-exported from the single splitter in
infr-chat). Does this rendered prompt end with a<think>PREFILL (the template opened the reasoning block itself — Qwen3.5 style — so the model’s output starts MID-reasoning with only the close marker)? Callers inject a synthetic"<think>"piece at the head of the stream when this is true, so the streaming splitter, the display styler and the history stripper all see a well-formed block through the one shared grammar. - split_
channels - Split cumulative model output into
(reasoning, content). - split_
reasoning - Format-aware reasoning split: channel-marker output (E2B/gpt-oss
<|channel>thought…<channel|>) goes throughsplit_channels, everything else throughsplit_think. THE one entry point for “what part of this reply was reasoning” — history stripping and batch consumers use this. - split_
think - Split output into
(reasoning, content)on the<think>…</think>markers Qwen3/DeepSeek-R1 emit — stripping EVERY reasoning span, not just the first (a constrained/looped turn can emit several). Handles the prefilled-<think>case where the open marker was added by the template (output then starts mid-reasoning and only the close marker appears) and an unterminated open (truncated turn — the tail is reasoning). No marker ⇒ all content, empty reasoning. This is THE reasoning grammar:infr run’s display,infr serve’s deltas and the chat history stripper all resolve reasoning-vs-content through this module.