Home / Function/ test_prompt_with_chat_model_and_parser() — langchain Function Reference

test_prompt_with_chat_model_and_parser() — langchain Function Reference

Architecture documentation for the test_prompt_with_chat_model_and_parser() function in test_runnable.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  a5bb8d40_4215_e525_7be8_b63db4b1a979["test_prompt_with_chat_model_and_parser()"]
  26df6ad8_0189_51d0_c3c1_6c3248893ff5["test_runnable.py"]
  a5bb8d40_4215_e525_7be8_b63db4b1a979 -->|defined in| 26df6ad8_0189_51d0_c3c1_6c3248893ff5
  a3895c50_dab4_0c36_2d24_f63121e198a0["invoke()"]
  a5bb8d40_4215_e525_7be8_b63db4b1a979 -->|calls| a3895c50_dab4_0c36_2d24_f63121e198a0
  style a5bb8d40_4215_e525_7be8_b63db4b1a979 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/runnables/test_runnable.py lines 2622–2658

def test_prompt_with_chat_model_and_parser(
    mocker: MockerFixture,
    snapshot: SnapshotAssertion,
) -> None:
    prompt = (
        SystemMessagePromptTemplate.from_template("You are a nice assistant.")
        + "{question}"
    )
    chat = FakeListChatModel(responses=["foo, bar"])
    parser = CommaSeparatedListOutputParser()

    chain = prompt | chat | parser

    assert isinstance(chain, RunnableSequence)
    assert chain.first == prompt
    assert chain.middle == [chat]
    assert chain.last == parser
    assert dumps(chain, pretty=True) == snapshot

    # Test invoke
    prompt_spy = mocker.spy(prompt.__class__, "invoke")
    chat_spy = mocker.spy(chat.__class__, "invoke")
    parser_spy = mocker.spy(parser.__class__, "invoke")
    tracer = FakeTracer()
    assert chain.invoke(
        {"question": "What is your name?"}, {"callbacks": [tracer]}
    ) == ["foo", "bar"]
    assert prompt_spy.call_args.args[1] == {"question": "What is your name?"}
    assert chat_spy.call_args.args[1] == ChatPromptValue(
        messages=[
            SystemMessage(content="You are a nice assistant."),
            HumanMessage(content="What is your name?"),
        ]
    )
    assert parser_spy.call_args.args[1] == _any_id_ai_message(content="foo, bar")

    assert tracer.runs == snapshot

Domain

Subdomains

Calls

Frequently Asked Questions

What does test_prompt_with_chat_model_and_parser() do?
test_prompt_with_chat_model_and_parser() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_prompt_with_chat_model_and_parser() defined?
test_prompt_with_chat_model_and_parser() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 2622.
What does test_prompt_with_chat_model_and_parser() call?
test_prompt_with_chat_model_and_parser() calls 1 function(s): invoke.

Analyze Your Own Codebase

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

Try Supermodel Free