minimax_m2_parser.py 1.97 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project

"""
MiniMax M2 Parser - A unified parser for MiniMax M2 models.

This parser combines the existing MiniMaxM2ReasoningParser and
MinimaxM2ToolParser into a single unified interface by delegating
to those implementations.
"""

from vllm.logger import init_logger
from vllm.parser.abstract_parser import DelegatingParser
from vllm.reasoning.minimax_m2_reasoning_parser import MiniMaxM2ReasoningParser
from vllm.tokenizers import TokenizerLike
16
17
18
from vllm.tool_parsers.abstract_tool_parser import (
    Tool,
)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from vllm.tool_parsers.minimax_m2_tool_parser import MinimaxM2ToolParser

logger = init_logger(__name__)


class MiniMaxM2Parser(DelegatingParser):
    """
    Unified parser for MiniMax M2 models that handles both reasoning
    extraction and tool call parsing.

    This parser delegates to the existing implementations:
    - MiniMaxM2ReasoningParser for reasoning extraction
    - MinimaxM2ToolParser for tool call parsing

    MiniMax M2 models have two special behaviors:
    1. Reasoning: They don't generate <think> start token, only </think> end
       token. All content before </think> is reasoning, content after is the
       actual response.
    2. Tool Calls: They use <minimax:tool_call>...</minimax:tool_call> tags
       with <invoke name="...">...</invoke> and <parameter name="...">...</parameter>
       syntax.
    """

    # Class-level parser classes for compatibility
    reasoning_parser_cls = MiniMaxM2ReasoningParser
    tool_parser_cls = MinimaxM2ToolParser

46
    def __init__(self, tokenizer: TokenizerLike, tools: list[Tool] | None = None):
47
48
49
50
        super().__init__(tokenizer)

        # Initialize the underlying parsers
        self._reasoning_parser = MiniMaxM2ReasoningParser(tokenizer)
51
        self._tool_parser = MinimaxM2ToolParser(tokenizer, tools)
52
53
54
55

        logger.debug(
            "vLLM Successfully initialized parser %s!", self.__class__.__name__
        )