mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
This commit is contained in:
parent
a749598693
commit
0d0dae45db
2 changed files with 79 additions and 9 deletions
|
|
@ -36,15 +36,15 @@ class OpenAIGPT5Config(OpenAIGPTConfig):
|
|||
|
||||
@classmethod
|
||||
def is_model_gpt_5_1_model(cls, model: str) -> bool:
|
||||
"""Check if the model is a gpt-5.1 or gpt-5.2 chat variant.
|
||||
|
||||
"""Check if the model is a gpt-5.1 or gpt-5.2 reasoning variant.
|
||||
|
||||
gpt-5.1/5.2 support temperature when reasoning_effort="none",
|
||||
unlike base gpt-5 which only supports temperature=1. Excludes
|
||||
pro variants which keep stricter knobs.
|
||||
pro and chat variants which don't support flexible temperature.
|
||||
"""
|
||||
model_name = model.split("/")[-1]
|
||||
is_gpt_5_1 = model_name.startswith("gpt-5.1")
|
||||
is_gpt_5_2 = model_name.startswith("gpt-5.2") and "pro" not in model_name
|
||||
model_name = model.split("/")[-1] # handle provider prefixes
|
||||
is_gpt_5_1 = model_name.startswith("gpt-5.1") and "-chat" not in model_name
|
||||
is_gpt_5_2 = model_name.startswith("gpt-5.2") and "pro" not in model_name and "-chat" not in model_name
|
||||
return is_gpt_5_1 or is_gpt_5_2
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -260,14 +260,22 @@ def test_gpt5_drops_reasoning_effort_xhigh_when_requested(config: OpenAIConfig):
|
|||
|
||||
# GPT-5.1 temperature handling tests
|
||||
def test_gpt5_1_model_detection(gpt5_config: OpenAIGPT5Config):
|
||||
"""Test that GPT-5.1 models are correctly detected."""
|
||||
"""Test that GPT-5.1 models are correctly detected.
|
||||
|
||||
Chat variants (gpt-5.1-chat, gpt-5.2-chat-*) are excluded because they
|
||||
are regular chat models that don't support flexible temperature tied to
|
||||
reasoning_effort.
|
||||
Related: https://github.com/BerriAI/litellm/issues/21911
|
||||
"""
|
||||
assert gpt5_config.is_model_gpt_5_1_model("gpt-5.1")
|
||||
assert gpt5_config.is_model_gpt_5_1_model("gpt-5.1-codex")
|
||||
assert gpt5_config.is_model_gpt_5_1_model("gpt-5.1-codex-max")
|
||||
assert gpt5_config.is_model_gpt_5_1_model("gpt-5.1-chat")
|
||||
assert gpt5_config.is_model_gpt_5_1_model("gpt-5.2")
|
||||
assert gpt5_config.is_model_gpt_5_1_model("gpt-5.2-2025-12-11")
|
||||
assert gpt5_config.is_model_gpt_5_1_model("gpt-5.2-chat-latest")
|
||||
# Chat variants should NOT be detected as gpt-5.1-style reasoning models
|
||||
assert not gpt5_config.is_model_gpt_5_1_model("gpt-5.1-chat")
|
||||
assert not gpt5_config.is_model_gpt_5_1_model("gpt-5.2-chat-latest")
|
||||
assert not gpt5_config.is_model_gpt_5_1_model("gpt-5.2-chat")
|
||||
assert not gpt5_config.is_model_gpt_5_1_model("gpt-5.2-pro")
|
||||
assert not gpt5_config.is_model_gpt_5_1_model("gpt-5")
|
||||
assert not gpt5_config.is_model_gpt_5_1_model("gpt-5-mini")
|
||||
|
|
@ -414,3 +422,65 @@ def test_gpt5_2_allows_reasoning_effort_xhigh(config: OpenAIConfig):
|
|||
drop_params=False,
|
||||
)
|
||||
assert params["reasoning_effort"] == "xhigh"
|
||||
|
||||
|
||||
# GPT-5.2-chat temperature drop tests
|
||||
# Related issue: https://github.com/BerriAI/litellm/issues/21911
|
||||
def test_gpt5_2_chat_temperature_drop(config: OpenAIConfig):
|
||||
"""Test that gpt-5.2-chat drops unsupported temperature with drop_params=True.
|
||||
|
||||
gpt-5.2-chat is a chat model, not a reasoning model. It should not get
|
||||
the flexible temperature handling that reasoning models (gpt-5.1, gpt-5.2)
|
||||
receive when reasoning_effort='none'.
|
||||
"""
|
||||
params = config.map_openai_params(
|
||||
non_default_params={"temperature": 0.5},
|
||||
optional_params={},
|
||||
model="gpt-5.2-chat",
|
||||
drop_params=True,
|
||||
)
|
||||
assert "temperature" not in params
|
||||
|
||||
|
||||
def test_gpt5_2_chat_latest_temperature_drop(config: OpenAIConfig):
|
||||
"""Test that gpt-5.2-chat-latest also drops unsupported temperature."""
|
||||
params = config.map_openai_params(
|
||||
non_default_params={"temperature": 0.7},
|
||||
optional_params={},
|
||||
model="gpt-5.2-chat-latest",
|
||||
drop_params=True,
|
||||
)
|
||||
assert "temperature" not in params
|
||||
|
||||
|
||||
def test_gpt5_2_chat_temperature_error(config: OpenAIConfig):
|
||||
"""Test that gpt-5.2-chat raises error for unsupported temperature when drop_params=False."""
|
||||
with pytest.raises(litellm.utils.UnsupportedParamsError):
|
||||
config.map_openai_params(
|
||||
non_default_params={"temperature": 0.5},
|
||||
optional_params={},
|
||||
model="gpt-5.2-chat-latest",
|
||||
drop_params=False,
|
||||
)
|
||||
|
||||
|
||||
def test_gpt5_2_chat_temperature_one_allowed(config: OpenAIConfig):
|
||||
"""Test that gpt-5.2-chat still allows temperature=1."""
|
||||
params = config.map_openai_params(
|
||||
non_default_params={"temperature": 1.0},
|
||||
optional_params={},
|
||||
model="gpt-5.2-chat-latest",
|
||||
drop_params=False,
|
||||
)
|
||||
assert params["temperature"] == 1.0
|
||||
|
||||
|
||||
def test_gpt5_2_base_still_allows_temperature(config: OpenAIConfig):
|
||||
"""Test that gpt-5.2 (reasoning model) still allows temperature when reasoning_effort is None."""
|
||||
params = config.map_openai_params(
|
||||
non_default_params={"temperature": 0.5},
|
||||
optional_params={},
|
||||
model="gpt-5.2",
|
||||
drop_params=False,
|
||||
)
|
||||
assert params["temperature"] == 0.5
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue