RunnableBinding<RunInput extends Object?, CallOptions extends RunnableOptions, RunOutput extends Object?> class
A RunnableBinding allows you to run a Runnable object with
CallOptions
.
You can create a RunnableBinding using the Runnable.bind method.
When you call invoke on a RunnableBinding, it will invoke the
Runnable with the CallOptions
passed to bind.
Example: Attaching Stop Sequences
final openaiApiKey = Platform.environment['OPENAI_API_KEY'];
final model = ChatOpenAI(apiKey: openaiApiKey);
final promptTemplate = ChatPromptTemplate.fromTemplate(
'Tell me a joke about {foo}',
);
final chain = promptTemplate | model.bind(ChatOpenAIOptions(stop: ['\n']));
final res = await chain.invoke({'foo': 'bears'});
print(res);
// ChatResult{
// generations: [
// ChatGeneration{
// output: AIChatMessage{
// content: Why don't bears wear shoes?,
// },
// },
// ],
// usage: ...,
// modelOutput: ...,
// }
Constructors
-
RunnableBinding({required Runnable<
RunInput, CallOptions, RunOutput> bound, required CallOptions options}) -
A RunnableBinding allows you to run a Runnable object with
CallOptions
.const
Properties
-
bound
→ Runnable<
RunInput, CallOptions, RunOutput> -
The Runnable to bind.
final
- defaultOptions → CallOptions
-
The default options to use when invoking the Runnable.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- options → CallOptions
-
The
CallOptions
to bind the Runnable with.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
batch(
List< RunInput> inputs, {List<CallOptions> ? options}) → Future<List< RunOutput> > -
Batches the invocation of the Runnable on the given
inputs
.inherited -
bind(
CallOptions options) → RunnableBinding< RunInput, CallOptions, RunOutput> -
Binds the Runnable to the given
options
.inherited -
close(
) → void -
Cleans up any resources associated with it the Runnable.
override
-
getCompatibleOptions(
RunnableOptions? options) → CallOptions? -
Returns the given
options
if they are compatible with the Runnable, otherwise returnsnull
.inherited -
invoke(
RunInput input, {CallOptions? options}) → Future< RunOutput> -
Invokes the RunnableBinding 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, {CallOptions? options}) → Stream< RunOutput> -
Streams the output of invoking the Runnable on the given
input
.override -
streamFromInputStream(
Stream< RunInput> inputStream, {CallOptions? 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