mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
fix(openai): validate logprobs/top_p against reasoning_effort for gpt-5.1/5.2
logprobs, top_p, top_logprobs are only accepted by OpenAI when reasoning_effort="none". Add validation matching the existing temperature logic: raise UnsupportedParamsError or drop when reasoning_effort is set to other values.
This commit is contained in:
parent
5c4c085353
commit
a185182086
2 changed files with 54 additions and 0 deletions
|
|
@ -124,6 +124,24 @@ class OpenAIGPT5Config(OpenAIGPTConfig):
|
|||
"max_tokens"
|
||||
)
|
||||
|
||||
# gpt-5.1/5.2 support logprobs, top_p, top_logprobs only when reasoning_effort="none"
|
||||
if self.is_model_gpt_5_1_model(model):
|
||||
sampling_params = ["logprobs", "top_logprobs", "top_p"]
|
||||
has_sampling = any(p in non_default_params for p in sampling_params)
|
||||
if has_sampling and reasoning_effort not in (None, "none"):
|
||||
if litellm.drop_params or drop_params:
|
||||
for p in sampling_params:
|
||||
non_default_params.pop(p, None)
|
||||
else:
|
||||
raise litellm.utils.UnsupportedParamsError(
|
||||
message=(
|
||||
"gpt-5.1/5.2 only support logprobs, top_p, top_logprobs when "
|
||||
"reasoning_effort='none'. Current reasoning_effort='{}'. "
|
||||
"To drop unsupported params set `litellm.drop_params = True`"
|
||||
).format(reasoning_effort),
|
||||
status_code=400,
|
||||
)
|
||||
|
||||
if "temperature" in non_default_params:
|
||||
temperature_value: Optional[float] = non_default_params.pop("temperature")
|
||||
if temperature_value is not None:
|
||||
|
|
|
|||
|
|
@ -473,3 +473,39 @@ def test_gpt5_1_top_p_passthrough(config: OpenAIConfig):
|
|||
drop_params=False,
|
||||
)
|
||||
assert params["top_p"] == 0.9
|
||||
|
||||
|
||||
def test_gpt5_1_logprobs_rejected_with_reasoning_effort(config: OpenAIConfig):
|
||||
"""logprobs/top_p/top_logprobs are rejected when reasoning_effort != 'none'."""
|
||||
for effort in ["low", "medium", "high"]:
|
||||
with pytest.raises(litellm.utils.UnsupportedParamsError):
|
||||
config.map_openai_params(
|
||||
non_default_params={"logprobs": True, "reasoning_effort": effort},
|
||||
optional_params={},
|
||||
model="gpt-5.1",
|
||||
drop_params=False,
|
||||
)
|
||||
|
||||
|
||||
def test_gpt5_1_top_p_rejected_with_reasoning_effort(config: OpenAIConfig):
|
||||
"""top_p is rejected when reasoning_effort != 'none'."""
|
||||
with pytest.raises(litellm.utils.UnsupportedParamsError):
|
||||
config.map_openai_params(
|
||||
non_default_params={"top_p": 0.9, "reasoning_effort": "high"},
|
||||
optional_params={},
|
||||
model="gpt-5.1",
|
||||
drop_params=False,
|
||||
)
|
||||
|
||||
|
||||
def test_gpt5_1_logprobs_dropped_with_reasoning_effort(config: OpenAIConfig):
|
||||
"""logprobs/top_p are dropped when reasoning_effort != 'none' and drop_params=True."""
|
||||
params = config.map_openai_params(
|
||||
non_default_params={"logprobs": True, "top_p": 0.9, "reasoning_effort": "high"},
|
||||
optional_params={},
|
||||
model="gpt-5.1",
|
||||
drop_params=True,
|
||||
)
|
||||
assert "logprobs" not in params
|
||||
assert "top_p" not in params
|
||||
assert params["reasoning_effort"] == "high"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue