Home / Function/ test_generic_fake_chat_model_stream() — langchain Function Reference

test_generic_fake_chat_model_stream() — langchain Function Reference

Architecture documentation for the test_generic_fake_chat_model_stream() function in test_fake_chat_model.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  9d6b0f7a_ad9d_35cc_6e18_def282f80337["test_generic_fake_chat_model_stream()"]
  80c98d4d_3f6a_0197_c2ea_3db4062a1246["test_fake_chat_model.py"]
  9d6b0f7a_ad9d_35cc_6e18_def282f80337 -->|defined in| 80c98d4d_3f6a_0197_c2ea_3db4062a1246
  style 9d6b0f7a_ad9d_35cc_6e18_def282f80337 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/tests/unit_tests/llms/test_fake_chat_model.py lines 40–133

async def test_generic_fake_chat_model_stream() -> None:
    """Test streaming."""
    infinite_cycle = cycle(
        [
            AIMessage(content="hello goodbye"),
        ],
    )
    model = GenericFakeChatModel(messages=infinite_cycle)
    chunks = [chunk async for chunk in model.astream("meow")]
    assert chunks == [
        _AnyIdAIMessageChunk(content="hello"),
        _AnyIdAIMessageChunk(content=" "),
        _AnyIdAIMessageChunk(content="goodbye", chunk_position="last"),
    ]

    chunks = list(model.stream("meow"))
    assert chunks == [
        _AnyIdAIMessageChunk(content="hello"),
        _AnyIdAIMessageChunk(content=" "),
        _AnyIdAIMessageChunk(content="goodbye", chunk_position="last"),
    ]

    # Test streaming of additional kwargs.
    # Relying on insertion order of the additional kwargs dict
    message = AIMessage(content="", additional_kwargs={"foo": 42, "bar": 24})
    model = GenericFakeChatModel(messages=cycle([message]))
    chunks = [chunk async for chunk in model.astream("meow")]
    assert chunks == [
        _AnyIdAIMessageChunk(content="", additional_kwargs={"foo": 42}),
        _AnyIdAIMessageChunk(content="", additional_kwargs={"bar": 24}),
        _AnyIdAIMessageChunk(content="", chunk_position="last"),
    ]

    message = AIMessage(
        id="a1",
        content="",
        additional_kwargs={
            "function_call": {
                "name": "move_file",
                "arguments": '{\n  "source_path": "foo",\n  "'
                'destination_path": "bar"\n}',
            },
        },
    )
    model = GenericFakeChatModel(messages=cycle([message]))
    chunks = [chunk async for chunk in model.astream("meow")]

    assert chunks == [
        AIMessageChunk(
            content="",
            additional_kwargs={"function_call": {"name": "move_file"}},
            id="a1",
        ),
        AIMessageChunk(
            id="a1",
            content="",
            additional_kwargs={
                "function_call": {"arguments": '{\n  "source_path": "foo"'},
            },
        ),
        AIMessageChunk(
            id="a1",
            content="",
            additional_kwargs={"function_call": {"arguments": ","}},
        ),
        AIMessageChunk(
            id="a1",
            content="",
            additional_kwargs={
                "function_call": {"arguments": '\n  "destination_path": "bar"\n}'},
            },
        ),
        _AnyIdAIMessageChunk(content="", chunk_position="last"),
    ]

    accumulate_chunks = None
    for chunk in chunks:
        if accumulate_chunks is None:
            accumulate_chunks = chunk
        else:
            accumulate_chunks += chunk

Domain

Subdomains

Frequently Asked Questions

What does test_generic_fake_chat_model_stream() do?
test_generic_fake_chat_model_stream() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/llms/test_fake_chat_model.py.
Where is test_generic_fake_chat_model_stream() defined?
test_generic_fake_chat_model_stream() is defined in libs/langchain/tests/unit_tests/llms/test_fake_chat_model.py at line 40.

Analyze Your Own Codebase

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

Try Supermodel Free