Worklets

A worklet is a directed acyclic graph of code and model execution that is backed by an API endpoint.

Worklets are where you define your application's business logic. A worklet is a directed acyclic graph of code and model execution that is backed by an API endpoint. It allows you to think in terms of your application's business logic and flow, rather than worrying about Kubernetes, Docker, Flask, and DB instances.

Once you create a worklet, you can test it in the Baseten UI then invoke it as an API endpoint, scheduled task, or view action.

Building worklets

Worklets are composed of blocks of different types, including Code, Model, and Decision blocks, plus actions such as a Slack block.

In the example below, we want to operationalize a zero-shot classification model. The worklet receives English text as input, pre-processes it, runs the model, and stores the results in the database.

How does data flow through a worklet?

As the flow suggests, the output of each block is fed as the input to the next block. The worklet's input becomes the first block's input, and the final block's output is the complete worklet's output.

Inputs and outputs must be JSON-serializable. For instance, dicts, lists, strings, numbers, and booleans are all valid. However, each node can only take a single input, so for named parameters a dict is usually the best option.

Managing worklets

To create a new worklet, click the "+" button on the left-side worklets menu. You can immediately rename the newly created worklet, and if you change your mind you can rename it later by clicking the three dots next to the worklet to open up the menu for that worklet.

For every worklet, you can:

  • Rename: The new name will be how you refer to the worklet in the Application, but will not change how you call it via the API.

  • Clone: Create an exact copy of the worklet in the application.

  • Delete: Delete the worklet. Any associated Files and Models will not be affected, but Views that rely on the worklet may break, as will any worklets and APIs that call the deleted worklet. Carefully ensure the worklet is totally unneeded before deleting it.

Last updated