pymllm.parsers.reasoning_parser

Reasoning / thinking content parser.

Separates <think>...</think> (or model-specific markers) from normal assistant content. Supports both one-shot and incremental streaming modes.

Usage:

# Non-streaming
parser = ReasoningParser("qwen3")
reasoning, content = parser.parse_non_stream(full_text)

# Streaming
parser = ReasoningParser("qwen3")
for delta in deltas:
    reasoning_delta, content_delta = parser.parse_stream_chunk(delta)

Classes

ReasoningParser

Model-agnostic reasoning content parser.

Module Contents

class pymllm.parsers.reasoning_parser.ReasoningParser(model_type, stream_reasoning=True)

Model-agnostic reasoning content parser.

Parameters:
  • model_type (str) – Key into the detector registry (e.g. "qwen3", "deepseek-r1").

  • stream_reasoning (bool) – If True, stream reasoning content incrementally as it arrives. If False, buffer reasoning until the end tag is found.

SUPPORTED
parse_non_stream(text)

Parse complete text.

Returns (reasoning_content, content) where either may be empty.

Parameters:

text (str)

Return type:

Tuple[Optional[str], str]

parse_stream_chunk(delta)

Parse an incremental streaming delta.

Returns (reasoning_delta, content_delta). Either may be "".

Parameters:

delta (str)

Return type:

Tuple[str, str]