Fix GPT-5 models to respect reasoning_effort config setting

Previously, GPT-5 models had reasoning_effort hardcoded to 'minimal',
which caused two issues:
1. 'minimal' is not supported by some models (e.g., gpt-5.1-codex)
2. User's config.reasoning_effort setting was completely ignored

This fix:
- Reads and respects user's reasoning_effort config value
- Uses valid defaults: 'none' for non-thinking models, 'low' for thinking
- Adds logging to show which value is being used

Fixes #2120
This commit is contained in:
Tyler Zhang 2025-12-06 18:41:10 +08:00
parent ede3f82143
commit eb2f432e16

View file

@ -292,16 +292,25 @@ class LiteLLMAIHandler(BaseAiHandler):
thinking_kwargs_gpt5 = None thinking_kwargs_gpt5 = None
if model.startswith('gpt-5'): if model.startswith('gpt-5'):
# Respect user's reasoning_effort config setting
# Supported values: 'none', 'low', 'medium', 'high'
# Note: gpt-5.1 supports 'none', but gpt-5.1-codex does not
config_effort = get_settings().config.reasoning_effort
supported_efforts = ['none', 'low', 'medium', 'high']
if model.endswith('_thinking'): if model.endswith('_thinking'):
thinking_kwargs_gpt5 = { # For thinking models, use config value or default to 'low'
"reasoning_effort": 'low', effort = config_effort if config_effort in supported_efforts else 'low'
"allowed_openai_params": ["reasoning_effort"],
}
else: else:
# For non-thinking models, use config value or default to 'none'
# If 'none' fails for specific models (e.g., codex), they should set config to 'low'
effort = config_effort if config_effort in supported_efforts else 'none'
thinking_kwargs_gpt5 = { thinking_kwargs_gpt5 = {
"reasoning_effort": 'minimal', "reasoning_effort": effort,
"allowed_openai_params": ["reasoning_effort"], "allowed_openai_params": ["reasoning_effort"],
} }
get_logger().info(f"Using reasoning_effort={effort} for GPT-5 model (from {'config' if config_effort in supported_efforts else 'default'})")
model = 'openai/'+model.replace('_thinking', '') # remove _thinking suffix model = 'openai/'+model.replace('_thinking', '') # remove _thinking suffix