aformat() — langchain Function Reference
Architecture documentation for the aformat() function in few_shot.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD a1af40b0_77e5_5515_2418_602984733e1b["aformat()"] 938e1250_dc3f_175c_b4b0_06175d9760e1["FewShotPromptTemplate"] a1af40b0_77e5_5515_2418_602984733e1b -->|defined in| 938e1250_dc3f_175c_b4b0_06175d9760e1 2ef7ae59_e8a5_8333_12ce_900bb3658156["aformat()"] 2ef7ae59_e8a5_8333_12ce_900bb3658156 -->|calls| a1af40b0_77e5_5515_2418_602984733e1b 451110ca_cd2a_6b46_2728_65bad5d8be19["_aget_examples()"] a1af40b0_77e5_5515_2418_602984733e1b -->|calls| 451110ca_cd2a_6b46_2728_65bad5d8be19 2ef7ae59_e8a5_8333_12ce_900bb3658156["aformat()"] a1af40b0_77e5_5515_2418_602984733e1b -->|calls| 2ef7ae59_e8a5_8333_12ce_900bb3658156 style a1af40b0_77e5_5515_2418_602984733e1b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/prompts/few_shot.py lines 207–233
async def aformat(self, **kwargs: Any) -> str:
"""Async format the prompt with inputs generating a string.
Use this method to generate a string representation of a prompt.
Args:
**kwargs: Keyword arguments to use for formatting.
Returns:
A string representation of the prompt.
"""
kwargs = self._merge_partial_and_user_variables(**kwargs)
# Get the examples to use.
examples = await self._aget_examples(**kwargs)
examples = [
{k: e[k] for k in self.example_prompt.input_variables} for e in examples
]
# Format the examples.
example_strings = [
await self.example_prompt.aformat(**example) for example in examples
]
# Create the overall template.
pieces = [self.prefix, *example_strings, self.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
Defined In
Called By
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.py.
Where is aformat() defined?
aformat() is defined in libs/core/langchain_core/prompts/few_shot.py at line 207.
What does aformat() call?
aformat() calls 2 function(s): _aget_examples, aformat.
What calls aformat()?
aformat() is called by 1 function(s): aformat.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free