Skip to content

vllm.parser.minimax_m2

MiniMax M2 parser for XML-style tool calls.

MiniMax M2 tool call format::

<minimax:tool_call><invoke name="get_weather">
<parameter name="city">Seattle</parameter>
</invoke></minimax:tool_call>

Each <invoke> block becomes one tool call. The argument body consists of <parameter name="...">...</parameter> tags.

Classes:

  • MinimaxM2Parser –

    MiniMax M2 parser backed by the declarative parser engine.

MinimaxM2Parser

Bases: ParserEngine

MiniMax M2 parser backed by the declarative parser engine.

Source code in vllm/parser/minimax_m2.py
class MinimaxM2Parser(ParserEngine):
    """MiniMax M2 parser backed by the declarative parser engine."""

    def __init__(self, tokenizer, tools=None, **kwargs) -> None:
        kwargs.setdefault("parser_engine_config", minimax_m2_config())
        super().__init__(tokenizer, tools, **kwargs)
        self._think_end_token_id = self.vocab.get(THINK_END)

    def extract_content_ids(self, input_ids: list[int]) -> list[int]:
        end_id = self._think_end_token_id
        if end_id is None:
            return []
        for i in range(len(input_ids) - 1, -1, -1):
            if input_ids[i] == end_id:
                return input_ids[i + 1 :]
        return []

_minimax_m2_parse_args(raw_args, partial)

Return the arguments and the match of the open trailing value, if any.

Source code in vllm/parser/minimax_m2.py
def _minimax_m2_parse_args(
    raw_args: str, partial: bool
) -> tuple[dict[str, object], re.Match | None]:
    """Return the arguments and the match of the open trailing value, if any."""
    params: dict[str, object] = {}

    for match in _PARAM_RE.finditer(raw_args):
        name = _param_name(match)
        if not name:
            continue
        # Keep the value verbatim (like the glm47 converter): it is inline
        # between `>` and `</parameter>`, so surrounding whitespace is data.
        params[name] = match.group("value")

    open_match = None
    if partial:
        remaining = _PARAM_RE.sub("", raw_args)
        match = _PARTIAL_PARAM_RE.search(remaining)
        if match:
            name = _param_name(match)
            if name:
                # Verbatim, same as the complete-match loop above.
                params[name] = match.group("value")
                open_match = match

    return params, open_match

_value_end_window(text)

Return the suffix of text that may still grow into a value end.

Source code in vllm/parser/minimax_m2.py
def _value_end_window(text: str) -> str:
    """Return the suffix of *text* that may still grow into a value end."""
    start = text.rfind("<")
    if start == -1:
        return ""
    tail = text[start:]
    return tail if _PARAM_VALUE_END_RE.fullmatch(tail, partial=True) else ""