Convenience method for instantiating a RunnableBranch from RunnableLikes (objects, functions, or Runnables).
Each item in the input except for the last one should be a tuple with two items. The first is a "condition" RunnableLike that returns "true" if the second RunnableLike in the tuple should run.
The final item in the input should be a RunnableLike that acts as a default branch if no other branches match.
from<
RunInput = any,
RunOutput = any
>(
branches: [...BranchLike<RunInput, RunOutput>[], RunnableLike<RunInput, RunOutput>]
): RunnableBranch<RunInput, RunOutput>| Name | Type | Description |
|---|---|---|
branches* | [...BranchLike<RunInput, RunOutput>[], RunnableLike<RunInput, RunOutput>] | An array where the every item except the last is a tuple of [condition, runnable] pairs. The last item is a default runnable which is invoked if no other condition matches. |
import { RunnableBranch } from "@langchain/core/runnables";
const branch = RunnableBranch.from([
[(x: number) => x > 0, (x: number) => x + 1],
[(x: number) => x < 0, (x: number) => x - 1],
(x: number) => x
]);