[Frontend] Let an unset --tool-strict-level fall back to the tool parser's default (#61328)
Signed-off-by: Bugen Zhao <i@bugenzhao.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
91ed2859c7
commit
8fa5ae844a
@@ -2,6 +2,7 @@
|
||||
// SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
use super::{GlmXmlToolParser, Separator};
|
||||
use crate::output_grammar::ToolStrictLevel;
|
||||
use crate::tool::{Result, StructuralTagBuilder, Tool, ToolParser, ToolParserOutput};
|
||||
|
||||
/// Tool parser for GLM-4.7 MoE XML-style tool calls.
|
||||
@@ -25,6 +26,11 @@ impl ToolParser for Glm47MoeToolParser {
|
||||
Ok(Box::new(Self::new(tools)))
|
||||
}
|
||||
|
||||
// Constrain auto tool calls by default, like the Python `glm47` parser.
|
||||
fn default_tool_strict_level(&self) -> ToolStrictLevel {
|
||||
ToolStrictLevel::Function
|
||||
}
|
||||
|
||||
fn structural_tag_builder(&self) -> Option<&dyn StructuralTagBuilder> {
|
||||
Some(xgrammar_structural_tag::Model::Glm47.builder())
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ pub use xgrammar_structural_tag::builders::StructuralTagBuilder;
|
||||
use xgrammar_structural_tag::format::Format;
|
||||
use xgrammar_structural_tag::tool::{AllowedToolsMode, ToolChoiceValue};
|
||||
|
||||
use crate::output_grammar::{self, OutputGrammarContext};
|
||||
use crate::output_grammar::{self, OutputGrammarContext, ToolStrictLevel};
|
||||
use crate::utils;
|
||||
|
||||
/// One function-style tool made available to the model.
|
||||
@@ -199,6 +199,12 @@ pub trait ToolParser: Send {
|
||||
false
|
||||
}
|
||||
|
||||
/// Return the tool strict level applied when the operator leaves
|
||||
/// `--tool-strict-level` unset.
|
||||
fn default_tool_strict_level(&self) -> ToolStrictLevel {
|
||||
ToolStrictLevel::Auto
|
||||
}
|
||||
|
||||
/// Build the language of everything the model may emit after reasoning
|
||||
/// ends for the context's tool choice: visible text plus tool calls. `None`
|
||||
/// means no tool grammar applies.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
use vllm_tokenizer::{DecodedText, DynTokenizer};
|
||||
|
||||
use super::{Result, UnifiedParser, UnifiedParserError, UnifiedParserOutput};
|
||||
use crate::output_grammar::{self, BuiltOutputGrammar, OutputGrammarContext};
|
||||
use crate::output_grammar::{self, BuiltOutputGrammar, OutputGrammarContext, ToolStrictLevel};
|
||||
use crate::reasoning::ReasoningParser;
|
||||
use crate::tool::{Tool, ToolParser, ToolParserOutput};
|
||||
|
||||
@@ -83,6 +83,12 @@ impl UnifiedParser for CombinedParser {
|
||||
|| self.tool.as_ref().is_some_and(|parser| parser.preserve_special_tokens())
|
||||
}
|
||||
|
||||
fn default_tool_strict_level(&self) -> ToolStrictLevel {
|
||||
self.tool.as_ref().map_or(ToolStrictLevel::Auto, |parser| {
|
||||
parser.default_tool_strict_level()
|
||||
})
|
||||
}
|
||||
|
||||
fn build_output_grammar(
|
||||
&self,
|
||||
ctx: &OutputGrammarContext<'_>,
|
||||
|
||||
@@ -20,7 +20,7 @@ use thiserror::Error;
|
||||
use thiserror_ext::Macro;
|
||||
use vllm_tokenizer::{DecodedText, DynTokenizer};
|
||||
|
||||
use crate::output_grammar::{self, BuiltOutputGrammar, OutputGrammarContext};
|
||||
use crate::output_grammar::{self, BuiltOutputGrammar, OutputGrammarContext, ToolStrictLevel};
|
||||
use crate::reasoning::ReasoningError;
|
||||
use crate::tool::{Tool, ToolCallDelta, ToolParserError, ToolParserEvent, ToolParserOutput};
|
||||
use crate::utils::SpecialToken;
|
||||
@@ -242,6 +242,12 @@ pub trait UnifiedParser: Send {
|
||||
false
|
||||
}
|
||||
|
||||
/// Return the tool strict level applied when the operator leaves
|
||||
/// `--tool-strict-level` unset.
|
||||
fn default_tool_strict_level(&self) -> ToolStrictLevel {
|
||||
ToolStrictLevel::Auto
|
||||
}
|
||||
|
||||
/// Build the request output grammar after prompt-based initialization.
|
||||
fn build_output_grammar(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user