mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-03 02:06:33 +00:00
core[patch]: fix init of RunnableAssign (#26903)
Example in API ref currently raises ValidationError. Resolves https://github.com/langchain-ai/langchain/issues/26862
This commit is contained in:
parent
f7583194de
commit
9d10151123
@ -389,7 +389,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
|
|||||||
# returns {'input': 5, 'add_step': {'added': 15}}
|
# returns {'input': 5, 'add_step': {'added': 15}}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
mapper: RunnableParallel[dict[str, Any]]
|
mapper: RunnableParallel
|
||||||
|
|
||||||
def __init__(self, mapper: RunnableParallel[dict[str, Any]], **kwargs: Any) -> None:
|
def __init__(self, mapper: RunnableParallel[dict[str, Any]], **kwargs: Any) -> None:
|
||||||
super().__init__(mapper=mapper, **kwargs) # type: ignore[call-arg]
|
super().__init__(mapper=mapper, **kwargs) # type: ignore[call-arg]
|
||||||
|
@ -63,6 +63,7 @@ from langchain_core.runnables import (
|
|||||||
ConfigurableFieldSingleOption,
|
ConfigurableFieldSingleOption,
|
||||||
RouterRunnable,
|
RouterRunnable,
|
||||||
Runnable,
|
Runnable,
|
||||||
|
RunnableAssign,
|
||||||
RunnableBinding,
|
RunnableBinding,
|
||||||
RunnableBranch,
|
RunnableBranch,
|
||||||
RunnableConfig,
|
RunnableConfig,
|
||||||
@ -5413,3 +5414,14 @@ def test_schema_for_prompt_and_chat_model() -> None:
|
|||||||
"title": "PromptInput",
|
"title": "PromptInput",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_runnable_assign() -> None:
|
||||||
|
def add_ten(x: dict[str, int]) -> dict[str, int]:
|
||||||
|
return {"added": x["input"] + 10}
|
||||||
|
|
||||||
|
mapper = RunnableParallel({"add_step": RunnableLambda(add_ten)})
|
||||||
|
runnable_assign = RunnableAssign(mapper)
|
||||||
|
|
||||||
|
result = runnable_assign.invoke({"input": 5})
|
||||||
|
assert result == {"input": 5, "add_step": {"added": 15}}
|
||||||
|
Loading…
Reference in New Issue
Block a user