test_seq_prompt_dict() — langchain Function Reference
Architecture documentation for the test_seq_prompt_dict() function in test_runnable.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 3e6f308a_404c_dd9a_1a4e_5882901f0fb8["test_seq_prompt_dict()"] 26df6ad8_0189_51d0_c3c1_6c3248893ff5["test_runnable.py"] 3e6f308a_404c_dd9a_1a4e_5882901f0fb8 -->|defined in| 26df6ad8_0189_51d0_c3c1_6c3248893ff5 a3895c50_dab4_0c36_2d24_f63121e198a0["invoke()"] 3e6f308a_404c_dd9a_1a4e_5882901f0fb8 -->|calls| a3895c50_dab4_0c36_2d24_f63121e198a0 style 3e6f308a_404c_dd9a_1a4e_5882901f0fb8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/runnables/test_runnable.py lines 2804–2861
def test_seq_prompt_dict(mocker: MockerFixture, snapshot: SnapshotAssertion) -> None:
passthrough = mocker.Mock(side_effect=lambda x: x)
prompt = (
SystemMessagePromptTemplate.from_template("You are a nice assistant.")
+ "{question}"
)
chat = FakeListChatModel(responses=["i'm a chatbot"])
llm = FakeListLLM(responses=["i'm a textbot"])
chain = (
prompt
| passthrough
| {
"chat": chat,
"llm": llm,
}
)
assert repr(chain) == snapshot
assert isinstance(chain, RunnableSequence)
assert chain.first == prompt
assert chain.middle == [RunnableLambda(passthrough)]
assert isinstance(chain.last, RunnableParallel)
assert dumps(chain, pretty=True) == snapshot
# Test invoke
prompt_spy = mocker.spy(prompt.__class__, "invoke")
chat_spy = mocker.spy(chat.__class__, "invoke")
llm_spy = mocker.spy(llm.__class__, "invoke")
tracer = FakeTracer()
assert chain.invoke(
{"question": "What is your name?"}, {"callbacks": [tracer]}
) == {
"chat": _any_id_ai_message(content="i'm a chatbot"),
"llm": "i'm a textbot",
}
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 llm_spy.call_args.args[1] == ChatPromptValue(
messages=[
SystemMessage(content="You are a nice assistant."),
HumanMessage(content="What is your name?"),
]
)
assert len([r for r in tracer.runs if r.parent_run_id is None]) == 1
parent_run = next(r for r in tracer.runs if r.parent_run_id is None)
assert len(parent_run.child_runs) == 3
map_run = parent_run.child_runs[2]
assert map_run.name == "RunnableParallel<chat,llm>"
assert len(map_run.child_runs) == 2
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does test_seq_prompt_dict() do?
test_seq_prompt_dict() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_seq_prompt_dict() defined?
test_seq_prompt_dict() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 2804.
What does test_seq_prompt_dict() call?
test_seq_prompt_dict() 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