[Bugfix] Tolerate misspelled DSML tool_calls wrapper (#56141)

Signed-off-by: sfeng33 <4florafeng@gmail.com>
This commit is contained in:
Flora Feng
2026-09-10 15:04:29 +08:00
committed by GitHub
parent 83990f5bcc
commit 9e25706560
9 changed files with 262 additions and 14 deletions
+6 -2
View File
@@ -5,6 +5,7 @@ tokens, with prefix-match buffering for ambiguous boundaries."""
from __future__ import annotations
from collections.abc import Mapping
from dataclasses import dataclass
import regex as re
@@ -284,7 +285,9 @@ class IncrementalLexer:
return n
def terminals_from_literals(literals: dict[str, str]) -> list[TerminalDef]:
def terminals_from_literals(
literals: Mapping[str, str | tuple[str, ...]],
) -> list[TerminalDef]:
return [
TerminalDef(
name=name,
@@ -292,5 +295,6 @@ def terminals_from_literals(literals: dict[str, str]) -> list[TerminalDef]:
is_literal=True,
literal=lit,
)
for name, lit in literals.items()
for name, value in literals.items()
for lit in ((value,) if isinstance(value, str) else value)
]
+2 -2
View File
@@ -158,11 +158,11 @@ class ParserEngine(Parser):
@property
def reasoning_start_str(self) -> str | None:
return self.parser_engine_config.terminals.get("THINK_START")
return self.parser_engine_config.terminal_literal("THINK_START")
@property
def reasoning_end_str(self) -> str | None:
return self.parser_engine_config.terminals.get("THINK_END")
return self.parser_engine_config.terminal_literal("THINK_END")
@cached_property
def vocab(self) -> dict[str, int]:
+19 -2
View File
@@ -17,7 +17,7 @@ Each model format is described by a :class:`ParserEngineConfig` that specifies:
from __future__ import annotations
from collections.abc import Callable
from collections.abc import Callable, Mapping
from dataclasses import dataclass, field
from enum import Enum, auto
from functools import cached_property
@@ -54,7 +54,8 @@ class ParserEngineConfig:
name: str
terminals: dict[str, str] = field(default_factory=dict)
# A terminal may carry several spellings; the first spelling is the canonical one.
terminals: Mapping[str, str | tuple[str, ...]] = field(default_factory=dict)
token_id_terminals: dict[str, str] = field(default_factory=dict)
@@ -100,6 +101,22 @@ class ParserEngineConfig:
# Reject tool calls whose names are absent from the request tools.
validate_tool_names: bool = False
def terminal_literal(self, name: str) -> str | None:
"""Canonical spelling of terminal *name*, or ``None`` if undeclared."""
value = self.terminals.get(name)
if isinstance(value, tuple):
return value[0] if value else None
return value
@property
def terminal_literals(self) -> frozenset[str]:
"""Every declared spelling across all terminals."""
return frozenset(
lit
for value in self.terminals.values()
for lit in ((value,) if isinstance(value, str) else value)
)
@cached_property
def terminal_defs(self):
from vllm.parser.engine.incremental_lexer import terminals_from_literals
@@ -51,7 +51,7 @@ def _build_drop_info(
configured_texts = (
set(config.token_id_terminals.values())
| set(config.terminals.values())
| config.terminal_literals
| config.preserve_tokens
)