refactor: Separate raw thinking token retrieval and fix self access

This commit is contained in:
Paul Gauthier 2025-03-28 20:09:01 -10:00 committed by Paul Gauthier (aider)
parent a4c9c10029
commit 96aa77288b

View file

@ -688,11 +688,11 @@ class Model(ModelSettings):
else: else:
self.extra_params["thinking"] = {"type": "enabled", "budget_tokens": num_tokens} self.extra_params["thinking"] = {"type": "enabled", "budget_tokens": num_tokens}
def get_thinking_tokens(self, model): def get_raw_thinking_tokens(self):
"""Get formatted thinking token budget if available""" """Get formatted thinking token budget if available"""
budget = None budget = None
if model.extra_params: if self.extra_params:
# Check for OpenRouter reasoning format # Check for OpenRouter reasoning format
if ( if (
"reasoning" in model.extra_params "reasoning" in model.extra_params
@ -706,6 +706,11 @@ class Model(ModelSettings):
): ):
budget = model.extra_params["thinking"]["budget_tokens"] budget = model.extra_params["thinking"]["budget_tokens"]
return budget
def get_thinking_tokens(self):
budget = self.get_raw_thinking_tokens()
if budget is not None: if budget is not None:
# Format as xx.yK for thousands, xx.yM for millions # Format as xx.yK for thousands, xx.yM for millions
if budget >= 1024 * 1024: if budget >= 1024 * 1024: