test_few_shot.py — langchain Source File
Architecture documentation for test_few_shot.py, a python file in the langchain codebase. 11 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR c6f9855b_9c8e_a8da_99b4_e2820d3b8064["test_few_shot.py"] 67ec3255_645e_8b6e_1eff_1eb3c648ed95["re"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> 67ec3255_645e_8b6e_1eff_1eb3c648ed95 cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> 120e2591_3e15_b895_72b6_cb26195e40a6 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> 91721f45_4909_e489_8c1f_084f8bd87145 a4804e3f_4fa3_c9fc_7121_e057c2daa7e3["langchain_core.example_selectors"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> a4804e3f_4fa3_c9fc_7121_e057c2daa7e3 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> d758344f_537f_649e_f467_b9d7442e86df e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> e6b4f61e_7b98_6666_3641_26b069517d4a e45722a2_0136_a972_1f58_7b5987500404["langchain_core.prompts.chat"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> e45722a2_0136_a972_1f58_7b5987500404 4fa023ed_e78b_1291_b37f_a81c605fc08d["langchain_core.prompts.few_shot"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> 4fa023ed_e78b_1291_b37f_a81c605fc08d c17bcf07_a2ef_b992_448f_5088d46a1e79["langchain_core.prompts.prompt"] c6f9855b_9c8e_a8da_99b4_e2820d3b8064 --> c17bcf07_a2ef_b992_448f_5088d46a1e79 style c6f9855b_9c8e_a8da_99b4_e2820d3b8064 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Test few shot prompt template."""
import re
from collections.abc import Sequence
from typing import Any
import pytest
from typing_extensions import override
from langchain_core.example_selectors import BaseExampleSelector
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
from langchain_core.prompts import (
AIMessagePromptTemplate,
ChatPromptTemplate,
HumanMessagePromptTemplate,
)
from langchain_core.prompts.chat import SystemMessagePromptTemplate
from langchain_core.prompts.few_shot import (
FewShotChatMessagePromptTemplate,
FewShotPromptTemplate,
)
from langchain_core.prompts.prompt import PromptTemplate
EXAMPLE_PROMPT = PromptTemplate(
input_variables=["question", "answer"], template="{question}: {answer}"
)
@pytest.fixture
def example_jinja2_prompt() -> tuple[PromptTemplate, list[dict[str, str]]]:
example_template = "{{ word }}: {{ antonym }}"
examples = [
{"word": "happy", "antonym": "sad"},
{"word": "tall", "antonym": "short"},
]
return (
PromptTemplate(
input_variables=["word", "antonym"],
template=example_template,
template_format="jinja2",
),
examples,
)
def test_suffix_only() -> None:
"""Test prompt works with just a suffix."""
suffix = "This is a {foo} test."
input_variables = ["foo"]
prompt = FewShotPromptTemplate(
input_variables=input_variables,
suffix=suffix,
examples=[],
example_prompt=EXAMPLE_PROMPT,
)
output = prompt.format(foo="bar")
expected_output = "This is a bar test."
assert output == expected_output
// ... (484 more lines)
Domain
Subdomains
Functions
- example_jinja2_prompt()
- test_auto_infer_input_variables()
- test_few_shot_chat_message_prompt_template()
- test_few_shot_chat_message_prompt_template_infer_input_variables()
- test_few_shot_chat_message_prompt_template_with_selector()
- test_few_shot_chat_message_prompt_template_with_selector_async()
- test_few_shot_functionality()
- test_few_shot_prompt_template_with_selector()
- test_few_shot_prompt_template_with_selector_async()
- test_partial()
- test_partial_init_func()
- test_partial_init_string()
- test_prompt_jinja2_extra_input_variables()
- test_prompt_jinja2_functionality()
- test_prompt_jinja2_missing_input_variables()
- test_prompt_missing_input_variables()
- test_suffix_only()
Classes
Dependencies
- collections.abc
- langchain_core.example_selectors
- langchain_core.messages
- langchain_core.prompts
- langchain_core.prompts.chat
- langchain_core.prompts.few_shot
- langchain_core.prompts.prompt
- pytest
- re
- typing
- typing_extensions
Source
Frequently Asked Questions
What does test_few_shot.py do?
test_few_shot.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_few_shot.py?
test_few_shot.py defines 17 function(s): example_jinja2_prompt, test_auto_infer_input_variables, test_few_shot_chat_message_prompt_template, test_few_shot_chat_message_prompt_template_infer_input_variables, test_few_shot_chat_message_prompt_template_with_selector, test_few_shot_chat_message_prompt_template_with_selector_async, test_few_shot_functionality, test_few_shot_prompt_template_with_selector, test_few_shot_prompt_template_with_selector_async, test_partial, and 7 more.
What does test_few_shot.py depend on?
test_few_shot.py imports 11 module(s): collections.abc, langchain_core.example_selectors, langchain_core.messages, langchain_core.prompts, langchain_core.prompts.chat, langchain_core.prompts.few_shot, langchain_core.prompts.prompt, pytest, and 3 more.
Where is test_few_shot.py in the architecture?
test_few_shot.py is located at libs/core/tests/unit_tests/prompts/test_few_shot.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/tests/unit_tests/prompts).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free