mirror of
https://github.com/hwchase17/langchain.git
synced 2025-10-22 09:41:52 +00:00
Fix loading of ImagePromptTemplate (#16868)
We didn't override the namespace of the ImagePromptTemplate, so it is listed as being in langchain.schema This updates the mapping to let the loader deserialize. Alternatively, we could make a slight breaking change and update the namespace of the ImagePromptTemplate since we haven't broadly publicized/documented it yet..
This commit is contained in:
@@ -115,6 +115,12 @@ SERIALIZABLE_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
|
||||
"chat",
|
||||
"SystemMessagePromptTemplate",
|
||||
),
|
||||
("langchain", "prompts", "image", "ImagePromptTemplate"): (
|
||||
"langchain_core",
|
||||
"prompts",
|
||||
"image",
|
||||
"ImagePromptTemplate",
|
||||
),
|
||||
("langchain", "schema", "agent", "AgentActionMessageLog"): (
|
||||
"langchain_core",
|
||||
"agents",
|
||||
@@ -510,6 +516,12 @@ _OG_SERIALIZABLE_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
|
||||
"system",
|
||||
"SystemMessage",
|
||||
),
|
||||
("langchain", "schema", "prompt_template", "ImagePromptTemplate"): (
|
||||
"langchain_core",
|
||||
"prompts",
|
||||
"image",
|
||||
"ImagePromptTemplate",
|
||||
),
|
||||
}
|
||||
|
||||
# Needed for backwards compatibility for a few versions where we serialized
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from typing import Any
|
||||
from typing import Any, List
|
||||
|
||||
from langchain_core.prompt_values import ImagePromptValue, ImageURL, PromptValue
|
||||
from langchain_core.prompts.base import BasePromptTemplate
|
||||
@@ -30,6 +30,11 @@ class ImagePromptTemplate(BasePromptTemplate[ImageURL]):
|
||||
"""Return the prompt type key."""
|
||||
return "image-prompt"
|
||||
|
||||
@classmethod
|
||||
def get_lc_namespace(cls) -> List[str]:
|
||||
"""Get the namespace of the langchain object."""
|
||||
return ["langchain", "prompts", "image"]
|
||||
|
||||
def format_prompt(self, **kwargs: Any) -> PromptValue:
|
||||
"""Create Chat Messages."""
|
||||
return ImagePromptValue(image_url=self.format(**kwargs))
|
||||
|
Reference in New Issue
Block a user