mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 05:43:55 +00:00
add old serializable mapping (#15906)
This commit is contained in:
parent
623f87c888
commit
80d41a8da3
@ -5,6 +5,7 @@ from typing import Any, Dict, List, Optional
|
|||||||
|
|
||||||
from langchain_core._api import beta
|
from langchain_core._api import beta
|
||||||
from langchain_core.load.mapping import (
|
from langchain_core.load.mapping import (
|
||||||
|
OG_SERIALIZABLE_MAPPING,
|
||||||
OLD_PROMPT_TEMPLATE_FORMATS,
|
OLD_PROMPT_TEMPLATE_FORMATS,
|
||||||
SERIALIZABLE_MAPPING,
|
SERIALIZABLE_MAPPING,
|
||||||
)
|
)
|
||||||
@ -12,7 +13,11 @@ from langchain_core.load.serializable import Serializable
|
|||||||
|
|
||||||
DEFAULT_NAMESPACES = ["langchain", "langchain_core", "langchain_community"]
|
DEFAULT_NAMESPACES = ["langchain", "langchain_core", "langchain_community"]
|
||||||
|
|
||||||
ALL_SERIALIZABLE_MAPPINGS = {**SERIALIZABLE_MAPPING, **OLD_PROMPT_TEMPLATE_FORMATS}
|
ALL_SERIALIZABLE_MAPPINGS = {
|
||||||
|
**SERIALIZABLE_MAPPING,
|
||||||
|
**OLD_PROMPT_TEMPLATE_FORMATS,
|
||||||
|
**OG_SERIALIZABLE_MAPPING,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Reviver:
|
class Reviver:
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
from typing import Dict, Tuple
|
||||||
|
|
||||||
# First value is the value that it is serialized as
|
# First value is the value that it is serialized as
|
||||||
# Second value is the path to load it from
|
# Second value is the path to load it from
|
||||||
SERIALIZABLE_MAPPING = {
|
SERIALIZABLE_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
|
||||||
("langchain", "schema", "messages", "AIMessage"): (
|
("langchain", "schema", "messages", "AIMessage"): (
|
||||||
"langchain_core",
|
"langchain_core",
|
||||||
"messages",
|
"messages",
|
||||||
@ -477,9 +479,44 @@ SERIALIZABLE_MAPPING = {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Needed for backwards compatibility for old versions of LangChain where things
|
||||||
|
# Were in different place
|
||||||
|
OG_SERIALIZABLE_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
|
||||||
|
("langchain", "schema", "AIMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"ai",
|
||||||
|
"AIMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "ChatMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"chat",
|
||||||
|
"ChatMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "FunctionMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"function",
|
||||||
|
"FunctionMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "HumanMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"human",
|
||||||
|
"HumanMessage",
|
||||||
|
),
|
||||||
|
("langchain", "schema", "SystemMessage"): (
|
||||||
|
"langchain_core",
|
||||||
|
"messages",
|
||||||
|
"system",
|
||||||
|
"SystemMessage",
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
# Needed for backwards compatibility for a few versions where we serialized
|
# Needed for backwards compatibility for a few versions where we serialized
|
||||||
# with langchain_core
|
# with langchain_core
|
||||||
OLD_PROMPT_TEMPLATE_FORMATS = {
|
OLD_PROMPT_TEMPLATE_FORMATS: Dict[Tuple[str, ...], Tuple[str, ...]] = {
|
||||||
(
|
(
|
||||||
"langchain_core",
|
"langchain_core",
|
||||||
"prompts",
|
"prompts",
|
||||||
|
Loading…
Reference in New Issue
Block a user