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`.
This commit is contained in:
kaijietti 2024-03-28 12:34:46 +08:00 committed by GitHub
parent 1adaa3c662
commit 9c4b6dc979
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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":