Find answers from the community

Updated 3 months ago

Hello,

Hello,
Is anyone getting this type error when using mistral API for async streaming ?

TypeError: object async_generator can't be used in 'await' expression
L
T
7 comments
full traceback?
{
  "name": "TypeError",
  "message": "object async_generator can't be used in 'await' expression",
  "stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[13], line 4
      1 from llama_index.core.llms import ChatMessage, MessageRole
      3 message = ChatMessage(role=MessageRole.USER, content="Tell me a joke.")
----> 4 resp = await llm_c.astream_chat([message])
      5 async for r in resp:
      6     print(r.delta, end="")
 
File c:\Users\\anaconda3\envs\llama\lib\site-packages\llama_index\core\llms\callbacks.py:71, in llm_chat_callback.<locals>.wrap.<locals>.wrapped_async_llm_chat(_self, messages, kwargs)     54 dispatcher.event(     55     LLMChatStartEvent(     56         model_dict=_self.to_dict(),   (...)     60     )     61 )     62 event_id = callback_manager.on_event_start(     63     CBEventType.LLM,     64     payload={   (...)     68     },     69 )---> 71 f_return_val = await f(_self, messages, kwargs)
     72 if isinstance(f_return_val, AsyncGenerator):
     73     # intercept the generator and add a callback to the end
     74     async def wrapped_gen() -> ChatResponseAsyncGen:
 
File c:\Users\\anaconda3\envs\llama\lib\site-packages\llama_index\llms\mistralai\base.py:327, in MistralAI.astream_chat(self, messages, kwargs)    324 messages = to_mistral_chatmessage(messages)    325 all_kwargs = self._get_all_kwargs(kwargs)
--> 327 response = await self._aclient.chat_stream(messages=messages, **all_kwargs)
    329 async def gen() -> ChatResponseAsyncGen:
    330     content = ""
 
TypeError: object async_generator can't be used in 'await' expression"
}
ah, seems like a small bug I suppose, the method itself isn't async but it returns an async generator
Oh right I see, do you want me to do a PR to fix it or create an issue on GitHub ?
If you have time to make a PR, that would be great! Should be an easy change to make I think
Ill see what I can do
Thanks 😊
@Logan M found it,
Waiting for the review now but it’s not the biggest or you’ll see
Add a reply
Sign up and join the conversation on Discord