fix(reasoning): let --enable-strict-thinking works for DeepSeek-V4 (#32400)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Xinyuan Tong <xinyuantong.cs@gmail.com>
This commit is contained in:
Shangming Cai
2026-07-27 18:15:47 +08:00
committed by GitHub
co-authored by Claude Fable 5 Xinyuan Tong
parent 08af5aea57
commit 1d350aaad3
2 changed files with 48 additions and 1 deletions
+32 -1
View File
@@ -2,6 +2,14 @@ import inspect
import re
from typing import Dict, List, Optional, Tuple, Type
from sglang.srt.entrypoints.openai.encoding_dsv4 import dsml_token as dsv4_dsml_token
from sglang.srt.entrypoints.openai.encoding_dsv4 import eos_token as dsv4_eos_token
from sglang.srt.entrypoints.openai.encoding_dsv4 import (
thinking_end_token as dsv4_thinking_end_token,
)
from sglang.srt.entrypoints.openai.encoding_dsv4 import (
thinking_start_token as dsv4_thinking_start_token,
)
from sglang.srt.entrypoints.openai.protocol import ChatCompletionRequest
from sglang.srt.function_call.hunyuan_detector import resolve_hunyuan_tokens
from sglang.srt.parser.harmony_parser import HarmonyParser
@@ -897,6 +905,29 @@ class _DeepSeekV3Detector(Qwen3Detector):
self.reasoning_default = "explicit_thinking"
class DeepSeekV4Detector(BaseReasoningFormatDetector):
def __init__(
self,
stream_reasoning: bool = True,
force_reasoning: bool = False,
continue_final_message: bool = False,
previous_content: str = "",
force_nonempty_content: bool = False,
):
super().__init__(
dsv4_thinking_start_token,
dsv4_thinking_end_token,
think_excluded_tokens=[dsv4_eos_token, dsv4_dsml_token],
force_reasoning=force_reasoning,
stream_reasoning=stream_reasoning,
continue_final_message=continue_final_message,
previous_content=previous_content,
thinks_internally=True,
reasoning_default="explicit_thinking",
force_nonempty_content=force_nonempty_content,
)
class _MimoDetector(Qwen3Detector):
"""MIMO reuses Qwen3 tokens but requires explicit enable_thinking=True to enable."""
@@ -1385,7 +1416,7 @@ class ReasoningParser:
"apertus2509": Apertus2509Detector,
"deepseek-r1": DeepSeekR1Detector,
"deepseek-v3": _DeepSeekV3Detector,
"deepseek-v4": _DeepSeekV3Detector,
"deepseek-v4": DeepSeekV4Detector,
"glm45": Glm45Detector,
"hunyuan": HunyuanDetector,
"gpt-oss": GptOssDetector,