import logging from sglang.srt.function_call.deepseekv32_detector import DeepSeekV32Detector logger = logging.getLogger(__name__) class DeepSeekV4Detector(DeepSeekV32Detector): """ Detector for DeepSeek V4 model function call format. The DeepSeek V4 format uses XML-like DSML tags to delimit function calls. Supports two parameter formats: Format 1 - XML Parameter Tags: ``` <|DSML|tool_calls> <|DSML|invoke name="function_name"> <|DSML|parameter name="param_name" string="true">value ... ``` Format 2 - Direct JSON: ``` <|DSML|tool_calls> <|DSML|invoke name="function_name"> { "param_name": "value" } ``` Examples: ``` <|DSML|tool_calls> <|DSML|invoke name="get_favorite_tourist_spot"> <|DSML|parameter name="city" string="true">San Francisco <|DSML|tool_calls> <|DSML|invoke name="get_favorite_tourist_spot"> { "city": "San Francisco" } ``` Key Components: - Tool Calls Section: Wrapped between `<|DSML|tool_calls>` and `` - Individual Tool Call: Wrapped between `<|DSML|invoke name="...">` and `` - Parameters: Either XML tags or direct JSON format - Supports multiple tool calls Reference: DeepSeek V4 format specification """ def __init__(self): super().__init__() self.bot_token = "<|DSML|tool_calls>" self.eot_token = "" self.function_calls_regex = r"<|DSML|tool_calls>(.*?)" def get_structural_tag_name(self) -> str: return "deepseek_v4"