Code
The following code creates a function that summarizes a given text and extracts key points. It uses ControlFlow’s task running feature and leverages Pydantic for structured output.Key concepts
This implementation showcases several important ControlFlow features that enable quick development of advanced text processing tools:-
Structured outputs: We use a Pydantic model (
Summary
) as theresult_type
to define the structure of our output. This ensures that the summarization task returns both a summary and a list of key points in a well-defined format. -
Context passing: The
context
parameter is used to pass the input text and maximum word count to the task. -
Dynamic instructions: We include the
max_words
parameter in the task instruction, allowing for flexible control over the summary length.