RunnableMapInputStream<RunInput extends Object, RunOutput extends Object> class
A RunnableMapInputStream allows you to map the input stream to a different stream of values.
You can create a RunnableMapInputStream using the Runnable.mapInputStream static method.
When you call stream on a RunnableMapInputStream, it will take the input stream it receives and returns the output stream returned by the given inputStreamMapper function.
Example:
final model = ChatOpenAI(
apiKey: openAiApiKey,
defaultOptions: ChatOpenAIOptions(
responseFormat: ChatOpenAIResponseFormat(
type: ChatOpenAIResponseFormatType.jsonObject,
),
),
);
final parser = JsonOutputParser<ChatResult>();
final mapper = Runnable.mapInputStream((Stream<Map<String, dynamic>> inputStream) async* {
yield await inputStream.last;
});
final chain = model.pipe(parser).pipe(mapper);
final stream = chain.stream(
PromptValue.string(
'Output a list of the countries france, spain and japan and their '
'populations in JSON format. Use a dict with an outer key of '
'"countries" which contains a list of countries. '
'Each country should have the key "name" and "population"',
),
);
await stream.forEach((final chunk) => print('$chunk|'));
// {countries: [{name: France, population: 65273511}, {name: Spain, population: 46754778}, {name: Japan, population: 126476461}]}|
- Inheritance
-
- Object
- Runnable<
RunInput, RunnableOptions, RunOutput> - RunnableMapInputStream
- Available extensions
Constructors
-
RunnableMapInputStream(Stream<
RunOutput> inputStreamMapper(Stream<RunInput> inputStream)) -
A RunnableMapInputStream allows you to map the input stream to a
different stream of values.
const
Properties
- defaultOptions → RunnableOptions
-
The default options to use when invoking the Runnable.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
inputStreamMapper
→ Stream<
RunOutput> Function(Stream<RunInput> inputStream) -
The stream transformer to run.
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
.inherited -
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 RunnableMapInputStream 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
input
through the RunnableMapInputStream.override -
streamFromInputStream(
Stream< RunInput> inputStream, {RunnableOptions? options}) → Stream<RunOutput> -
Streams the
inputStream
through the RunnableMapInputStream.override -
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