Home / Function/ test_few_shot_chat_message_prompt_template_with_selector_async() — langchain Function Reference

test_few_shot_chat_message_prompt_template_with_selector_async() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/tests/unit_tests/prompts/test_few_shot.py lines 510–543

async def test_few_shot_chat_message_prompt_template_with_selector_async() -> None:
    """Tests for few shot chat message template with an async example selector."""
    examples = [
        {"input": "2+2", "output": "4"},
        {"input": "2+3", "output": "5"},
    ]
    example_selector = AsyncAsIsSelector(examples)
    example_prompt = ChatPromptTemplate.from_messages(
        [
            HumanMessagePromptTemplate.from_template("{input}"),
            AIMessagePromptTemplate.from_template("{output}"),
        ]
    )

    few_shot_prompt = FewShotChatMessagePromptTemplate(
        input_variables=["input"],
        example_prompt=example_prompt,
        example_selector=example_selector,
    )
    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 = 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_with_selector_async() do?
test_few_shot_chat_message_prompt_template_with_selector_async() 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_with_selector_async() defined?
test_few_shot_chat_message_prompt_template_with_selector_async() is defined in libs/core/tests/unit_tests/prompts/test_few_shot.py at line 510.

Analyze Your Own Codebase

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

Try Supermodel Free