diff --git a/Dockerfile b/Dockerfile index c034c7f..7921883 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,3 +29,7 @@ COPY deepseekv32_tool_parser.py /usr/local/lib/python3.12/dist-packages/vllm/too # Copy over minimax tool call parser with kwargs fixes COPY minimax_tool_parser.py /usr/local/lib/python3.12/dist-packages/vllm/tool_parsers/minimax_tool_parser.py + +# Copy over minimax parsers with kwargs fixes +COPY minimax_tool_parser.py /usr/local/lib/python3.12/dist-packages/vllm/tool_parsers/minimax_tool_parser.py +COPY minimax_m2_parser.py /usr/local/lib/python3.12/dist-packages/vllm/parser/minimax_m2_parser.py diff --git a/minimax_m2_parser.py b/minimax_m2_parser.py new file mode 100644 index 0000000..068bef4 --- /dev/null +++ b/minimax_m2_parser.py @@ -0,0 +1,61 @@ +# 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 +from vllm.tool_parsers.abstract_tool_parser import ( + Tool, +) +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 start token, only end + token. All content before is reasoning, content after is the + actual response. + 2. Tool Calls: They use ... tags + with ... and ... + syntax. + """ + + # Class-level parser classes for compatibility + reasoning_parser_cls = MiniMaxM2ReasoningParser + tool_parser_cls = MinimaxM2ToolParser + + def __init__( + self, + tokenizer: TokenizerLike, + tools: list[Tool] | None = None, + *args, + **kwargs, + ): + super().__init__(tokenizer, *args, **kwargs) + + # Initialize the underlying parsers + self._reasoning_parser = MiniMaxM2ReasoningParser(tokenizer, *args, **kwargs) + self._tool_parser = MinimaxM2ToolParser(tokenizer, tools) + + logger.debug( + "vLLM Successfully initialized parser %s!", self.__class__.__name__ + ) \ No newline at end of file