Home / Function/ test_deep_stream_assign() — langchain Function Reference

test_deep_stream_assign() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/tests/unit_tests/runnables/test_runnable.py lines 3551–3646

def test_deep_stream_assign() -> None:
    prompt = (
        SystemMessagePromptTemplate.from_template("You are a nice assistant.")
        + "{question}"
    )
    llm = FakeStreamingListLLM(responses=["foo-lish"])

    chain: Runnable = prompt | llm | {"str": StrOutputParser()}

    stream = chain.stream({"question": "What up"})

    chunks = list(stream)

    assert len(chunks) == len("foo-lish")
    assert add(chunks) == {"str": "foo-lish"}

    chain_with_assign = chain.assign(hello=itemgetter("str") | llm)

    assert chain_with_assign.get_input_jsonschema() == {
        "title": "PromptInput",
        "type": "object",
        "properties": {"question": {"title": "Question", "type": "string"}},
        "required": ["question"],
    }
    assert chain_with_assign.get_output_jsonschema() == {
        "title": "RunnableSequenceOutput",
        "type": "object",
        "properties": {
            "str": {"title": "Str", "type": "string"},
            "hello": {"title": "Hello", "type": "string"},
        },
        "required": ["str", "hello"],
    }

    chunks = []
    for chunk in chain_with_assign.stream({"question": "What up"}):
        chunks.append(chunk)

    assert len(chunks) == len("foo-lish") * 2
    assert chunks == [
        # first stream passthrough input chunks
        {"str": "f"},
        {"str": "o"},
        {"str": "o"},
        {"str": "-"},
        {"str": "l"},
        {"str": "i"},
        {"str": "s"},
        {"str": "h"},
        # then stream assign output chunks
        {"hello": "f"},
        {"hello": "o"},
        {"hello": "o"},
        {"hello": "-"},
        {"hello": "l"},
        {"hello": "i"},
        {"hello": "s"},
        {"hello": "h"},
    ]
    assert add(chunks) == {"str": "foo-lish", "hello": "foo-lish"}
    assert chain_with_assign.invoke({"question": "What up"}) == {
        "str": "foo-lish",
        "hello": "foo-lish",
    }

    chain_with_assign_shadow = chain.assign(
        str=lambda _: "shadow",
        hello=itemgetter("str") | llm,
    )

    assert chain_with_assign_shadow.get_input_jsonschema() == {
        "title": "PromptInput",
        "type": "object",
        "properties": {"question": {"title": "Question", "type": "string"}},
        "required": ["question"],
    }
    assert chain_with_assign_shadow.get_output_jsonschema() == {
        "title": "RunnableSequenceOutput",
        "type": "object",
        "properties": {
            "str": {"title": "Str"},

Domain

Subdomains

Calls

Frequently Asked Questions

What does test_deep_stream_assign() do?
test_deep_stream_assign() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_deep_stream_assign() defined?
test_deep_stream_assign() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 3551.
What does test_deep_stream_assign() call?
test_deep_stream_assign() 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