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:
ccurme 2024-10-01 14:21:54 -04:00 committed by GitHub
parent f7583194de
commit 9d10151123
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -389,7 +389,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
# 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:
super().__init__(mapper=mapper, **kwargs) # type: ignore[call-arg]

View File

@ -63,6 +63,7 @@ from langchain_core.runnables import (
ConfigurableFieldSingleOption,
RouterRunnable,
Runnable,
RunnableAssign,
RunnableBinding,
RunnableBranch,
RunnableConfig,
@ -5413,3 +5414,14 @@ def test_schema_for_prompt_and_chat_model() -> None:
"title": "PromptInput",
"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}}