[PARSER][Mistral] unified engine-based parser for reasoning and tool calls (#48947)

This commit is contained in:
Julien Denize
2026-07-30 15:38:00 +02:00
committed by GitHub
parent e2efe79695
commit 1a20d23dab
30 changed files with 2934 additions and 1495 deletions
+5 -10
View File
@@ -12,10 +12,8 @@ from vllm.utils.import_utils import LazyLoader
if TYPE_CHECKING:
# if type checking, eagerly import the module
import vllm.tokenizers.mistral as mt
import vllm.tool_parsers.mistral_tool_parser as mtp
else:
mt = LazyLoader("mt", globals(), "vllm.tokenizers.mistral")
mtp = LazyLoader("mtp", globals(), "vllm.tool_parsers.mistral_tool_parser")
def is_mistral_tokenizer(obj: TokenizerLike | None) -> TypeGuard[mt.MistralTokenizer]:
@@ -31,13 +29,10 @@ def is_mistral_tokenizer(obj: TokenizerLike | None) -> TypeGuard[mt.MistralToken
def is_mistral_tool_parser(cls: type | None) -> bool:
"""Return true if *cls* is (a subclass of) MistralToolParser.
"""Return true if *cls* carries the ``IS_MISTRAL_TOOL_PARSER`` marker.
Uses a class attribute check so that importing
``vllm.tool_parsers.mistral_tool_parser`` — and transitively
``mistral_common`` — is not required.
The marker is set on the engine-adapter subclass registered under the
``"mistral"`` tool-parser key. No import of the parser module is
required.
"""
return bool(
getattr(cls, "IS_MISTRAL_TOOL_PARSER", False)
and issubclass(cls, mtp.MistralToolParser) # type: ignore[arg-type]
)
return bool(getattr(cls, "IS_MISTRAL_TOOL_PARSER", False))