dict.py — langchain Source File
Architecture documentation for dict.py, a python file in the langchain codebase. 8 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR d31ac8f6_f369_3202_2fdc_84c37eba4e57["dict.py"] 0c635125_6987_b8b3_7ff7_d60249aecde7["warnings"] d31ac8f6_f369_3202_2fdc_84c37eba4e57 --> 0c635125_6987_b8b3_7ff7_d60249aecde7 c990f2d7_9509_7cea_ca95_51ad57dbe5c6["functools"] d31ac8f6_f369_3202_2fdc_84c37eba4e57 --> c990f2d7_9509_7cea_ca95_51ad57dbe5c6 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] d31ac8f6_f369_3202_2fdc_84c37eba4e57 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] d31ac8f6_f369_3202_2fdc_84c37eba4e57 --> 91721f45_4909_e489_8c1f_084f8bd87145 36cce5da_d805_04c3_7e86_e1b4dd49b497["langchain_core.load"] d31ac8f6_f369_3202_2fdc_84c37eba4e57 --> 36cce5da_d805_04c3_7e86_e1b4dd49b497 e10bb307_3784_1031_cf6b_680e7c362c93["langchain_core.prompts.string"] d31ac8f6_f369_3202_2fdc_84c37eba4e57 --> e10bb307_3784_1031_cf6b_680e7c362c93 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"] d31ac8f6_f369_3202_2fdc_84c37eba4e57 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c 2971f9da_6393_a3e3_610e_ace3d35ee978["langchain_core.runnables.config"] d31ac8f6_f369_3202_2fdc_84c37eba4e57 --> 2971f9da_6393_a3e3_610e_ace3d35ee978 style d31ac8f6_f369_3202_2fdc_84c37eba4e57 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Dictionary prompt template."""
import warnings
from functools import cached_property
from typing import Any, Literal, cast
from typing_extensions import override
from langchain_core.load import dumpd
from langchain_core.prompts.string import (
DEFAULT_FORMATTER_MAPPING,
get_template_variables,
)
from langchain_core.runnables import RunnableConfig, RunnableSerializable
from langchain_core.runnables.config import ensure_config
class DictPromptTemplate(RunnableSerializable[dict, dict]):
"""Template represented by a dictionary.
Recognizes variables in f-string or mustache formatted string dict values.
Does NOT recognize variables in dict keys. Applies recursively.
"""
template: dict[str, Any]
template_format: Literal["f-string", "mustache"]
@property
def input_variables(self) -> list[str]:
"""Template input variables."""
return _get_input_variables(self.template, self.template_format)
def format(self, **kwargs: Any) -> dict[str, Any]:
"""Format the prompt with the inputs.
Returns:
A formatted dict.
"""
return _insert_input_variables(self.template, kwargs, self.template_format)
async def aformat(self, **kwargs: Any) -> dict[str, Any]:
"""Format the prompt with the inputs.
Returns:
A formatted dict.
"""
return self.format(**kwargs)
@override
def invoke(
self, input: dict, config: RunnableConfig | None = None, **kwargs: Any
) -> dict:
return self._call_with_config(
lambda x: self.format(**x),
input,
ensure_config(config),
run_type="prompt",
serialized=self._serialized,
**kwargs,
// ... (91 more lines)
Domain
Subdomains
Classes
Dependencies
- functools
- langchain_core.load
- langchain_core.prompts.string
- langchain_core.runnables
- langchain_core.runnables.config
- typing
- typing_extensions
- warnings
Source
Frequently Asked Questions
What does dict.py do?
dict.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 dict.py?
dict.py defines 2 function(s): _get_input_variables, _insert_input_variables.
What does dict.py depend on?
dict.py imports 8 module(s): functools, langchain_core.load, langchain_core.prompts.string, langchain_core.runnables, langchain_core.runnables.config, typing, typing_extensions, warnings.
Where is dict.py in the architecture?
dict.py is located at libs/core/langchain_core/prompts/dict.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