ImagePromptTemplate Class — langchain Architecture
Architecture documentation for the ImagePromptTemplate class in image.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6a465cb4_c33a_e368_ad81_def98b4d2da2["ImagePromptTemplate"] 5c37ae95_be41_5e54_aaf5_00f7e4715fbc["image.py"] 6a465cb4_c33a_e368_ad81_def98b4d2da2 -->|defined in| 5c37ae95_be41_5e54_aaf5_00f7e4715fbc f083de38_569a_92f5_40cc_79d6ef0decd2["__init__()"] 6a465cb4_c33a_e368_ad81_def98b4d2da2 -->|method| f083de38_569a_92f5_40cc_79d6ef0decd2 f1b64557_d75f_f24b_47ba_a98a55fdbdaf["_prompt_type()"] 6a465cb4_c33a_e368_ad81_def98b4d2da2 -->|method| f1b64557_d75f_f24b_47ba_a98a55fdbdaf 9462323f_2113_8d33_eeb0_ef448d949a66["get_lc_namespace()"] 6a465cb4_c33a_e368_ad81_def98b4d2da2 -->|method| 9462323f_2113_8d33_eeb0_ef448d949a66 24bd1a9c_f02c_2911_efd9_da075dd6cda5["format_prompt()"] 6a465cb4_c33a_e368_ad81_def98b4d2da2 -->|method| 24bd1a9c_f02c_2911_efd9_da075dd6cda5 95eb0b40_bc2d_888f_dc2e_0641d1268008["aformat_prompt()"] 6a465cb4_c33a_e368_ad81_def98b4d2da2 -->|method| 95eb0b40_bc2d_888f_dc2e_0641d1268008 dedbfd05_46bc_9cd0_b34a_11d767ba397b["format()"] 6a465cb4_c33a_e368_ad81_def98b4d2da2 -->|method| dedbfd05_46bc_9cd0_b34a_11d767ba397b bbf6e932_5147_518b_e7a3_3d9cae8701f6["aformat()"] 6a465cb4_c33a_e368_ad81_def98b4d2da2 -->|method| bbf6e932_5147_518b_e7a3_3d9cae8701f6 4533d6ee_bb83_fdf4_9edc_3948b66a320e["pretty_repr()"] 6a465cb4_c33a_e368_ad81_def98b4d2da2 -->|method| 4533d6ee_bb83_fdf4_9edc_3948b66a320e
Relationship Graph
Source Code
libs/core/langchain_core/prompts/image.py lines 16–157
class ImagePromptTemplate(BasePromptTemplate[ImageURL]):
"""Image prompt template for a multimodal model."""
template: dict = Field(default_factory=dict)
"""Template for the prompt."""
template_format: PromptTemplateFormat = "f-string"
"""The format of the prompt template.
Options are: `'f-string'`, `'mustache'`, `'jinja2'`.
"""
def __init__(self, **kwargs: Any) -> None:
"""Create an image prompt template.
Raises:
ValueError: If the input variables contain `'url'`, `'path'`, or
`'detail'`.
"""
if "input_variables" not in kwargs:
kwargs["input_variables"] = []
overlap = set(kwargs["input_variables"]) & {"url", "path", "detail"}
if overlap:
msg = (
"input_variables for the image template cannot contain"
" any of 'url', 'path', or 'detail'."
f" Found: {overlap}"
)
raise ValueError(msg)
super().__init__(**kwargs)
@property
def _prompt_type(self) -> str:
"""Return the prompt type key."""
return "image-prompt"
@classmethod
def get_lc_namespace(cls) -> list[str]:
"""Get the namespace of the LangChain object.
Returns:
`["langchain", "prompts", "image"]`
"""
return ["langchain", "prompts", "image"]
def format_prompt(self, **kwargs: Any) -> PromptValue:
"""Format the prompt with the inputs.
Args:
**kwargs: Any arguments to be passed to the prompt template.
Returns:
A formatted string.
"""
return ImagePromptValue(image_url=self.format(**kwargs))
async def aformat_prompt(self, **kwargs: Any) -> PromptValue:
"""Async format the prompt with the inputs.
Args:
**kwargs: Any arguments to be passed to the prompt template.
Returns:
A formatted string.
"""
return ImagePromptValue(image_url=await self.aformat(**kwargs))
def format(
self,
**kwargs: Any,
) -> ImageURL:
"""Format the prompt with the inputs.
Args:
**kwargs: Any arguments to be passed to the prompt template.
Returns:
A formatted string.
Raises:
Defined In
Source
Frequently Asked Questions
What is the ImagePromptTemplate class?
ImagePromptTemplate is a class in the langchain codebase, defined in libs/core/langchain_core/prompts/image.py.
Where is ImagePromptTemplate defined?
ImagePromptTemplate is defined in libs/core/langchain_core/prompts/image.py at line 16.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free