ToolsOutputParser constructor
ToolsOutputParser({
- bool reduceOutputStream = false,
A parser that returns the list of tool calls returned by the model.
When streaming, the parser attempts to “auto-complete” the partial json from each chunk into a valid state.
Example:
const tool = ToolSpec(
name: 'joke',
description: 'A joke',
inputJsonSchema: {
'type': 'object',
'properties': {
'setup': {
'type': 'string',
'description': 'The setup for the joke',
},
'punchline': {
'type': 'string',
'description': 'The punchline to the joke',
},
},
'required': ['location', 'punchline'],
},
);
final promptTemplate = ChatPromptTemplate.fromTemplate(
'tell me a long joke about {foo}',
);
final chat = ChatOpenAI(
apiKey: openaiApiKey,
defaultOptions: ChatOpenAIOptions(
temperature: 0,
),
).bind(
ChatOpenAIOptions(
tools: [tool],
toolChoice: ChatToolChoice.forced(name: 'joke'),
),
);
final outputParser = ToolsOutputParser();
final chain = promptTemplate.pipe(chat).pipe(outputParser);
final res = await chain.invoke({'foo': 'bears'});
print(res);
// [ParsedToolCall{
// id: call_5TU1iYgYO3Z81eAuTe7J23f7,
// name: joke,
// arguments: {
// setup: Why don't bears like fast food restaurants?,
// punchline: Because they can't bear the wait!
// },
// }]
Implementation
ToolsOutputParser({
this.reduceOutputStream = false,
}) : super(
defaultOptions: const OutputParserOptions(),
);