boundless-lifeguard-61788
10/22/2024, 8:03 PMjolly-florist-66728
10/22/2024, 8:03 PMboundless-lifeguard-61788
10/22/2024, 8:04 PMboundless-lifeguard-61788
10/22/2024, 8:05 PMjolly-florist-66728
10/22/2024, 8:05 PMboundless-lifeguard-61788
10/22/2024, 8:05 PMjolly-florist-66728
10/22/2024, 8:05 PMfrom enum import Enum
class Coffee(Enum):
ESPRESSO = "espresso"
AMERICANO = "americano"
LATTE = "latte"
CAPPUCCINO = "cappuccino"
2. Create Tasks and Workflows: Use the Enum as an input parameter in your tasks and workflows. Flytekit will automatically handle the conversion and ensure that only the predefined values are accepted.
from flytekit import task, workflow
@task
def take_order(coffee: str) -> Coffee:
return Coffee(coffee)
@task
def prep_order(coffee_enum: Coffee) -> str:
return f"Preparing {coffee_enum.value} ..."
@workflow
def coffee_maker(coffee: str) -> str:
coffee_enum = take_order(coffee=coffee)
return prep_order(coffee_enum=coffee_enum)
@workflow
def coffee_maker_enum(coffee_enum: Coffee) -> str:
return prep_order(coffee_enum=coffee_enum)
3. Run the Workflow: You can execute the workflow and pass the Enum value as a string. The Flyte UI will display a dropdown list for the Enum input, allowing users to select from the predefined options.
pyflyte run \
<https://raw.githubusercontent.com/flyteorg/flytesnacks/master/examples/data_types_and_io/data_types_and_io/enum_type.py> \
coffee_maker_enum --coffee_enum="latte"
This setup ensures that users can only select from the specified Enum values, providing a controlled input mechanism through a dropdown list in the Flyte UI.
Sources:
- Enum type — Flyte
- Flytesnacks example 👍 1 button 👎 0 button 💡 Hint: Mention @ancient-wolf-19325 in the thread for followups.boundless-lifeguard-61788
10/22/2024, 9:18 PMjolly-florist-66728
10/22/2024, 9:18 PM