Files
vllm-with-lmcache/deepseekv4_tool_parser.py
2026-04-25 13:06:33 +00:00

27 lines
942 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import regex as re
from vllm.tool_parsers.deepseekv32_tool_parser import DeepSeekV32ToolParser
class DeepSeekV4ToolParser(DeepSeekV32ToolParser):
"""
DeepSeek V4 DSML tool parser.
V4 keeps the V3.2 DSML invoke/parameter grammar, but wraps tool calls in
``<DSMLtool_calls>`` instead of ``<DSMLfunction_calls>``.
"""
tool_call_start_token: str = "<DSMLtool_calls>"
tool_call_end_token: str = "</DSMLtool_calls>"
def __init__(self, tokenizer, tools=None):
super().__init__(tokenizer, tools)
# Recompile regexes with the V4 tool_calls tags instead of
# the V3.2 function_calls tags that the base class hardcodes.
self.tool_call_complete_regex = re.compile(
r"<DSMLtool_calls>(.*?)</DSMLtool_calls>", re.DOTALL
)