Skip to content

Commit

Permalink
add old serializable mapping (#15906)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchase17 authored Jan 11, 2024
1 parent 623f87c commit 80d41a8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
7 changes: 6 additions & 1 deletion libs/core/langchain_core/load/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

from langchain_core._api import beta
from langchain_core.load.mapping import (
OG_SERIALIZABLE_MAPPING,
OLD_PROMPT_TEMPLATE_FORMATS,
SERIALIZABLE_MAPPING,
)
from langchain_core.load.serializable import Serializable

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:
Expand Down
41 changes: 39 additions & 2 deletions libs/core/langchain_core/load/mapping.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Dict, Tuple

# First value is the value that it is serialized as
# Second value is the path to load it from
SERIALIZABLE_MAPPING = {
SERIALIZABLE_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
("langchain", "schema", "messages", "AIMessage"): (
"langchain_core",
"messages",
Expand Down Expand Up @@ -477,9 +479,44 @@
),
}

# 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
# with langchain_core
OLD_PROMPT_TEMPLATE_FORMATS = {
OLD_PROMPT_TEMPLATE_FORMATS: Dict[Tuple[str, ...], Tuple[str, ...]] = {
(
"langchain_core",
"prompts",
Expand Down

0 comments on commit 80d41a8

Please sign in to comment.