Code
The following code creates a function that takes a count then returns a list of generated user profiles that match a provideresult_type
template:
Key concepts
This implementation showcases several important ControlFlow features:-
Pydantic models: We use a Pydantic model (
UserProfile
) to define the structure of our generated data. This ensures that the generation task returns well-structured, consistent results. -
Batch processing: We generate multiple user profiles in a single task, which is more efficient than generating them individually. This is achieved by specifying
List[UserProfile]
as theresult_type
. -
Context passing: We pass the desired count as context to the task, allowing the LLM to generate multiple data points based on the given parameters.