Skip to content

Compatible with both thinking and enable_thinking.#1260

Merged
hiworldwzj merged 2 commits intomainfrom
WANDY666-patch-2
Apr 7, 2026
Merged

Compatible with both thinking and enable_thinking.#1260
hiworldwzj merged 2 commits intomainfrom
WANDY666-patch-2

Conversation

@WANDY666
Copy link
Copy Markdown
Contributor

@WANDY666 WANDY666 commented Apr 7, 2026

No description provided.

Add model validator to synchronize thinking and enable_thinking in chat_template_kwargs.
Copy link
Copy Markdown
Contributor

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

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 model validator to synchronize the 'thinking' and 'enable_thinking' keys within 'chat_template_kwargs', ensuring compatibility across different chat templates like Qwen and DeepSeek. Feedback suggests optimizing the implementation by modifying the dictionary in place to avoid unnecessary allocations and re-assignments.

Comment on lines +274 to +279
d = dict(self.chat_template_kwargs)
if "thinking" not in d and "enable_thinking" in d:
d["thinking"] = d["enable_thinking"]
elif "enable_thinking" not in d and "thinking" in d:
d["enable_thinking"] = d["thinking"]
self.chat_template_kwargs = d
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

The current implementation creates a shallow copy of the dictionary and re-assigns it to the field even when no changes are necessary. Since chat_template_kwargs is a mutable dictionary, you can modify it in place to avoid unnecessary allocations and re-assignments. This improves efficiency, especially for requests where these specific keys are not present or both are already set.

Suggested change
d = dict(self.chat_template_kwargs)
if "thinking" not in d and "enable_thinking" in d:
d["thinking"] = d["enable_thinking"]
elif "enable_thinking" not in d and "thinking" in d:
d["enable_thinking"] = d["thinking"]
self.chat_template_kwargs = d
if "thinking" not in self.chat_template_kwargs and "enable_thinking" in self.chat_template_kwargs:
self.chat_template_kwargs["thinking"] = self.chat_template_kwargs["enable_thinking"]
elif "enable_thinking" not in self.chat_template_kwargs and "thinking" in self.chat_template_kwargs:
self.chat_template_kwargs["enable_thinking"] = self.chat_template_kwargs["thinking"]

@hiworldwzj hiworldwzj merged commit 8aea9a2 into main Apr 7, 2026
1 check passed
@hiworldwzj hiworldwzj deleted the WANDY666-patch-2 branch April 7, 2026 07:06
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.

2 participants