ReasoningParser

Trait ReasoningParser 

Source
pub trait ReasoningParser: Send + Sync {
    // Required methods
    fn detect_and_parse_reasoning(
        &mut self,
        text: &str,
    ) -> Result<ParserResult, ParseError>;
    fn parse_reasoning_streaming_incremental(
        &mut self,
        text: &str,
    ) -> Result<ParserResult, ParseError>;
    fn reset(&mut self);
    fn model_type(&self) -> &str;
    fn is_in_reasoning(&self) -> bool;
}
Expand description

Trait for parsing reasoning content from LLM outputs.

Required Methods§

Source

fn detect_and_parse_reasoning( &mut self, text: &str, ) -> Result<ParserResult, ParseError>

Detects and parses reasoning from the input text (one-time parsing).

This method is used for non-streaming scenarios where the complete text is available at once.

Returns an error if the text exceeds buffer limits or contains invalid UTF-8.

Source

fn parse_reasoning_streaming_incremental( &mut self, text: &str, ) -> Result<ParserResult, ParseError>

Parses reasoning incrementally from streaming input.

This method maintains internal state across calls to handle partial tokens and chunk boundaries correctly.

Returns an error if the buffer exceeds max_buffer_size.

Source

fn reset(&mut self)

Reset the parser state for reuse.

This should clear any buffers and reset flags to initial state.

Source

fn model_type(&self) -> &str

Get the model type this parser is designed for.

Source

fn is_in_reasoning(&self) -> bool

Check if the parser is currently in reasoning mode.

Returns true if the parser is currently parsing reasoning content.

Implementors§