mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
openai[patch]: enable streaming for o1 (#29823)
Verified streaming works for the `o1-2024-12-17` snapshot as well.
This commit is contained in:
parent
3dffee3d0b
commit
65a6dce428
@ -511,15 +511,6 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
values["temperature"] = 1
|
values["temperature"] = 1
|
||||||
return values
|
return values
|
||||||
|
|
||||||
@model_validator(mode="before")
|
|
||||||
@classmethod
|
|
||||||
def validate_disable_streaming(cls, values: Dict[str, Any]) -> Any:
|
|
||||||
"""Disable streaming if n > 1."""
|
|
||||||
model = values.get("model_name") or values.get("model") or ""
|
|
||||||
if model == "o1" and values.get("disable_streaming") is None:
|
|
||||||
values["disable_streaming"] = True
|
|
||||||
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."""
|
||||||
|
@ -1188,16 +1188,6 @@ def test_o1(use_max_completion_tokens: bool) -> None:
|
|||||||
assert response.content.upper() == response.content
|
assert response.content.upper() == response.content
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.scheduled
|
|
||||||
def test_o1_doesnt_stream() -> None:
|
|
||||||
"""
|
|
||||||
When this starts failing, remove the `disable_streaming` validator in
|
|
||||||
`BaseChatOpenAI`
|
|
||||||
"""
|
|
||||||
with pytest.raises(openai.BadRequestError):
|
|
||||||
list(ChatOpenAI(model="o1", disable_streaming=False).stream("how are you"))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.scheduled
|
@pytest.mark.scheduled
|
||||||
def test_o1_stream_default_works() -> None:
|
def test_o1_stream_default_works() -> None:
|
||||||
result = list(ChatOpenAI(model="o1").stream("say 'hi'"))
|
result = list(ChatOpenAI(model="o1").stream("say 'hi'"))
|
||||||
|
Loading…
Reference in New Issue
Block a user