async def test_query_pipeline_async() -> None:
    """Test query pipeline in async fashion."""
    # run some synchronous tests above

    # should work if input is a single arg
    p = QueryPipeline(chain=[QueryComponent3(), QueryComponent3()])
    # since there's one output, output is just the value
    output = await p.arun(3)
    assert output == 12

    # test qc1 with qc2 with one partial with full syntax
    qc1 = QueryComponent1()
    qc2 = QueryComponent2()
    p = QueryPipeline()
    p.add_modules({"qc1": qc1, "qc2": qc2})
    qc2.partial(input2="foo")
    p.add_link("qc1", "qc2", dest_key="input1")
    output = await p.arun(input1=2, input2=2)
    assert output == "4:foo"

    # Test input component
    # test connecting different inputs to different components
    qc1 = QueryComponent1()
    qc2 = QueryComponent2()
    inp = InputComponent()
    p = QueryPipeline()
    p.add_modules({"qc1": qc1, "qc2": qc2, "inp": inp})
    # add inp.inp1 to both qc1.input1 and qc2.input2
    p.add_link("inp", "qc1", src_key="inp1", dest_key="input1")
    p.add_link("inp", "qc2", src_key="inp1", dest_key="input2")
    # add inp.inp2 to qc1.input2
    p.add_link("inp", "qc1", src_key="inp2", dest_key="input2")
    # add qc1 to qc2.input1
    p.add_link("qc1", "qc2", dest_key="input1")
    output = await p.arun(inp1=1, inp2=2)
    assert output == "3:1"

    output = await p.arun(inp1=[1, 2], inp2=[2, 3], batch=True)
    assert output == ["3:1", "5:2"]

    # try run run_multi
    # link both qc1_0 and qc1_1 to qc2
    qc1_0 = QueryComponent1()
    qc1_1 = QueryComponent1()
    qc2 = QueryComponent2()
    p = QueryPipeline()
    p.add_modules({"qc1_0": qc1_0, "qc1_1": qc1_1, "qc2": qc2})
    p.add_link("qc1_0", "qc2", dest_key="input1")
    p.add_link("qc1_1", "qc2", dest_key="input2")
    output = await p.arun_multi(
        {"qc1_0": {"input1": 1, "input2": 2}, "qc1_1": {"input1": 3, "input2": 4}}
    )
    assert output == {"qc2": {"output": "3:7"}}

    output = await p.arun_multi(
        {
            "qc1_0": {"input1": [1, 5], "input2": [2, 1]},
            "qc1_1": {"input1": [3, 7], "input2": [4, 2]},
        },
        batch=True,
    )
    assert output == {"qc2": {"output": ["3:7", "6:9"]}}
Test query pipeline in async fashion.
llama-index-core/tests/query_pipeline/test_query.py