core[patch]: Change structured prompt lc id to match js (#19099)

This commit is contained in:
Nuno Campos
2024-03-14 20:02:52 -07:00
committed by GitHub
parent 7ce81eb6f4
commit 508f75853c
3 changed files with 26 additions and 9 deletions

View File

@@ -481,6 +481,12 @@ SERIALIZABLE_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
"retry",
"RunnableRetry",
),
("langchain_core", "prompts", "structured", "StructuredPrompt"): (
"langchain_core",
"prompts",
"structured",
"StructuredPrompt",
),
}
# Needed for backwards compatibility for old versions of LangChain where things
@@ -522,12 +528,6 @@ _OG_SERIALIZABLE_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
"image",
"ImagePromptTemplate",
),
("langchain", "prompts", "chat", "StructuredPrompt"): (
"langchain_core",
"prompts",
"structured",
"StructuredPrompt",
),
}
# Needed for backwards compatibility for a few versions where we serialized

View File

@@ -3,6 +3,7 @@ from typing import (
Callable,
Dict,
Iterator,
List,
Mapping,
Optional,
Sequence,
@@ -34,6 +35,15 @@ from langchain_core.runnables.base import (
class StructuredPrompt(ChatPromptTemplate):
schema_: Union[Dict, Type[BaseModel]]
@classmethod
def get_lc_namespace(cls) -> List[str]:
"""Get the namespace of the langchain object.
For example, if the class is `langchain.llms.openai.OpenAI`, then the
namespace is ["langchain", "llms", "openai"]
"""
return cls.__module__.split(".")
@classmethod
def from_messages_and_schema(
cls,

View File

@@ -40,16 +40,23 @@ def import_all_modules(package_name: str) -> dict:
def test_serializable_mapping() -> None:
# This should have had a different namespace, as it was never
# exported from the langchain module, but we keep for whoever has
# already serialized it.
to_skip = {
# This should have had a different namespace, as it was never
# exported from the langchain module, but we keep for whoever has
# already serialized it.
("langchain", "prompts", "image", "ImagePromptTemplate"): (
"langchain_core",
"prompts",
"image",
"ImagePromptTemplate",
),
# This is not exported from langchain, only langchain_core
("langchain_core", "prompts", "structured", "StructuredPrompt"): (
"langchain_core",
"prompts",
"structured",
"StructuredPrompt",
),
}
serializable_modules = import_all_modules("langchain")
missing = set(SERIALIZABLE_MAPPING).difference(