Text Translation
Use ControlFlow to translate text from one language to another.
This example demonstrates how to use ControlFlow to create a task that translates text from one language to another. It showcases the use of custom types and context passing for language translation tasks.
Code
The following code creates a function that takes a text string and a target language, then returns a translation result:
Now we can use this function to translate text:
Key concepts
This implementation showcases several important ControlFlow features:
-
Pydantic models: We use a Pydantic model (
TranslationResult
) to define the structure of our translation result. This ensures that the translation task returns well-structured, consistent results. -
Context passing: We pass both the original text and the target language as context to the task, providing all necessary information for the translation.
By leveraging these ControlFlow features, we create an efficient and flexible text translation tool. This example demonstrates how ControlFlow can be used to build AI-powered language processing workflows that can handle translation tasks with ease.