[Tool Parser][1/3] Pass tools to ToolParser constructor (#38029)

Signed-off-by: sfeng33 <4florafeng@gmail.com>
This commit is contained in:
Flora Feng
2026-03-25 22:29:06 -04:00
committed by GitHub
parent 87f05d6880
commit e2db2b4234
38 changed files with 147 additions and 92 deletions

View File

@@ -565,7 +565,7 @@ class OpenAIServingChat(OpenAIServing):
)
tool_parsers: list[ToolParser | None] = [
self.tool_parser(tokenizer)
self.tool_parser(tokenizer, request.tools)
] * num_choices
else:
tool_parsers = [None] * num_choices
@@ -1331,7 +1331,7 @@ class OpenAIServingChat(OpenAIServing):
"Tokenizer not available when `skip_tokenizer_init=True`"
)
tool_parser = self.tool_parser(tokenizer)
tool_parser = self.tool_parser(tokenizer, request.tools)
# NOTE: We use token_ids for openai tool parser
tool_call_info = tool_parser.extract_tool_calls(
"",

View File

@@ -925,7 +925,7 @@ class OpenAIServing:
# Automatic Tool Call Parsing
try:
tool_parser = tool_parser_cls(tokenizer)
tool_parser = tool_parser_cls(tokenizer, request.tools)
except RuntimeError as e:
logger.exception("Error in tool parser creation.")
raise e

View File

@@ -52,7 +52,7 @@ class ResponsesParser:
self.reasoning_parser_instance = reasoning_parser_cls(tokenizer)
self.tool_parser_instance = None
if tool_parser_cls is not None:
self.tool_parser_instance = tool_parser_cls(tokenizer)
self.tool_parser_instance = tool_parser_cls(tokenizer, request.tools)
# Store the last finish_reason to determine response status
self.finish_reason: str | None = None

View File

@@ -1344,7 +1344,7 @@ class OpenAIServingResponses(OpenAIServing):
reasoning_parser = self.parser.reasoning_parser_cls(tokenizer)
tool_parser = None
if self.parser and self.parser.tool_parser_cls:
tool_parser = self.parser.tool_parser_cls(tokenizer)
tool_parser = self.parser.tool_parser_cls(tokenizer, request.tools)
reasoning_ended = False
tool_call_text_started = False
previous_text = ""