https://flyte.org logo
#ask-ai
Title
# ask-ai
g

Greg Linklater

03/11/2024, 10:49 AM
@Glime how can I set default values for parameters on my workflow that can be overiden by the user at runtime?
g

Glime

03/11/2024, 10:49 AM
To set default values for parameters in your Flyte workflow that can be overridden by the user at runtime, you can utilize the
LaunchPlan
feature. Launch plans in Flyte allow you to specify default values for your workflow's inputs. These defaults can then be overridden at the time of execution if needed. Here's a basic example of how you can define a workflow with parameters, create a launch plan with default values, and how those values can be overridden at runtime: 1. Define Your Workflow with Parameters: First, define your workflow in Flyte, specifying input parameters.
Copy code
from flytekit import task, workflow  @task def my_task(a: int) -> int:     return a + 5  @workflow def my_workflow(a: int) -> int:     return my_task(a=a)
2. Create a Launch Plan with Default Values: Next, create a launch plan for your workflow, specifying default values for the parameters.
Copy code
from flytekit import LaunchPlan  my_workflow_lp = LaunchPlan.create(     "my_workflow_launch_plan",     my_workflow,     default_inputs={"a": 10} )
In this example, the default value for the parameter
a
is set to
10
. This means that if the workflow is executed using this launch plan and no value is provided for
a
, it will default to
10
. 3. Override Default Values at Runtime: When executing the workflow, you can override the default values specified in the launch plan. This can be done via the Flyte console or through the command line using
flytectl
. For example, to override the default value using
flytectl
, you would use the following command:
Copy code
flytectl create execution --project my_project --domain development --lpName my_workflow_launch_plan --inputs '{"a": 20}'
This command overrides the default value of
a
with
20
for this particular execution. It's important to note that while you can set default values for workflow inputs using launch plans, the ability to dynamically set default values (e.g., using the current date as a default value) is not directly supported. However, you can achieve dynamic behavior by setting the values programmatically within your workflow or tasks based on the conditions or logic you define.
g

Greg Linklater

03/11/2024, 10:50 AM
For anyone else reading this, the reason why I am asking is because the usual default value syntax for function definitions is not working.
🤦‍♂️ scratch that; this was due to programmer error.
5 Views