Skip to content

Commit

Permalink
core[patch]: fix init of RunnableAssign (langchain-ai#26903)
Browse files Browse the repository at this point in the history
Example in API ref currently raises ValidationError.

Resolves langchain-ai#26862
  • Loading branch information
ccurme authored Oct 1, 2024
1 parent f758319 commit 9d10151
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libs/core/langchain_core/runnables/passthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def add_ten(x: Dict[str, int]) -> Dict[str, int]:
# 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]
Expand Down
12 changes: 12 additions & 0 deletions libs/core/tests/unit_tests/runnables/test_runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
ConfigurableFieldSingleOption,
RouterRunnable,
Runnable,
RunnableAssign,
RunnableBinding,
RunnableBranch,
RunnableConfig,
Expand Down Expand Up @@ -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}}

0 comments on commit 9d10151

Please sign in to comment.