Support default chat template kwargs#1363
Conversation
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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).
| 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 |
8963ad5 to
cce09d1
Compare
No description provided.