Home / Function/ test_chat_prompt_template_from_messages_using_role_strings() — langchain Function Reference

test_chat_prompt_template_from_messages_using_role_strings() — langchain Function Reference

Architecture documentation for the test_chat_prompt_template_from_messages_using_role_strings() function in test_chat.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6bc9276a_b048_fdd7_4c54_7741bda55958["test_chat_prompt_template_from_messages_using_role_strings()"]
  bf3138ca_0068_68ea_f479_35376e264d13["test_chat.py"]
  6bc9276a_b048_fdd7_4c54_7741bda55958 -->|defined in| bf3138ca_0068_68ea_f479_35376e264d13
  style 6bc9276a_b048_fdd7_4c54_7741bda55958 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/prompts/test_chat.py lines 240–266

async def test_chat_prompt_template_from_messages_using_role_strings() -> None:
    """Test creating a chat prompt template from role string messages."""
    template = ChatPromptTemplate.from_messages(
        [
            ("system", "You are a helpful AI bot. Your name is {name}."),
            ("human", "Hello, how are you doing?"),
            ("ai", "I'm doing well, thanks!"),
            ("human", "{user_input}"),
        ]
    )

    expected = [
        SystemMessage(
            content="You are a helpful AI bot. Your name is Bob.", additional_kwargs={}
        ),
        HumanMessage(content="Hello, how are you doing?", additional_kwargs={}),
        AIMessage(content="I'm doing well, thanks!", additional_kwargs={}),
        HumanMessage(content="What is your name?", additional_kwargs={}),
    ]

    messages = template.format_messages(name="Bob", user_input="What is your name?")
    assert messages == expected

    messages = await template.aformat_messages(
        name="Bob", user_input="What is your name?"
    )
    assert messages == expected

Subdomains

Frequently Asked Questions

What does test_chat_prompt_template_from_messages_using_role_strings() do?
test_chat_prompt_template_from_messages_using_role_strings() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/prompts/test_chat.py.
Where is test_chat_prompt_template_from_messages_using_role_strings() defined?
test_chat_prompt_template_from_messages_using_role_strings() is defined in libs/core/tests/unit_tests/prompts/test_chat.py at line 240.

Analyze Your Own Codebase

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

Try Supermodel Free