mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
fix(core,openai,anthropic): delegate to core implementation on invoke when streaming=True (#33308)
This commit is contained in:
@@ -38,8 +38,6 @@ from langchain_core.language_models import LanguageModelInput
|
||||
from langchain_core.language_models.chat_models import (
|
||||
BaseChatModel,
|
||||
LangSmithParams,
|
||||
agenerate_from_stream,
|
||||
generate_from_stream,
|
||||
)
|
||||
from langchain_core.messages import (
|
||||
AIMessage,
|
||||
@@ -1187,11 +1185,6 @@ class BaseChatOpenAI(BaseChatModel):
|
||||
run_manager: Optional[CallbackManagerForLLMRun] = None,
|
||||
**kwargs: Any,
|
||||
) -> ChatResult:
|
||||
if self.streaming:
|
||||
stream_iter = self._stream(
|
||||
messages, stop=stop, run_manager=run_manager, **kwargs
|
||||
)
|
||||
return generate_from_stream(stream_iter)
|
||||
payload = self._get_request_payload(messages, stop=stop, **kwargs)
|
||||
generation_info = None
|
||||
raw_response = None
|
||||
@@ -1432,11 +1425,6 @@ class BaseChatOpenAI(BaseChatModel):
|
||||
run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
|
||||
**kwargs: Any,
|
||||
) -> ChatResult:
|
||||
if self.streaming:
|
||||
stream_iter = self._astream(
|
||||
messages, stop=stop, run_manager=run_manager, **kwargs
|
||||
)
|
||||
return await agenerate_from_stream(stream_iter)
|
||||
payload = self._get_request_payload(messages, stop=stop, **kwargs)
|
||||
generation_info = None
|
||||
raw_response = None
|
||||
|
||||
@@ -89,6 +89,12 @@ def test_openai_model_param() -> None:
|
||||
assert llm.max_tokens == 10
|
||||
|
||||
|
||||
@pytest.mark.parametrize("async_api", [True, False])
|
||||
def test_streaming_attribute_should_stream(async_api: bool) -> None:
|
||||
llm = ChatOpenAI(model="foo", streaming=True)
|
||||
assert llm._should_stream(async_api=async_api)
|
||||
|
||||
|
||||
def test_openai_client_caching() -> None:
|
||||
"""Test that the OpenAI client is cached."""
|
||||
llm1 = ChatOpenAI(model="gpt-4.1-mini")
|
||||
|
||||
Reference in New Issue
Block a user