Standardize Place Names
Use ControlFlow to efficiently standardize multiple place names into consistent postal addresses.
This example demonstrates how to use ControlFlow to create a task that standardizes multiple place names into consistent postal addresses in a single operation. It showcases the use of custom types and efficient batch processing.
Code
The following code creates a function that takes a list of place names and returns a list of standardized addresses:
You can use this function to standardize a list of place names:
Key concepts
This implementation showcases several important ControlFlow features:
-
Pydantic models: We use a Pydantic model (
StandardAddress
) to define the structure of our standardized addresses. This ensures that the standardization task returns well-structured, consistent results. -
Batch processing: We process a list of place names in a single task, which is more efficient than processing them individually. This is achieved by specifying
List[StandardAddress]
as theresult_type
. -
Context passing: We pass the entire list of place names as context to the task, allowing the LLM to process all inputs at once.
-
Simple task creation: We use
cf.run()
to create and execute a task in a single step, simplifying our code.
By leveraging these ControlFlow features, we create an efficient and straightforward address standardization tool. This example demonstrates how ControlFlow can be used to build AI-powered data processing workflows that handle multiple inputs in a single operation, improving performance and reducing costs.