bumpy-match-83743
06/29/2024, 4:19 PMancient-wolf-19325
06/29/2024, 4:19 PMpyflyte run
command to execute the task with the JSON payload.
Here is an example:
Step 1: Define the Task
Define a task that accepts a dictionary input.
from flytekit import task, workflow
@task
def process_data(input_data: dict) -> str:
return f"Processed data: {input_data}"
@workflow
def my_workflow(input_data: dict) -> str:
return process_data(input_data=input_data)
Step 2: Serialize the JSON Payload
Prepare the JSON payload in a file, e.g., input.json
.
{
"key1": "value1",
"key2": "value2"
}
Step 3: Run the Task
Use the pyflyte run
command to execute the workflow with the JSON payload.
pyflyte run my_script.py my_workflow --input_data input.json
This approach ensures that the JSON payload is correctly passed and processed by the Flyte task.
Would you like more detail?
Sources:
- Flyte 1.6 Release
- Flyte Issue 3004 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.bumpy-match-83743
06/29/2024, 4:21 PMancient-wolf-19325
06/29/2024, 4:21 PMpom.xml
or build.gradle
file.
<dependency>
<groupId>org.flyte</groupId>
<artifactId>flyteidl-protos</artifactId>
<version>0.4.38</version>
</dependency>
Step 2: Define the Task and Workflow in Python
Define a task that accepts a dictionary input and a workflow in Python.
from flytekit import task, workflow
@task
def process_data(input_data: dict) -> str:
return f"Processed data: {input_data}"
@workflow
def my_workflow(input_data: dict) -> str:
return process_data(input_data=input_data)
Step 3: Use FlyteAdminClient in Java
Use the FlyteAdminClient to trigger the workflow with the JSON payload.
import org.flyte.jflyte.FlyteAdminClient;
import org.flyte.jflyte.api.ExecutionCreateRequest;
import org.flyte.jflyte.api.LiteralMap;
import org.flyte.jflyte.api.Literal;
import org.flyte.jflyte.api.Scalar;
import org.flyte.jflyte.api.Primitive;
import org.flyte.jflyte.api.LiteralType;
import org.flyte.jflyte.api.SimpleType;
import org.flyte.jflyte.api.WorkflowIdentifier;
public class FlyteExample {
public static void main(String[] args) {
FlyteAdminClient client = FlyteAdminClient.create("localhost:8089");
// Create a JSON payload
Map<String, Literal> inputMap = new HashMap<>();
inputMap.put("input_data", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofString("{\"key1\":\"value1\",\"key2\":\"value2\"}"))));
LiteralMap inputs = LiteralMap.builder().literals(inputMap).build();
// Define the workflow identifier
WorkflowIdentifier workflowId = WorkflowIdentifier.builder()
.project("my_project")
.domain("development")
.name("my_workflow")
.build();
// Create the execution request
ExecutionCreateRequest request = ExecutionCreateRequest.builder()
.workflowId(workflowId)
.inputs(inputs)
.build();
// Trigger the workflow execution
client.createExecution(request);
}
}
This example demonstrates how to define a task and workflow in Python, and then use the FlyteAdminClient in Java to trigger the workflow with a JSON payload.
Would you like more detail?
Sources:
- Flyte Java SDK Exampleancient-wolf-19325
06/29/2024, 4:21 PM