core[patch]: support JS message serial namespaces (#18151)

This commit is contained in:
Bagatur 2024-02-26 16:19:46 -08:00 committed by GitHub
parent c673717c2b
commit c53aa5cd37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 89 additions and 0 deletions

View File

@ -5,6 +5,7 @@ from typing import Any, Dict, List, Optional
from langchain_core._api import beta
from langchain_core.load.mapping import (
_JS_SERIALIZABLE_MAPPING,
_OG_SERIALIZABLE_MAPPING,
OLD_CORE_NAMESPACES_MAPPING,
SERIALIZABLE_MAPPING,
@ -17,6 +18,7 @@ ALL_SERIALIZABLE_MAPPINGS = {
**SERIALIZABLE_MAPPING,
**OLD_CORE_NAMESPACES_MAPPING,
**_OG_SERIALIZABLE_MAPPING,
**_JS_SERIALIZABLE_MAPPING,
}

View File

@ -879,3 +879,90 @@ OLD_CORE_NAMESPACES_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
"RunnableRetry",
),
}
_JS_SERIALIZABLE_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
("langchain_core", "messages", "AIMessage"): (
"langchain_core",
"messages",
"ai",
"AIMessage",
),
("langchain_core", "messages", "AIMessageChunk"): (
"langchain_core",
"messages",
"ai",
"AIMessageChunk",
),
("langchain_core", "messages", "BaseMessage"): (
"langchain_core",
"messages",
"base",
"BaseMessage",
),
("langchain_core", "messages", "BaseMessageChunk"): (
"langchain_core",
"messages",
"base",
"BaseMessageChunk",
),
("langchain_core", "messages", "ChatMessage"): (
"langchain_core",
"messages",
"chat",
"ChatMessage",
),
("langchain_core", "messages", "ChatMessageChunk"): (
"langchain_core",
"messages",
"chat",
"ChatMessageChunk",
),
("langchain_core", "messages", "FunctionMessage"): (
"langchain_core",
"messages",
"function",
"FunctionMessage",
),
("langchain_core", "messages", "FunctionMessageChunk"): (
"langchain_core",
"messages",
"function",
"FunctionMessageChunk",
),
("langchain_core", "messages", "HumanMessage"): (
"langchain_core",
"messages",
"human",
"HumanMessage",
),
("langchain_core", "messages", "HumanMessageChunk"): (
"langchain_core",
"messages",
"human",
"HumanMessageChunk",
),
("langchain_core", "messages", "SystemMessage"): (
"langchain_core",
"messages",
"system",
"SystemMessage",
),
("langchain_core", "messages", "SystemMessageChunk"): (
"langchain_core",
"messages",
"system",
"SystemMessageChunk",
),
("langchain_core", "messages", "ToolMessage"): (
"langchain_core",
"messages",
"tool",
"ToolMessage",
),
("langchain_core", "messages", "ToolMessageChunk"): (
"langchain_core",
"messages",
"tool",
"ToolMessageChunk",
),
}