Skip to content

Commit c92bdb9

Browse files
committed
feat: Remember thinking config when toggling
This commit introduces a feature to remember the previous thinking configuration (budget_tokens) when toggling it on/off. This way, when thinking is enabled again, it restores the previous settings instead of always defaulting to 1024 tokens. A property is used to temporarily save/load the old configuration.
1 parent 417832f commit c92bdb9

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

lua/parrot/provider/anthropic.lua

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,31 @@ function Anthropic:configure_thinking(params, is_chat, providers, state)
263263

264264
if current then
265265
-- Thinking is enabled, disable it
266-
providers[self.name].params[mode].thinking = nil
267-
268-
-- Save to state if provided
266+
-- Store the current config before disabling for future restoration
269267
if state then
268+
-- Save the current state temporarily (it's already in state storage)
269+
providers[self.name].params[mode]._stored_thinking = vim.deepcopy(current)
270270
state:set_thinking(self.name, mode, nil)
271271
end
272272

273+
providers[self.name].params[mode].thinking = nil
273274
logger.info("Disabled thinking for " .. mode)
274275
else
275-
-- Thinking is disabled, enable it with default budget
276-
local thinking_config = {
277-
type = "enabled",
278-
budget_tokens = 1024
279-
}
276+
-- Thinking is disabled, enable it with previous budget if available
277+
local stored_config = providers[self.name].params[mode]._stored_thinking
278+
local thinking_config
279+
280+
if stored_config then
281+
-- Restore previous configuration
282+
thinking_config = vim.deepcopy(stored_config)
283+
providers[self.name].params[mode]._stored_thinking = nil
284+
else
285+
-- Use default if no previous configuration exists
286+
thinking_config = {
287+
type = "enabled",
288+
budget_tokens = 1024
289+
}
290+
end
280291

281292
providers[self.name].params[mode].thinking = thinking_config
282293

@@ -285,8 +296,8 @@ function Anthropic:configure_thinking(params, is_chat, providers, state)
285296
state:set_thinking(self.name, mode, thinking_config)
286297
end
287298

288-
logger.info(string.format("Enabled thinking with default budget of 1024 tokens for %s",
289-
mode))
299+
logger.info(string.format("Enabled thinking with budget of %d tokens for %s",
300+
thinking_config.budget_tokens, mode))
290301
end
291302
end
292303
end

0 commit comments

Comments
 (0)