[Frontend] [Bugfix] respect server-level default chat template kwargs in reasoning parser (#31581)
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com> Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
@@ -659,9 +659,14 @@ class OpenAIServingChat(OpenAIServing):
|
|||||||
"Tokenizer not available when `skip_tokenizer_init=True`"
|
"Tokenizer not available when `skip_tokenizer_init=True`"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Pass the same chat template kwargs as used in tokenization
|
||||||
|
chat_template_kwargs = self._prepare_extra_chat_template_kwargs(
|
||||||
|
request.chat_template_kwargs,
|
||||||
|
self.default_chat_template_kwargs,
|
||||||
|
)
|
||||||
reasoning_parser = self.reasoning_parser(
|
reasoning_parser = self.reasoning_parser(
|
||||||
tokenizer,
|
tokenizer,
|
||||||
chat_template_kwargs=request.chat_template_kwargs, # type: ignore
|
chat_template_kwargs=chat_template_kwargs, # type: ignore[call-arg]
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
logger.exception("Error in reasoning parser creation.")
|
logger.exception("Error in reasoning parser creation.")
|
||||||
@@ -1437,9 +1442,14 @@ class OpenAIServingChat(OpenAIServing):
|
|||||||
"Tokenizer not available when `skip_tokenizer_init=True`"
|
"Tokenizer not available when `skip_tokenizer_init=True`"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Pass the same chat template kwargs as used in tokenization
|
||||||
|
chat_template_kwargs = self._prepare_extra_chat_template_kwargs(
|
||||||
|
request.chat_template_kwargs,
|
||||||
|
self.default_chat_template_kwargs,
|
||||||
|
)
|
||||||
reasoning_parser = self.reasoning_parser(
|
reasoning_parser = self.reasoning_parser(
|
||||||
tokenizer,
|
tokenizer,
|
||||||
chat_template_kwargs=request.chat_template_kwargs, # type: ignore
|
chat_template_kwargs=chat_template_kwargs, # type: ignore[call-arg]
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
logger.exception("Error in reasoning parser creation.")
|
logger.exception("Error in reasoning parser creation.")
|
||||||
|
|||||||
@@ -1146,6 +1146,18 @@ class OpenAIServing:
|
|||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _prepare_extra_chat_template_kwargs(
|
||||||
|
request_chat_template_kwargs: dict[str, Any] | None = None,
|
||||||
|
default_chat_template_kwargs: dict[str, Any] | None = None,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Helper to merge server-default and request-specific chat template kwargs."""
|
||||||
|
request_chat_template_kwargs = request_chat_template_kwargs or {}
|
||||||
|
if default_chat_template_kwargs is None:
|
||||||
|
return request_chat_template_kwargs
|
||||||
|
# Apply server defaults first, then request kwargs override.
|
||||||
|
return default_chat_template_kwargs | request_chat_template_kwargs
|
||||||
|
|
||||||
async def _preprocess_chat(
|
async def _preprocess_chat(
|
||||||
self,
|
self,
|
||||||
request: ChatLikeRequest | ResponsesRequest,
|
request: ChatLikeRequest | ResponsesRequest,
|
||||||
@@ -1184,9 +1196,10 @@ class OpenAIServing:
|
|||||||
tools=tool_dicts,
|
tools=tool_dicts,
|
||||||
documents=documents,
|
documents=documents,
|
||||||
)
|
)
|
||||||
if default_chat_template_kwargs:
|
_chat_template_kwargs |= self._prepare_extra_chat_template_kwargs(
|
||||||
_chat_template_kwargs.update(default_chat_template_kwargs)
|
chat_template_kwargs,
|
||||||
_chat_template_kwargs.update(chat_template_kwargs or {})
|
default_chat_template_kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
request_prompt: str | list[int]
|
request_prompt: str | list[int]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user