| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | """Step-3.5 / Step-3.7 parser for tool calls and reasoning. |
| 4 | |
| 5 | Both models use the Qwen3 XML tool-call grammar and ``<think>`` reasoning |
| 6 | unchanged. Two things differ from :class:`Qwen3Parser`: |
| 7 | |
| 8 | * The chat template always prefills ``<think>\\n`` and has no switch to turn |
| 9 | thinking off, so ``enable_thinking`` is ignored. |
| 10 | * The model closes reasoning with ``\\n</think>\\n``, so trailing reasoning |
| 11 | whitespace is stripped. |
| 12 | """ |
| 13 | |
| 14 | from __future__ import annotations |
| 15 | |
| 16 | import functools |
| 17 | from dataclasses import replace |
| 18 | from typing import TYPE_CHECKING |
| 19 | |
| 20 | from vllm.parser.engine.parser_engine_config import ParserEngineConfig |
| 21 | from vllm.parser.qwen3 import CHATML_TURN_BOUNDARIES, Qwen3Parser, qwen3_config |
| 22 | |
| 23 | if TYPE_CHECKING: |
| 24 | from vllm.tokenizers import TokenizerLike |
| 25 | from vllm.tool_parsers.abstract_tool_parser import Tool |
| 26 | |
| 27 | |
| 28 | @functools.cache |
| 29 | def step3p5_config() -> ParserEngineConfig: |
| 30 | return replace( |
| 31 | qwen3_config( |
| 32 | thinking=True, |
| 33 | name="step3p5", |
| 34 | turn_boundary_tokens=CHATML_TURN_BOUNDARIES, |
| 35 | ), |
| 36 | strip_trailing_reasoning_whitespace=True, |
| 37 | ) |
| 38 | |
| 39 | |
| 40 | class Step3p5Parser(Qwen3Parser): |
| 41 | def __init__( |
| 42 | self, |
| 43 | tokenizer: TokenizerLike, |
| 44 | tools: list[Tool] | None = None, |
| 45 | **kwargs, |
| 46 | ) -> None: |
| 47 | kwargs.setdefault("parser_engine_config", step3p5_config()) |
| 48 | super().__init__(tokenizer, tools, **kwargs) |
| 49 | self.thinking_enabled = True |