Skip to content

vllm.parser.deepseek_v4

DeepSeek V4 parser: <think>/</think> reasoning plus DSML tool calls in a single state machine.

DeepSeek V4 output format::

<think>
...reasoning...
</think>
<|DSML|tool_calls>
<|DSML|invoke name="func_name">
<|DSML|parameter name="location" string="true">杭州</|DSML|parameter>
<|DSML|parameter name="count" string="false">5</|DSML|parameter>
</|DSML|invoke>
</|DSML|tool_calls>

_param_patterns(param_start, param_close)

Complete and trailing-partial parameter regexes for one DSML dialect.

The string attribute is optional: the model sometimes omits it, and dropping such a parameter hands the client a tool call with no arguments.

Source code in vllm/parser/deepseek_v4.py
def _param_patterns(
    param_start: str, param_close: str
) -> tuple[re.Pattern, re.Pattern]:
    """Complete and trailing-partial parameter regexes for one DSML dialect.

    The ``string`` attribute is optional: the model sometimes omits it, and
    dropping such a parameter hands the client a tool call with no arguments.
    """
    start, close = re.escape(param_start), re.escape(param_close)
    head = rf'{start}\s+name="([^"]+)"(?:\s+string="([^"]*)")?\s*>'
    return (
        re.compile(rf"{head}(.*?)(?:{close}|(?={start}\s+name=))", re.DOTALL),
        re.compile(rf"{head}(.*)$", re.DOTALL),
    )