DocUA commited on
Commit
09efcd1
·
1 Parent(s): 085df7b

Fix Anthropic thinking mode configuration logic

Browse files
Files changed (1) hide show
  1. main.py +23 -10
main.py CHANGED
@@ -995,17 +995,30 @@ def generate_legal_position(
995
 
996
  # Add thinking config if enabled
997
  if thinking_enabled and "claude" in model_name.lower():
998
- # For Claude 4.6 models, we can use Adaptive
999
- if thinking_type.lower() == "adaptive" and getattr(model_name, "find", lambda x: -1)("-4-6") != -1:
1000
- message_params["thinking"] = {"type": "adaptive"}
1001
- message_params["temperature"] = 1.0
1002
  else:
1003
- # 'Enabled' type works for both 4.5 and 4.6 models
1004
- message_params["thinking"] = {
1005
- "type": "enabled",
1006
- "budget_tokens": max(1024, int(thinking_budget))
1007
- }
1008
- message_params["temperature"] = 1.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1009
 
1010
  # Log full prompts in debug mode
1011
  _log_prompt("anthropic", model_name, system_prompt, content)
 
995
 
996
  # Add thinking config if enabled
997
  if thinking_enabled and "claude" in model_name.lower():
998
+ # Claude Haiku typically does not support thinking mode
999
+ if "haiku" in model_name.lower():
1000
+ print(f"[WARNING] Thinking mode is not supported for Haiku models. Disabling thinking for {model_name}.")
 
1001
  else:
1002
+ # For Claude 4.6 models, we can use Adaptive
1003
+ if thinking_type.lower() == "adaptive" and "-4-6" in str(model_name).lower():
1004
+ message_params["thinking"] = {"type": "adaptive"}
1005
+ message_params["temperature"] = 1.0
1006
+ else:
1007
+ # 'Enabled' type works for both 4.5 and 4.6 models
1008
+ budget = max(1024, int(thinking_budget))
1009
+
1010
+ # Anthropic REQUIRES max_tokens > budget_tokens.
1011
+ # If the user sets a low max_tokens (e.g. 4000) and high budget (10000), it will fail.
1012
+ if message_params["max_tokens"] <= budget:
1013
+ recommended_max = budget + 4000
1014
+ print(f"[WARNING] max_tokens ({message_params['max_tokens']}) is <= thinking_budget ({budget}). Increasing max_tokens to {recommended_max}.")
1015
+ message_params["max_tokens"] = recommended_max
1016
+
1017
+ message_params["thinking"] = {
1018
+ "type": "enabled",
1019
+ "budget_tokens": budget
1020
+ }
1021
+ message_params["temperature"] = 1.0
1022
 
1023
  # Log full prompts in debug mode
1024
  _log_prompt("anthropic", model_name, system_prompt, content)