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
新增
--default_chat_template_kwargs(别名--default-chat-template-kwargs),支持为所有聊天请求设置默认模板参数,例如--default-chat-template-kwargs '{"preserve_thinking": true}'。CLI 仅接受 JSON 对象,请求中的chat_template_kwargs按键覆盖服务默认值。默认参数会同步
thinking/enable_thinking别名,并由提示词构建和 reasoning parser 共用,避免思考模式不一致。reasoning_effort的优先级为:请求chat_template_kwargs> 请求顶层字段 > 服务默认值。已合入最新
main并解决冲突,保留当前启动参数默认值。验证:python -m pytest unit_tests/server/test_default_chat_template_kwargs.py unit_tests/server/test_reasoning_token_usage.py unit_tests/server/test_api_responses.py -q:56 passed;覆盖 JSON 校验、参数覆盖、输入不变性、思考别名及 reasoning_effort 优先级。git diff --check通过。