mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-05 09:25:14 +03:00
fix(core): allow deserializing RunnablePick (#39753)
This commit is contained in:
1 parent
04ae7447d7
commit
ded2a1fb3c
2 files changed
+37
No files matched your search
@@ -548,6 +548,12 @@ SERIALIZABLE_MAPPING: dict[tuple[str, ...], tuple[str, ...]] = {
|
||||
"passthrough",
|
||||
"RunnableAssign",
|
||||
),
|
||||
("langchain", "schema", "runnable", "RunnablePick"): (
|
||||
"langchain_core",
|
||||
"runnables",
|
||||
"passthrough",
|
||||
"RunnablePick",
|
||||
),
|
||||
("langchain", "schema", "runnable", "RunnableRetry"): (
|
||||
"langchain_core",
|
||||
"runnables",
|
||||
@@ -963,6 +969,12 @@ OLD_CORE_NAMESPACES_MAPPING: dict[tuple[str, ...], tuple[str, ...]] = {
|
||||
"passthrough",
|
||||
"RunnableAssign",
|
||||
),
|
||||
("langchain_core", "runnables", "passthrough", "RunnablePick"): (
|
||||
"langchain_core",
|
||||
"runnables",
|
||||
"passthrough",
|
||||
"RunnablePick",
|
||||
),
|
||||
("langchain_core", "runnables", "retry", "RunnableRetry"): (
|
||||
"langchain_core",
|
||||
"runnables",
|
||||
|
||||
@@ -23,6 +23,7 @@ from langchain_core.prompts import (
|
||||
HumanMessagePromptTemplate,
|
||||
PromptTemplate,
|
||||
)
|
||||
from langchain_core.runnables import RunnablePassthrough, RunnablePick
|
||||
from langchain_core.runnables.history import RunnableWithMessageHistory
|
||||
from langchain_core.tracers import log_stream
|
||||
from langchain_core.utils import from_env
|
||||
@@ -1233,3 +1234,27 @@ class TestInternalCallSitesUseMessages:
|
||||
'allowed_objects="messages"' in source
|
||||
or "allowed_objects='messages'" in source
|
||||
)
|
||||
|
||||
|
||||
def test_runnable_pick_roundtrips() -> None:
|
||||
"""Test `RunnablePick` can be loaded back after being dumped.
|
||||
|
||||
Regression test: `RunnablePick` reports `is_lc_serializable()` and dumps fine,
|
||||
but was missing from the deserialization mapping, so `load` rejected it while
|
||||
its siblings in the same module round-tripped.
|
||||
"""
|
||||
original = RunnablePick(keys=["a"])
|
||||
|
||||
revived = load(dumpd(original))
|
||||
|
||||
assert isinstance(revived, RunnablePick)
|
||||
assert revived.keys == ["a"]
|
||||
|
||||
|
||||
def test_chain_using_pick_roundtrips() -> None:
|
||||
"""Test a chain built with the public `.pick()` helper survives a round trip."""
|
||||
chain = RunnablePassthrough().pick(["a"])
|
||||
|
||||
revived = load(dumpd(chain))
|
||||
|
||||
assert revived.invoke({"a": 1, "b": 2}) == {"a": 1}
|
||||
Reference in new issue
Block a user