From 9c4b6dc979ed185efce9bd8f4d9a7be09df69ad8 Mon Sep 17 00:00:00 2001 From: kaijietti <43436010+kaijietti@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:34:46 +0800 Subject: [PATCH] community[patch]: fix bug in cohere that `async for` a coroutine in ChatCohere (#19381) Without `await`, the `stream` returned from the `async_client` is actually a coroutine, which could not be used in `async for`. --- libs/community/langchain_community/chat_models/cohere.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/community/langchain_community/chat_models/cohere.py b/libs/community/langchain_community/chat_models/cohere.py index 07718c7f799..2ea44328a71 100644 --- a/libs/community/langchain_community/chat_models/cohere.py +++ b/libs/community/langchain_community/chat_models/cohere.py @@ -172,9 +172,9 @@ class ChatCohere(BaseChatModel, BaseCohere): request = get_cohere_chat_request(messages, **self._default_params, **kwargs) if hasattr(self.async_client, "chat_stream"): # detect and support sdk v5 - stream = self.async_client.chat_stream(**request) + stream = await self.async_client.chat_stream(**request) else: - stream = self.async_client.chat(**request, stream=True) + stream = await self.async_client.chat(**request, stream=True) async for data in stream: if data.event_type == "text-generation":