RunnableRouter<RunInput extends Object, RunOutput extends Object> constructor

const RunnableRouter<RunInput extends Object, RunOutput extends Object>(
  1. FutureOr<Runnable<RunInput, RunnableOptions, RunOutput>> router(
    1. RunInput input,
    2. RunnableOptions? options
    )
)

A RunnableRouter takes the input it receives and routes it to the runnable returned by the router function.

You can create a RunnableRouter using the Runnable.fromRouter static method.

When you call invoke on a RunnableRouter, it will invoke the router function, passing the input to it. Then, the returned runnable will be invoked with the input.

Example:

final router = Runnable.fromRouter((Map<String, dynamic> input, _) {
  return switch(input['topic'] as String) {
    'langchain' => langchainChain,
    'anthropic' => anthropicChain,
    _ => generalChain,
  };
});

final fullChain = Runnable.fromMap({
      'topic': classificationChain,
      'question': Runnable.getItemFromMap('question'),
    }).pipe(router);

final res2 = await fullChain.invoke({
  'question': 'how do I use Anthropic?',
});
print(res2);
// As Dario Amodei told me, using Anthropic is a straightforward process that...

Implementation

const RunnableRouter(this.router)
    : super(defaultOptions: const RunnableOptions());