RunnableMapInputStream<RunInput extends Object, RunOutput extends Object> constructor
const
RunnableMapInputStream<RunInput extends Object, RunOutput extends Object> ()
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}]}|
Implementation
const RunnableMapInputStream(this.inputStreamMapper)
: super(defaultOptions: const RunnableOptions());