async def test_astream_chat_with_tools(monkeypatch, dashscope_llm):
    """
    Test astream_chat method: when the tools parameter is passed,
    astream_call_with_messages should receive this parameter,
    and the additional_kwargs of the returned ChatResponse should contain the correct tool_calls.
    """

    async def fake_async_responses(*args, **kwargs) -> AsyncGenerator:
        expected_tools = [{"dummy": "tool_spec"}]
        assert kwargs.get("tools") == expected_tools, (
            "tools parameter is not passed correctly"
        )

        class FakeOutput:
            def __init__(self) -> None:
                self.choices = [
                    {
                        "message": {
                            "role": "assistant",
                            "content": "Hello, this is a test.",
                            "tool_calls": [
                                {
                                    "index": 0,
                                    "id": "dummy_tool_call_id",
                                    "type": "function",
                                    "function": {
                                        "name": "dummy_tool",
                                        "arguments": '{"param": "value"}',
                                    },
                                }
                            ],
                        }
                    }
                ]

        class FakeResponse:
            def __init__(self) -> None:
                self.status_code = HTTPStatus.OK
                self.output = FakeOutput()

        yield FakeResponse()

    monkeypatch.setattr(
        "llama_index.llms.dashscope.base.astream_call_with_messages",
        fake_async_responses,
    )

    messages = [ChatMessage(role="user", content="Test message")]
    dummy_tools = [{"dummy": "tool_spec"}]

    gen = await dashscope_llm.astream_chat(messages, tools=dummy_tools)
    responses = []
    async for response in gen:
        responses.append(response)

    assert len(responses) == 1
    response = responses[0]
    tool_calls = response.message.additional_kwargs.get("tool_calls", [])
    assert len(tool_calls) == 1, "tool_calls number is not correct"
    expected_tool_call = {
        "index": 0,
        "id": "dummy_tool_call_id",
        "type": "function",
        "function": {"name": "dummy_tool", "arguments": '{"param": "value"}'},
    }
    assert tool_calls[0] == expected_tool_call, "tool_calls is not as expected"

    Test astream_chat method: when the tools parameter is passed,
    astream_call_with_messages should receive this parameter,
    and the additional_kwargs of the returned ChatResponse should contain the correct tool_calls.
    
llama-index-integrations/llms/llama-index-llms-dashscope/tests/test_dashscope.py