Skip to content

Support default chat template kwargs#1363

Open
sufubao wants to merge 1 commit into
ModelTC:mainfrom
sufubao:preserve_thinking
Open

Support default chat template kwargs#1363
sufubao wants to merge 1 commit into
ModelTC:mainfrom
sufubao:preserve_thinking

Conversation

@sufubao

@sufubao sufubao commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new CLI argument --default_chat_template_kwargs to specify default JSON keyword arguments for the chat template tokenizer, which are merged with request-specific arguments when building prompts and determining reasoning modes. Unit tests are also added to verify this functionality. The reviewer suggests making the get_effective_chat_template_kwargs helper function more robust by defensively checking types and using getattr on the request object to prevent potential runtime errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +130 to +137
def get_effective_chat_template_kwargs(request) -> dict:
kwargs = {}
default_kwargs = getattr(get_env_start_args(), "default_chat_template_kwargs", None)
if default_kwargs:
kwargs.update(default_kwargs)
if request.chat_template_kwargs:
kwargs.update(request.chat_template_kwargs)
return kwargs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential runtime errors (such as AttributeError or TypeError), it is safer to defensively check that default_chat_template_kwargs and request.chat_template_kwargs are indeed dictionaries before calling .update(). Additionally, using getattr on request ensures compatibility if a request object without the chat_template_kwargs attribute is passed (e.g., in certain testing scenarios or alternative request flows).

Suggested change
def get_effective_chat_template_kwargs(request) -> dict:
kwargs = {}
default_kwargs = getattr(get_env_start_args(), "default_chat_template_kwargs", None)
if default_kwargs:
kwargs.update(default_kwargs)
if request.chat_template_kwargs:
kwargs.update(request.chat_template_kwargs)
return kwargs
def get_effective_chat_template_kwargs(request) -> dict:
kwargs = {}
default_kwargs = getattr(get_env_start_args(), "default_chat_template_kwargs", None)
if isinstance(default_kwargs, dict):
kwargs.update(default_kwargs)
req_kwargs = getattr(request, "chat_template_kwargs", None)
if isinstance(req_kwargs, dict):
kwargs.update(req_kwargs)
return kwargs

@sufubao sufubao force-pushed the preserve_thinking branch from 8963ad5 to cce09d1 Compare June 18, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant