feat: cmd_enable_thinking

Adds a command which can be used to enable or disable reasoning by
supported models (Qwen3). This is more robust than using the /no_think
prompt and saves a small number of tokens.
This commit is contained in:
randoentity 2025-05-08 22:24:46 +02:00
parent 56b45ce1d3
commit 8010bebb6b
3 changed files with 49 additions and 0 deletions

View file

@ -145,6 +145,14 @@ def get_parser(default_config_files, git_root):
type=str,
help="Set the thinking token budget for models that support it (default: not set)",
)
group.add_argument(
"--enable-thinking",
type=str,
help=(
"Switches between thinking and non-thinking modes for models that support it."
" (default: not set)"
),
)
group.add_argument(
"--verify-ssl",
action=argparse.BooleanOptionalAction,

View file

@ -1588,6 +1588,28 @@ class Commands:
announcements = "\n".join(self.coder.get_announcements())
self.io.tool_output(announcements)
def cmd_enable_thinking(self, args):
"""Enable or disable thinking for models that support it."""
model = self.coder.main_model
if not args.strip():
# Display current value if no args are provided
thinking_value = model.get_enable_thinking()
if thinking_value is None:
self.io.tool_output("thinking effort is not currently set.")
else:
self.io.tool_output(f"Current thinking setting: {thinking_value}")
return
value = args.strip()
model.set_enable_thinking(value)
thinking_value = model.get_enable_thinking()
self.io.tool_output(f"Set enable thinking to {thinking_value}")
self.io.tool_output()
# Output announcements
announcements = "\n".join(self.coder.get_announcements())
self.io.tool_output(announcements)
def cmd_copy_context(self, args=None):
"""Copy the current chat context as markdown, suitable to paste into a web UI"""

View file

@ -755,6 +755,15 @@ class Model(ModelSettings):
self.extra_params["extra_body"] = {}
self.extra_params["extra_body"]["reasoning_effort"] = effort
def set_enable_thinking(self, setting):
"""Set the enable thinking parameter for models that support it"""
if setting is not None:
if not self.extra_params:
self.extra_params = {}
if "extra_body" not in self.extra_params:
self.extra_params["extra_body"] = {}
self.extra_params["extra_body"]["enable_thinking"] = setting
def parse_token_value(self, value):
"""
Parse a token value string into an integer.
@ -864,6 +873,16 @@ class Model(ModelSettings):
return self.extra_params["extra_body"]["reasoning_effort"]
return None
def get_enable_thinking(self):
"""Get enable thinking value if available"""
if (
self.extra_params
and "extra_body" in self.extra_params
and "enable_thinking" in self.extra_params["extra_body"]
):
return self.extra_params["extra_body"]["enable_thinking"]
return None
def is_deepseek_r1(self):
name = self.name.lower()
if "deepseek" not in name: