async def astream_call_with_messages(
    model: str,
    messages: List[Dict],
    parameters: Optional[Dict] = None,
    tools: Optional[List[Dict]] = None,
    api_key: Optional[str] = None,
    **kwargs: Any,
) -> AsyncGenerator[Any, None]:
    """Call DashScope in streaming mode, returning an async generator of partial responses."""
    try:
        from dashscope import AioGeneration
    except ImportError:
        raise ValueError(
            "DashScope is not installed. Please install it with "
            "`pip install dashscope`."
        )

    response = await AioGeneration.call(
        model=model, messages=messages, tools=tools, api_key=api_key, **parameters
    )
    if not hasattr(response, "__aiter__"):
        raise TypeError(
            f"AioGeneration.call() did not return an async iterable, got {type(response)}"
        )

    async for partial_response in response:
        yield partial_response
Call DashScope in streaming mode, returning an async generator of partial responses.
llama-index-integrations/llms/llama-index-llms-dashscope/llama_index/llms/dashscope/base.py