[Bugfix] Pass effective chat template kwargs to reasoning parsers (#40460)

Signed-off-by: Bugen Zhao <i@bugenzhao.com>
This commit is contained in:
Bugen Zhao
2026-04-21 22:17:51 -07:00
committed by GitHub
parent 4eafc72928
commit 0210024ae7
6 changed files with 71 additions and 17 deletions
+16 -2
View File
@@ -267,6 +267,14 @@ class OpenAIServingResponses(OpenAIServing):
self.tool_server = tool_server
def _effective_chat_template_kwargs(
self, request: ResponsesRequest
) -> dict[str, Any]:
return request.build_chat_params(
self.chat_template,
self.chat_template_content_format,
).chat_template_kwargs
def _validate_generator_input(
self,
engine_input: EngineInput,
@@ -464,7 +472,10 @@ class OpenAIServingResponses(OpenAIServing):
context = SimpleContext()
if self.parser and self.parser.reasoning_parser_cls is not None:
reasoning_parser = self.parser.reasoning_parser_cls(tokenizer)
reasoning_parser = self.parser.reasoning_parser_cls(
tokenizer,
chat_template_kwargs=self._effective_chat_template_kwargs(request),
)
if (
isinstance(
struct_out := sampling_params.structured_outputs,
@@ -835,7 +846,10 @@ class OpenAIServingResponses(OpenAIServing):
and self.parser.reasoning_parser_cls is not None
and isinstance(context, (SimpleContext, ParsableContext))
):
reasoning_parser = self.parser.reasoning_parser_cls(tokenizer)
reasoning_parser = self.parser.reasoning_parser_cls(
tokenizer,
chat_template_kwargs=self._effective_chat_template_kwargs(request),
)
accumulated = getattr(context, "_accumulated_token_ids", []) or []
num_reasoning_tokens = reasoning_parser.count_reasoning_tokens(accumulated)