few_shot.py — langchain Source File
Architecture documentation for few_shot.py, a python file in the langchain codebase. 10 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a["few_shot.py"] 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"] 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a --> 91721f45_4909_e489_8c1f_084f8bd87145 a4804e3f_4fa3_c9fc_7121_e057c2daa7e3["langchain_core.example_selectors"] 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a --> a4804e3f_4fa3_c9fc_7121_e057c2daa7e3 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a --> d758344f_537f_649e_f467_b9d7442e86df e45722a2_0136_a972_1f58_7b5987500404["langchain_core.prompts.chat"] 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a --> e45722a2_0136_a972_1f58_7b5987500404 63bafb65_e3c1_8fca_d02a_332411ce701e["langchain_core.prompts.message"] 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a --> 63bafb65_e3c1_8fca_d02a_332411ce701e c17bcf07_a2ef_b992_448f_5088d46a1e79["langchain_core.prompts.prompt"] 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a --> c17bcf07_a2ef_b992_448f_5088d46a1e79 e10bb307_3784_1031_cf6b_680e7c362c93["langchain_core.prompts.string"] 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a --> e10bb307_3784_1031_cf6b_680e7c362c93 b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8["pathlib"] 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a --> b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8 style 86a08c5c_a8e3_8f4d_a193_4d9c7166ae3a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Prompt template that contains few shot examples."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any, Literal
from pydantic import (
BaseModel,
ConfigDict,
Field,
model_validator,
)
from typing_extensions import override
from langchain_core.example_selectors import BaseExampleSelector
from langchain_core.messages import BaseMessage, get_buffer_string
from langchain_core.prompts.chat import BaseChatPromptTemplate
from langchain_core.prompts.message import BaseMessagePromptTemplate
from langchain_core.prompts.prompt import PromptTemplate
from langchain_core.prompts.string import (
DEFAULT_FORMATTER_MAPPING,
StringPromptTemplate,
check_valid_template,
get_template_variables,
)
if TYPE_CHECKING:
from pathlib import Path
from typing_extensions import Self
class _FewShotPromptTemplateMixin(BaseModel):
"""Prompt template that contains few shot examples."""
examples: list[dict] | None = None
"""Examples to format into the prompt.
Either this or `example_selector` should be provided.
"""
example_selector: BaseExampleSelector | None = None
"""`ExampleSelector` to choose the examples to format into the prompt.
Either this or `examples` should be provided.
"""
model_config = ConfigDict(
arbitrary_types_allowed=True,
extra="forbid",
)
@model_validator(mode="before")
@classmethod
def check_examples_and_selector(cls, values: dict) -> Any:
"""Check that one and only one of `examples`/`example_selector` are provided.
Args:
values: The values to check.
// ... (417 more lines)
Domain
Subdomains
Functions
Dependencies
- langchain_core.example_selectors
- langchain_core.messages
- langchain_core.prompts.chat
- langchain_core.prompts.message
- langchain_core.prompts.prompt
- langchain_core.prompts.string
- pathlib
- pydantic
- typing
- typing_extensions
Source
Frequently Asked Questions
What does few_shot.py do?
few_shot.py is a source file in the langchain codebase, written in python. It belongs to the PromptManagement domain, ExampleSelection subdomain.
What functions are defined in few_shot.py?
few_shot.py defines 1 function(s): pathlib.
What does few_shot.py depend on?
few_shot.py imports 10 module(s): langchain_core.example_selectors, langchain_core.messages, langchain_core.prompts.chat, langchain_core.prompts.message, langchain_core.prompts.prompt, langchain_core.prompts.string, pathlib, pydantic, and 2 more.
Where is few_shot.py in the architecture?
few_shot.py is located at libs/core/langchain_core/prompts/few_shot.py (domain: PromptManagement, subdomain: ExampleSelection, directory: libs/core/langchain_core/prompts).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free