Home / Function/ test_few_shot_chat_message_prompt_template() — langchain Function Reference

test_few_shot_chat_message_prompt_template() — langchain Function Reference

Architecture documentation for the test_few_shot_chat_message_prompt_template() function in test_few_shot.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  76ec3578_7042_70f3_52e7_657661cf8ff5["test_few_shot_chat_message_prompt_template()"]
  e4e12a36_798e_ddc0_ab57_e44de269c7e7["test_few_shot.py"]
  76ec3578_7042_70f3_52e7_657661cf8ff5 -->|defined in| e4e12a36_798e_ddc0_ab57_e44de269c7e7
  style 76ec3578_7042_70f3_52e7_657661cf8ff5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/prompts/test_few_shot.py lines 333–370

async def test_few_shot_chat_message_prompt_template() -> None:
    """Tests for few shot chat message template."""
    examples = [
        {"input": "2+2", "output": "4"},
        {"input": "2+3", "output": "5"},
    ]

    example_prompt = ChatPromptTemplate.from_messages(
        [
            HumanMessagePromptTemplate.from_template("{input}"),
            AIMessagePromptTemplate.from_template("{output}"),
        ]
    )

    few_shot_prompt = FewShotChatMessagePromptTemplate(
        input_variables=["input"],
        example_prompt=example_prompt,
        examples=examples,
    )
    final_prompt: ChatPromptTemplate = (
        SystemMessagePromptTemplate.from_template("You are a helpful AI Assistant")
        + few_shot_prompt
        + HumanMessagePromptTemplate.from_template("{input}")
    )

    expected = [
        SystemMessage(content="You are a helpful AI Assistant", additional_kwargs={}),
        HumanMessage(content="2+2", additional_kwargs={}),
        AIMessage(content="4", additional_kwargs={}),
        HumanMessage(content="2+3", additional_kwargs={}),
        AIMessage(content="5", additional_kwargs={}),
        HumanMessage(content="100 + 1", additional_kwargs={}),
    ]

    messages = final_prompt.format_messages(input="100 + 1")
    assert messages == expected
    messages = await final_prompt.aformat_messages(input="100 + 1")
    assert messages == expected

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free