vllm_mlx.reasoning.deepseek_r1_parser¶
Reasoning parser for DeepSeek-R1 models.
View the complete module source at #L1-L114.
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.deepseek_r1_parser
¶
Reasoning parser for DeepSeek-R1 models.
DeepSeek-R1 uses
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser
¶
Bases: BaseThinkingReasoningParser
Reasoning parser for DeepSeek-R1 model.
DeepSeek-R1 uses <think>...</think> tokens to denote reasoning text.
This parser is more lenient than Qwen3:
- The <think> tag may not be explicitly generated (model assumes it)
- If only </think> is found, everything before it is reasoning
Example:
Input: "<think>Step 1: analyze...
Step 2: solve...The answer is 42." Output: reasoning="Step 1: analyze... Step 2: solve...", content="The answer is 42."
Input: "reasoning content</think>final answer" # No opening tag
Output: reasoning="reasoning content", content="final answer"
Source code in vllm_mlx/reasoning/think_parser.py
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser.start_token
property
¶
Return the marker that opens an explicit DeepSeek reasoning span.
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser.end_token
property
¶
Return the marker that closes a DeepSeek reasoning span.
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser.extract_reasoning
¶
Extract reasoning from DeepSeek-R1 output.
More lenient than Qwen3 - handles cases where start tag is implicit.
Parameters:
-
model_output(str) –Complete model output text.
Returns:
-
tuple[str | None, str | None]–(reasoning, content) tuple.
Source code in vllm_mlx/reasoning/deepseek_r1_parser.py
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser.extract_reasoning_streaming
¶
extract_reasoning_streaming(previous_text: str, current_text: str, delta_text: str) -> DeltaMessage | None
Extract reasoning from streaming delta.
Handles DeepSeek-R1's pattern where
Parameters:
-
previous_text(str) –Text accumulated before this delta.
-
current_text(str) –Text including this delta.
-
delta_text(str) –Just the new text.
Returns:
-
DeltaMessage | None–DeltaMessage with reasoning/content, or None to skip.
Source code in vllm_mlx/reasoning/deepseek_r1_parser.py
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.deepseek_r1_parser.DeepSeekR1ReasoningParser · class
Reasoning parser for DeepSeek-R1 model.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser
Exceptions and behavior
Class DeepSeekR1ReasoningParser derives from BaseThinkingReasoningParser and declares 4 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser.start_token · method
Return the marker that opens an explicit DeepSeek reasoning span.
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
'<think>'
Exceptions and behavior
Method DeepSeekR1ReasoningParser.start_token returns '<think>'.
No direct raise statement appears in this definition.
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser.end_token · method
Return the marker that closes a DeepSeek reasoning span.
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
'</think>'
Exceptions and behavior
Method DeepSeekR1ReasoningParser.end_token returns '</think>'.
No direct raise statement appears in this definition.
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser.extract_reasoning · method
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser.extract_reasoning(model_output: str) -> tuple[str | None, str | None]
Extract reasoning from DeepSeek-R1 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:
self._extract_complete_reasoning(model_output);(None, model_output);super().extract_reasoning(model_output)
Exceptions and behavior
Method DeepSeekR1ReasoningParser.extract_reasoning calls self._extract_complete_reasoning, super().extract_reasoning, super; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser.extract_reasoning_streaming · method
vllm_mlx.reasoning.deepseek_r1_parser.DeepSeekR1ReasoningParser.extract_reasoning_streaming(previous_text: str, current_text: str, delta_text: str) -> DeltaMessage | None
Extract reasoning from streaming delta.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
previous_text |
str |
yes |
none |
Text accumulated before this delta. |
current_text |
str |
yes |
none |
Text including this delta. |
delta_text |
str |
yes |
none |
Just the new text. |
Returns
- Type:
DeltaMessage | None - Direct return expressions:
DeltaMessage(reasoning=reasoning_part if reasoning_part else None, content=content_part if content_part else None);result
Exceptions and behavior
Method DeepSeekR1ReasoningParser.extract_reasoning_streaming calls super().extract_reasoning_streaming, super, delta_text.find, len; has 2 explicit return paths.
No direct raise statement appears in this definition.
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 |
|---|---|---|---|---|
DeepSeekR1ReasoningParser |
class | DeepSeekR1ReasoningParser() |
Reasoning parser for DeepSeek-R1 model. | #L14-L114 |
DeepSeekR1ReasoningParser.start_token |
method | DeepSeekR1ReasoningParser.start_token() -> str |
Return the marker that opens an explicit DeepSeek reasoning span. | #L32-L35 |
DeepSeekR1ReasoningParser.end_token |
method | DeepSeekR1ReasoningParser.end_token() -> str |
Return the marker that closes a DeepSeek reasoning span. | #L38-L41 |
DeepSeekR1ReasoningParser.extract_reasoning |
method | DeepSeekR1ReasoningParser.extract_reasoning(model_output: str) -> tuple[str \| None, str \| None] |
Extract reasoning from DeepSeek-R1 output. | #L43-L67 |
DeepSeekR1ReasoningParser.extract_reasoning_streaming |
method | DeepSeekR1ReasoningParser.extract_reasoning_streaming(previous_text: str, current_text: str, delta_text: str) -> DeltaMessage \| None |
Extract reasoning from streaming delta. | #L69-L114 |