mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-13 13:36:15 +00:00
fix(openai): allow temperature parameter for gpt-5-chat models (#32624)
This commit is contained in:
@@ -716,7 +716,8 @@ class BaseChatOpenAI(BaseChatModel):
|
||||
"""Validate temperature parameter for different models.
|
||||
|
||||
- o1 models only allow temperature=1
|
||||
- gpt-5 models only allow temperature=1 or unset (defaults to 1)
|
||||
- gpt-5 models (excluding gpt-5-chat) only allow temperature=1 or unset
|
||||
(defaults to 1)
|
||||
"""
|
||||
model = values.get("model_name") or values.get("model") or ""
|
||||
|
||||
@@ -725,10 +726,12 @@ class BaseChatOpenAI(BaseChatModel):
|
||||
values["temperature"] = 1
|
||||
|
||||
# For gpt-5 models, handle temperature restrictions
|
||||
if model.startswith("gpt-5"):
|
||||
# Note that gpt-5-chat models do support temperature
|
||||
if model.startswith("gpt-5") and "chat" not in model:
|
||||
temperature = values.get("temperature")
|
||||
if temperature is not None and temperature != 1:
|
||||
# For gpt-5, only temperature=1 is supported, so remove non-defaults
|
||||
# For gpt-5 (non-chat), only temperature=1 is supported
|
||||
# So we remove any non-defaults
|
||||
values.pop("temperature", None)
|
||||
|
||||
return values
|
||||
@@ -3520,7 +3523,7 @@ def _construct_responses_api_payload(
|
||||
|
||||
# Remove temperature parameter for models that don't support it in responses API
|
||||
model = payload.get("model", "")
|
||||
if model.startswith("gpt-5"):
|
||||
if model.startswith("gpt-5") and "chat" not in model: # gpt-5-chat supports
|
||||
payload.pop("temperature", None)
|
||||
|
||||
payload["input"] = _construct_responses_api_input(messages)
|
||||
|
Reference in New Issue
Block a user