Code
The following code creates a function that takes a text string and a target language, then returns a translation result: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.