Files
vllm-with-lmcache/deepseekv4_tool_parser.py
biondizzle 4556945525 fix: V4 parser instance attrs shadowed by V3.2 __init__
V3.2 __init__ sets self.tool_call_start_token and self.tool_call_end_token
as instance attributes with function_calls tag values, shadowing the V4
class-level attributes that use tool_calls tags. Re-assign after super().
2026-04-25 23:14:37 +00:00

34 lines
1.4 KiB
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)
# The V3.2 __init__ overwrites the class-level start/end tokens
# with instance attributes set to "function_calls". Re-override
# them to the V4 "tool_calls" tags so _extract_content(),
# _extract_invoke_regions(), etc. match the correct tags.
self.tool_call_start_token = "<DSMLtool_calls>"
self.tool_call_end_token = "</DSMLtool_calls>"
self.tool_calls_start_token = self.tool_call_start_token
# 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
)