Skip to content

vllm.parser.ling3

Ling3 parser for reasoning and tool calls.

Ling3 uses the same XML tool-call format as GLM-4.7 and defaults thinking on. It follows the GLM-style <think> / </think> reasoning format and treats <tool_call> as an implicit reasoning terminator.

Classes:

  • Ling3Parser

    Ling3 parser backed by the GLM XML parser engine.

Ling3Parser

Bases: Glm47MoeParser

Ling3 parser backed by the GLM XML parser engine.

Source code in vllm/parser/ling3.py
class Ling3Parser(Glm47MoeParser):
    """Ling3 parser backed by the GLM XML parser engine."""

    def __init__(
        self,
        tokenizer: TokenizerLike,
        tools: list[Tool] | None = None,
        **kwargs,
    ) -> None:
        chat_kwargs = kwargs.get("chat_template_kwargs", {}) or {}
        thinking = chat_kwargs.get("thinking", None)
        enable_thinking = chat_kwargs.get("enable_thinking", None)
        self.thinking_enabled = (
            True
            if thinking is None and enable_thinking is None
            else bool(thinking) or bool(enable_thinking)
        )
        parser_config = replace(
            glm47_moe_config(thinking=self.thinking_enabled),
            name="ling3",
        )
        kwargs.setdefault(
            "parser_engine_config",
            parser_config,
        )
        ParserEngine.__init__(self, tokenizer, tools, **kwargs)

    @property
    def reasoning_start_str(self) -> str:
        return THINK_START

    @property
    def reasoning_end_str(self) -> str:
        return THINK_END

    def extract_reasoning(
        self,
        model_output: str,
        request: ChatCompletionRequest | ResponsesRequest,
    ) -> tuple[str | None, str | None]:
        if not self.thinking_enabled:
            return None, model_output

        reasoning, content = super().extract_reasoning(model_output, request)
        if reasoning and not content and "<tool_call>" not in model_output:
            return None, reasoning
        return reasoning, content