Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Mistral Client: TypeError: 'async for' requires an object with __aiter__ method, got coroutine #1968

Closed
galaxygliese opened this issue Feb 1, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@galaxygliese
Copy link

Hello, I got the error while I was using Mistral AI client in app.agno.com.

Description

Running the Mistral client as is works fine, but running ti from app.agno.com is causing the error.
I tried OpenAI client version, it worked.

Steps to Reproduce

List the steps needed to encounter this bug or issue.

Agent Configuration (if applicable)

Mistral AI model code:

def get_mistral_model():
    mistral_api_key = os.getenv("MISTRAL_API_KEY")
    client = Mistral(
        api_key=mistral_api_key,
    )
    model = MistralChat(
        id="mistral-large-latest",
        mistral_client=client,
        api_key=mistral_api_key,
        temperature=0.0,
    )
    return model 

Agent code:

agent = Agent(
        name="assistant agent",
        user_id=user_id,
        model=get_mistral_model(),
        ...
)

Actual Behavior

TypeError occured.

Screenshots or Logs (if applicable)

    | Traceback (most recent call last):
    |   File "/home/galaxygliese/.local/lib/python3.10/site-packages/starlette/responses.py", line 260, in wrap
    |     await func()
    |   File "/home/galaxygliese/.local/lib/python3.10/site-packages/starlette/responses.py", line 249, in stream_response
    |     async for chunk in self.body_iterator:
    |   File "/home/galaxygliese/.local/lib/python3.10/site-packages/agno/playground/async_router.py", line 110, in chat_response_streamer
    |     async for run_response_chunk in run_response:
    |   File "/home/galaxygliese/.local/lib/python3.10/site-packages/agno/agent/agent.py", line 968, in _arun
    |     async for model_response_chunk in model_response_stream:  # type: ignore
    | TypeError: 'async for' requires an object with __aiter__ method, got coroutine

Environment

  • OS: Ubuntu 22
  • Browser (if relevant): Chrome
  • Agno Version: agno==1.0.1
  • External Dependency Versions: mistralai==1.5.0
  • Additional Environment Details: Python 3.10

Possible Solutions (optional)

I think the error may be in async client. The openai version client is shown below:

from openai import AsyncOpenAI as AsyncOpenAIClient
from openai import OpenAI
from agno.models.openai import OpenAIChat 

def get_openai_model()-> OpenAIChat :
    API_KEY = os.environ.get("OPENAI_API_KEY")
    return OpenAIChat(
        id="gpt-4o-mini",
        client=OpenAI(
            api_key=API_KEY,
        ),
        async_client=AsyncOpenAIClient(
            api_key=API_KEY,
        ),
        temperature=0.0,
    )

Additional Context

Add any other context or details about the problem here.

@galaxygliese galaxygliese added the bug Something isn't working label Feb 1, 2025
@ashpreetbedi
Copy link
Contributor

ashpreetbedi commented Feb 1, 2025

Thanks @galaxygliese, looking into this!

@manthanguptaa
Copy link
Contributor

Hey @galaxygliese! Mistral right now doesn't support async capabilities which is causing this issue. Are you by any chance trying to use the playground with Mistral model?

@galaxygliese
Copy link
Author

Hi @manthanguptaa! Thank you for your message. Now, I'm trying another model on the playground. No worries! openai-based models are working.

@manthanguptaa
Copy link
Contributor

@galaxygliese we now support async with Mistral in our latest release. Please update agno using pip install -U agno and your code should now start working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants