Home / Function/ test_run_llm_or_chain_with_input_mapper() — langchain Function Reference

test_run_llm_or_chain_with_input_mapper() — langchain Function Reference

Architecture documentation for the test_run_llm_or_chain_with_input_mapper() function in test_runner_utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  51d4889d_ec55_59c7_bb9a_688436e50526["test_run_llm_or_chain_with_input_mapper()"]
  c6cd417d_d0bc_a309_dd34_61e338d2ac18["test_runner_utils.py"]
  51d4889d_ec55_59c7_bb9a_688436e50526 -->|defined in| c6cd417d_d0bc_a309_dd34_61e338d2ac18
  style 51d4889d_ec55_59c7_bb9a_688436e50526 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/tests/unit_tests/smith/evaluation/test_runner_utils.py lines 161–211

def test_run_llm_or_chain_with_input_mapper() -> None:
    example = Example(
        id=uuid.uuid4(),
        created_at=_CREATED_AT,
        inputs={"the wrong input": "1", "another key": "2"},
        outputs={"output": "2"},
        dataset_id=str(uuid.uuid4()),
    )

    def run_val(inputs: dict) -> dict:
        assert "the right input" in inputs
        return {"output": "2"}

    mock_chain = TransformChain(
        input_variables=["the right input"],
        output_variables=["output"],
        transform=run_val,
    )

    def input_mapper(inputs: dict) -> dict:
        assert "the wrong input" in inputs
        return {"the right input": inputs["the wrong input"]}

    result = _run_llm_or_chain(
        example,
        {"callbacks": [], "tags": []},
        llm_or_chain_factory=lambda: mock_chain,
        input_mapper=input_mapper,
    )
    assert result == {"output": "2", "the right input": "1"}
    bad_result = _run_llm_or_chain(
        example,
        {"callbacks": [], "tags": []},
        llm_or_chain_factory=lambda: mock_chain,
    )
    assert "Error" in bad_result

    # Try with LLM
    def llm_input_mapper(inputs: dict) -> str:
        assert "the wrong input" in inputs
        return "the right input"

    mock_llm = FakeLLM(queries={"the right input": "somenumber"})
    llm_result = _run_llm_or_chain(
        example,
        {"callbacks": [], "tags": []},
        llm_or_chain_factory=mock_llm,
        input_mapper=llm_input_mapper,
    )
    assert isinstance(llm_result, str)
    assert llm_result == "somenumber"

Domain

Subdomains

Frequently Asked Questions

What does test_run_llm_or_chain_with_input_mapper() do?
test_run_llm_or_chain_with_input_mapper() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/smith/evaluation/test_runner_utils.py.
Where is test_run_llm_or_chain_with_input_mapper() defined?
test_run_llm_or_chain_with_input_mapper() is defined in libs/langchain/tests/unit_tests/smith/evaluation/test_runner_utils.py at line 161.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free