Skip to main content

split_think

Function split_think 

Source
pub fn split_think(text: &str) -> (String, String)
Expand description

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.