StringOutputParser<ParserInput extends Object?> constructor
const
StringOutputParser<ParserInput extends Object?> ({
- bool reduceOutputStream = false,
Output parser that returns the output of the previous Runnable as a
String
.
ParserInput
- The type of the input to the parser.
If the input is:
null
, the parser returns an empty String.- A LLMResult, the parser returns the output String.
- A ChatResult, the parser returns the content of the output message as a String.
- A ChatMessage, the parser returns the content of the message as a String.
- A Document, the parser returns the page content as a String.
- Anything else, the parser returns the String representation of the input.
Example:
final model = ChatOpenAI(apiKey: openAiApiKey);
final promptTemplate = ChatPromptTemplate.fromTemplate(
'Tell me a joke about {topic}',
);
final chain = promptTemplate | model | StringOutputParser();
final res = await chain.invoke({'topic': 'bears'});
print(res);
// Why don't bears wear shoes? Because they have bear feet!
Implementation
const StringOutputParser({
this.reduceOutputStream = false,
}) : super(defaultOptions: const OutputParserOptions());