Skip to content

vllm_mlx.reasoning.qwen3_parser

Reasoning parser for Qwen3 models.

View the complete module source at #L1-L68.

API details

Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.

vllm_mlx.reasoning.qwen3_parser

Reasoning parser for Qwen3 models.

Qwen3 uses ... tags for reasoning content and supports a strict switch via 'enable_thinking=False' in chat template kwargs.

Supports implicit reasoning mode where is injected in the prompt by AI agents (e.g., OpenCode) and only appears in the output.

vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser

Qwen3ReasoningParser(tokenizer=None)

Bases: BaseThinkingReasoningParser

Reasoning parser for Qwen3 models.

Qwen3 uses ... tokens to denote reasoning text.

Supports three scenarios: 1. Both tags in output: reasoningcontent 2. Only closing tag (think in prompt): reasoningcontent 3. No tags: pure content

Example (normal): Input: "Let me analyze this...The answer is 42." Output: reasoning="Let me analyze this...", content="The answer is 42."

Example (think in prompt): Input: "Let me analyze this...The answer is 42." Output: reasoning="Let me analyze this...", content="The answer is 42."

Source code in vllm_mlx/reasoning/think_parser.py
def __init__(self, tokenizer=None):
    super().__init__(tokenizer)
    # Streaming state — reset per request via reset_state()
    self._phase: str = "pre_think"  # "pre_think" | "thinking" | "content"
    self._content_started = False
    self._content_buffer = ""
    # Tool call promotion state.
    self._in_tool_call = False
    self._tool_call_buffer = ""

vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser.start_token property

start_token: str

Return the Qwen3 reasoning opening marker.

vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser.end_token property

end_token: str

Return the Qwen3 reasoning closing marker.

vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser.extract_reasoning

extract_reasoning(model_output: str) -> tuple[str | None, str | None]

Extract reasoning from Qwen3 output.

Handles both explicit ... tags and implicit mode where was in the prompt (only in output).

Parameters:

  • model_output (str) –

    Complete model output text.

Returns:

  • tuple[str | None, str | None]

    (reasoning, content) tuple.

Source code in vllm_mlx/reasoning/qwen3_parser.py
def extract_reasoning(
    self,
    model_output: str,
) -> tuple[str | None, str | None]:
    """
    Extract reasoning from Qwen3 output.

    Handles both explicit <think>...</think> tags and implicit mode
    where <think> was in the prompt (only </think> in output).

    Args:
        model_output: Complete model output text.

    Returns:
        (reasoning, content) tuple.
    """
    # If no end token at all, treat as pure content
    if self.end_token not in model_output:
        return None, model_output

    # Use base class implementation (handles both explicit and implicit)
    return super().extract_reasoning(model_output)

Complete contract reference

Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.

vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser · class
vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser()

Reasoning parser for Qwen3 models.

Parameters

This callable has no explicit inputs.

Returns

  • Constructs: vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser

Exceptions and behavior

Class Qwen3ReasoningParser derives from BaseThinkingReasoningParser and declares 3 direct member(s). No direct raise statement appears in this definition.

View source #L15-L68.

vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser.start_token · method
vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser.start_token() -> str

Return the Qwen3 reasoning opening marker.

Parameters

This callable has no explicit inputs.

Returns

  • Type: str
  • Direct return expressions: '<think>'

Exceptions and behavior

Method Qwen3ReasoningParser.start_token returns '<think>'. No direct raise statement appears in this definition.

View source #L36-L39.

vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser.end_token · method
vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser.end_token() -> str

Return the Qwen3 reasoning closing marker.

Parameters

This callable has no explicit inputs.

Returns

  • Type: str
  • Direct return expressions: '</think>'

Exceptions and behavior

Method Qwen3ReasoningParser.end_token returns '</think>'. No direct raise statement appears in this definition.

View source #L42-L45.

vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser.extract_reasoning · method
vllm_mlx.reasoning.qwen3_parser.Qwen3ReasoningParser.extract_reasoning(model_output: str) -> tuple[str | None, str | None]

Extract reasoning from Qwen3 output.

Parameters

Name Type Required Default Description
model_output str yes none Complete model output text.

Returns

  • Type: tuple[str | None, str | None]
  • Direct return expressions: (None, model_output); super().extract_reasoning(model_output)

Exceptions and behavior

Method Qwen3ReasoningParser.extract_reasoning calls super().extract_reasoning, super; has 2 explicit return paths. No direct raise statement appears in this definition.

View source #L47-L68.

Complete symbol map

This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.

Symbol Kind Signature and inputs What it does Source
Qwen3ReasoningParser class Qwen3ReasoningParser() Reasoning parser for Qwen3 models. #L15-L68
Qwen3ReasoningParser.start_token method Qwen3ReasoningParser.start_token() -> str Return the Qwen3 reasoning opening marker. #L36-L39
Qwen3ReasoningParser.end_token method Qwen3ReasoningParser.end_token() -> str Return the Qwen3 reasoning closing marker. #L42-L45
Qwen3ReasoningParser.extract_reasoning method Qwen3ReasoningParser.extract_reasoning(model_output: str) -> tuple[str \| None, str \| None] Extract reasoning from Qwen3 output. #L47-L68