ReasoningParser

Trait ReasoningParser 

Source
pub trait ReasoningParser: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn start_tag(&self) -> &str;
    fn end_tag(&self) -> &str;
    fn extract_thinking(
        &self,
        text: &str,
        enable_thinking: bool,
    ) -> (Option<String>, String);

    // Provided method
    fn end_token_id(&self, tokenizer: &ChatTokenizer) -> Option<u32> { ... }
}
Expand description

Parses reasoning/thinking blocks from completed model output.

Required Methods§

Source

fn name(&self) -> &str

Parser name for logging (e.g. "qwen", "deepseek_r1").

Source

fn start_tag(&self) -> &str

Opening delimiter (e.g. "<think>", "[THINK]", "<|channel>").

Source

fn end_tag(&self) -> &str

Closing delimiter (e.g. "</think>", "[/THINK]", "<channel|>").

Source

fn extract_thinking( &self, text: &str, enable_thinking: bool, ) -> (Option<String>, String)

Split completed generation text into (reasoning, content).

enable_thinking is the resolved per-request thinking state. When false the reasoning is discarded (None); the answer is always returned in content.

Provided Methods§

Source

fn end_token_id(&self, tokenizer: &ChatTokenizer) -> Option<u32>

Resolve the end-of-thinking token ID from the tokenizer. Returns None if the end tag doesn’t encode to a single token.

Implementors§