mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 23:29:21 +00:00
openai[patch]: default temp=1 for o1 (#27206)
This commit is contained in:
parent
b298d0337e
commit
ce33c4fa40
@ -480,6 +480,15 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
values = _build_model_kwargs(values, all_required_field_names)
|
values = _build_model_kwargs(values, all_required_field_names)
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
@model_validator(mode="before")
|
||||||
|
@classmethod
|
||||||
|
def validate_temperature(cls, values: Dict[str, Any]) -> Any:
|
||||||
|
"""Currently o1 models only allow temperature=1."""
|
||||||
|
model = values.get("model_name") or values.get("model") or ""
|
||||||
|
if model.startswith("o1") and "temperature" not in values:
|
||||||
|
values["temperature"] = 1
|
||||||
|
return values
|
||||||
|
|
||||||
@model_validator(mode="after")
|
@model_validator(mode="after")
|
||||||
def validate_environment(self) -> Self:
|
def validate_environment(self) -> Self:
|
||||||
"""Validate that api key and python package exists in environment."""
|
"""Validate that api key and python package exists in environment."""
|
||||||
|
@ -35,6 +35,13 @@ def test_openai_model_param() -> None:
|
|||||||
assert llm.model_name == "foo"
|
assert llm.model_name == "foo"
|
||||||
|
|
||||||
|
|
||||||
|
def test_openai_o1_temperature() -> None:
|
||||||
|
llm = ChatOpenAI(model="o1-preview")
|
||||||
|
assert llm.temperature == 1
|
||||||
|
llm = ChatOpenAI(model_name="o1-mini") # type: ignore[call-arg]
|
||||||
|
assert llm.temperature == 1
|
||||||
|
|
||||||
|
|
||||||
def test_function_message_dict_to_function_message() -> None:
|
def test_function_message_dict_to_function_message() -> None:
|
||||||
content = json.dumps({"result": "Example #1"})
|
content = json.dumps({"result": "Example #1"})
|
||||||
name = "test_function"
|
name = "test_function"
|
||||||
|
Loading…
Reference in New Issue
Block a user