MCPcopy
hub / github.com/langchain-ai/langchain / test_each

Function test_each

libs/core/tests/unit_tests/runnables/test_runnable.py:4053–4071  ·  view source on GitHub ↗
(snapshot: SnapshotAssertion)

Source from the content-addressed store, hash-verified

4051
4052
4053def test_each(snapshot: SnapshotAssertion) -> None:
4054 prompt = (
4055 SystemMessagePromptTemplate.from_template("You are a nice assistant.")
4056 + "{question}"
4057 )
4058 first_llm = FakeStreamingListLLM(responses=["first item, second item, third item"])
4059 parser = FakeSplitIntoListParser()
4060 second_llm = FakeStreamingListLLM(responses=["this", "is", "a", "test"])
4061
4062 chain = prompt | first_llm | parser | second_llm.map()
4063
4064 assert dumps(chain, pretty=True) == snapshot
4065 output = chain.invoke({"question": "What up"})
4066 assert output == ["this", "is", "a"]
4067
4068 assert (parser | second_llm.map()).invoke("first item, second item") == [
4069 "test",
4070 "this",
4071 ]
4072
4073
4074def test_recursive_lambda() -> None:

Callers

nothing calls this directly

Calls 6

dumpsFunction · 0.90
from_templateMethod · 0.45
mapMethod · 0.45
invokeMethod · 0.45

Tested by

no test coverage detected