bumpy-match-83743
08/01/2024, 10:01 PMancient-wolf-19325
08/01/2024, 10:02 PMfrom flytekit import task, workflow
import typing
# Task to double an integer
@task
def double(x: int) -> int:
return x * 2
# Task to sum a list of integers
@task
def sum_list(numbers: typing.List[int]) -> int:
return sum(numbers)
# Workflow to orchestrate the tasks
@workflow
def double_and_sum_workflow(numbers: typing.List[int]) -> int:
doubled_numbers = [double(x=n) for n in numbers]
return sum_list(numbers=doubled_numbers)
# Example execution
if __name__ == "__main__":
result = double_and_sum_workflow(numbers=[1, 2, 3, 4])
print(f"Result: {result}")
In this example:
- The double
task takes an integer and returns its double.
- The sum_list
task takes a list of integers and returns their sum.
- The double_and_sum_workflow
workflow takes a list of integers, applies the double
task to each integer, and then sums the results using the sum_list
task.
Would you like more details on any specific part of this workflow?
Sources:
- Flyte Task and Workflow Definition
- Flyte Customizing Task Resources 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.bumpy-match-83743
08/01/2024, 10:53 PMhttps://files.slack.com/files-pri/TN89P6GGK-F07FUQHLWN4/image.png▾