aformat() — langchain Function Reference
Architecture documentation for the aformat() function in few_shot_with_templates.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 36741e4a_4cfb_7230_12d1_c97fa33865ca["aformat()"] 4d8b68be_b916_6d5d_4da3_8f6d6a8725be["FewShotPromptWithTemplates"] 36741e4a_4cfb_7230_12d1_c97fa33865ca -->|defined in| 4d8b68be_b916_6d5d_4da3_8f6d6a8725be 80329a95_62e6_ed30_4576_f0ba15cb524a["_aget_examples()"] 36741e4a_4cfb_7230_12d1_c97fa33865ca -->|calls| 80329a95_62e6_ed30_4576_f0ba15cb524a 451886d0_bb14_d110_57ef_d2202fccdf8d["format()"] 36741e4a_4cfb_7230_12d1_c97fa33865ca -->|calls| 451886d0_bb14_d110_57ef_d2202fccdf8d style 36741e4a_4cfb_7230_12d1_c97fa33865ca fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/prompts/few_shot_with_templates.py lines 169–211
async def aformat(self, **kwargs: Any) -> str:
"""Async format the prompt with the inputs.
Args:
**kwargs: Any arguments to be passed to the prompt template.
Returns:
A formatted string.
"""
kwargs = self._merge_partial_and_user_variables(**kwargs)
# Get the examples to use.
examples = await self._aget_examples(**kwargs)
# Format the examples.
example_strings = [
# We can use the sync method here as PromptTemplate doesn't block
self.example_prompt.format(**example)
for example in examples
]
# Create the overall prefix.
if self.prefix is None:
prefix = ""
else:
prefix_kwargs = {
k: v for k, v in kwargs.items() if k in self.prefix.input_variables
}
for k in prefix_kwargs:
kwargs.pop(k)
prefix = await self.prefix.aformat(**prefix_kwargs)
# Create the overall suffix
suffix_kwargs = {
k: v for k, v in kwargs.items() if k in self.suffix.input_variables
}
for k in suffix_kwargs:
kwargs.pop(k)
suffix = await self.suffix.aformat(
**suffix_kwargs,
)
pieces = [prefix, *example_strings, suffix]
template = self.example_separator.join([piece for piece in pieces if piece])
# Format the template with the input variables.
return DEFAULT_FORMATTER_MAPPING[self.template_format](template, **kwargs)
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does aformat() do?
aformat() is a function in the langchain codebase, defined in libs/core/langchain_core/prompts/few_shot_with_templates.py.
Where is aformat() defined?
aformat() is defined in libs/core/langchain_core/prompts/few_shot_with_templates.py at line 169.
What does aformat() call?
aformat() calls 2 function(s): _aget_examples, format.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free