RunnableWithFallback<RunInput extends Object?, RunOutput extends Object?> class
A Runnable that can fallback to other Runnables if it fails.
This class allows for the creation of a Runnable chain where a main Runnable is attempted first, and if it fails, a sequence of fallback Runnables are tried in order. This process continues until one of the Runnables succeeds or all of them fail, in which case an exception is thrown.
You can create a RunnableWithFallback using the Runnable.withFallbacks method.
Example:
final mainChatModel = ChatOpenAI(...);
final fallbackChatModel = ChatOpenAI(...);
final chatModel = mainChatModel.withFallbacks([fallbackChatModel]);
final res = await chatModel.invoke(...);
- Inheritance
-
- Object
- Runnable<
RunInput, RunnableOptions, RunOutput> - RunnableWithFallback
- Available extensions
Constructors
-
RunnableWithFallback({required Runnable<
RunInput, RunnableOptions, RunOutput> mainRunnable, required List<Runnable< fallbacks})RunInput, RunnableOptions, RunOutput> >
Properties
- defaultOptions → RunnableOptions
-
The default options to use when invoking the Runnable.
finalinherited
-
fallbacks
→ List<
Runnable< RunInput, RunnableOptions, RunOutput> > -
A sequence of fallbacks to try if the mainRunnable fails.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
mainRunnable
→ Runnable<
RunInput, RunnableOptions, RunOutput> -
The Runnable to run first.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
batch(
List< RunInput> inputs, {List<RunnableOptions> ? options}) → Future<List< RunOutput> > -
Batches the invocation of the Runnable on the given
inputs
.override -
bind(
RunnableOptions options) → RunnableBinding< RunInput, RunnableOptions, RunOutput> -
Binds the Runnable to the given
options
.inherited -
close(
) → void -
Cleans up any resources associated with it the Runnable.
inherited
-
getCompatibleOptions(
RunnableOptions? options) → RunnableOptions? -
Returns the given
options
if they are compatible with the Runnable, otherwise returnsnull
.inherited -
invoke(
RunInput input, {RunnableOptions? options}) → Future< RunOutput> -
Invokes the Runnable on the given
input
.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pipe<
NewRunOutput extends Object?, NewCallOptions extends RunnableOptions> (Runnable< RunOutput, NewCallOptions, NewRunOutput> next) → RunnableSequence<RunInput, NewRunOutput> -
Pipes the output of this Runnable into another Runnable using a
RunnableSequence.
inherited
-
stream(
RunInput input, {RunnableOptions? options}) → Stream< RunOutput> -
Streams the output of invoking the Runnable on the given
input
.override -
streamFromInputStream(
Stream< RunInput> inputStream, {RunnableOptions? options}) → Stream<RunOutput> -
Streams the output of invoking the Runnable on the given
inputStream
.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
withFallbacks(
List< Runnable< fallbacks) → RunnableWithFallback<RunInput, RunnableOptions, RunOutput> >RunInput, RunOutput> -
Adds fallback runnables to be invoked if the primary runnable fails.
inherited
-
withRetry(
{int maxRetries = 3, FutureOr< bool> retryIf(Object e)?, List<Duration?> ? delayDurations, bool addJitter = false}) → RunnableRetry<RunInput, RunOutput> -
Adds retry logic to an existing runnable.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator |(
Runnable< RunOutput, RunnableOptions, NewRunOutput> next) → RunnableSequence<RunInput, NewRunOutput> -
Available on Runnable<
Pipes the output of this Runnable into another Runnable.RunInput, CallOptions, RunOutput> , provided by the RunnableX extension