microscopic-animal-17045
03/06/2025, 1:35 PMjolly-florist-66728
03/06/2025, 1:35 PMPromise
objects. You cannot directly iterate over these promises as you would with regular Python objects. Instead, you need to access each output individually by indexing into the promise. Here's an example to illustrate how you can handle multiple outputs from a task and use them as inputs for another task in a workflow:
from flytekit import task, workflow
from typing import Tuple
@task
def task1(a: int) -> Tuple[int, str]:
return a + 1, "hello"
@task
def task2(x: int, y: str) -> str:
return f"{y} {x}"
@workflow
def my_workflow(a: int) -> str:
x, y = task1(a=a) # Access the outputs individually
result = task2(x=x, y=y)
return result
if __name__ == "__main__":
print(my_workflow(a=5))
In this example, task1
returns two outputs, an integer and a string. These outputs are accessed individually using tuple unpacking (x, y = task1(a=a)
) and then passed as inputs to task2
.
Would you like more detail on any specific part?
Sources:
- Flyte documentation on task execution inside a workflow 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.microscopic-animal-17045
03/06/2025, 1:39 PMjolly-florist-66728
03/06/2025, 1:39 PMFlyteFile
and FlyteDirectory
types, which may require specific handling when used as outputs in Flyte workflows. When dealing with these types, ensure that you are correctly accessing and using them in your workflow. Here's an example to demonstrate how you can handle FlyteFile
and FlyteDirectory
outputs:
from flytekit import task, workflow
from flytekit.types.file import FlyteFile
from flytekit.types.directory import FlyteDirectory
from typing import Tuple
@task
def task1() -> Tuple[FlyteFile, FlyteDirectory]:
file_path = FlyteFile("/path/to/file.txt")
directory_path = FlyteDirectory("/path/to/directory")
return file_path, directory_path
@task
def task2(file: FlyteFile, directory: FlyteDirectory) -> str:
# Example operation using the file and directory
return f"Processed {file.path} and {directory.path}"
@workflow
def my_workflow() -> str:
file, directory = task1() # Unpack the outputs
result = task2(file=file, directory=directory)
return result
if __name__ == "__main__":
print(my_workflow())
In this example, task1
returns a FlyteFile
and a FlyteDirectory
. These are unpacked and passed to task2
, which processes them. Ensure that the paths are correctly specified and accessible in your environment.
Would you like more detail on handling FlyteFile
and FlyteDirectory
?
Sources:
- Flyte documentation on task execution inside a workflow 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.