Widgets/Logic

Sequence Widget

Sequence Widget

A "Logic" type widget. Sequence Widget executes a series of connected widgets in a specific order. It ensures that each step completes its execution before moving to the next one, making it perfect for workflows that require strict ordering of operations.

 

Inputs

  • event (DataType: Anything) Initiates the sequence execution. Any incoming event will trigger the sequence to start processing its outputs in order.

Outputs

  • 1 (DataType: Same as event input) First step in the sequence
  • 2 (DataType: Same as event input) Second step in the sequence
  • 3 (DataTypes: Same as event input) Third step in the sequence

Note: The Sequence Widget preserves the data type of the input event across all outputs. For example, if you send a number to the event input, all outputs will carry the same number to their connected widgets.

 

Examples

Basic Counter Sequence

This example demonstrates how the Sequence Widget ensures ordered execution of multiple counters:


Drag the example onto the workspace to explore and experiment!



In this example:

  1. The Button widget initiates the sequence by sending a trigger event to the Sequence widget
  2. The Sequence widget executes three Counter widgets in strict order (1 → 2 → 3), where each counter increments its value by 1
  3. Each Counter widget connects to a custom Widget Group (labeled "Sleep 1 second") that creates a 1-second pause between each counter execution
  4. The Sequence widget ensures each counter completes its increment and delay before allowing the next counter to start, demonstrating ordered execution

Note: The "Sleep 1 second" Widget Group is a custom container that includes a JavaScript script widget with await new Promise(resolve => setTimeout(resolve, 1000)) to create a 1-second delay, simulating real-world processing time between sequence steps.

 

ChatGPT Query Sequence

This example shows how to use the Sequence Widget to properly coordinate a ChatGPT query and response flow:

Note: You need to install and configure the ChatGPT Service to use this example.


Drag the example onto the workspace to explore and experiment!



In this example:

  1. The Button widget sends the text "What is the capital of France?" to the sequence
  2. The Sequence widget coordinates the ChatGPT Service interaction in two steps
    • The first output sets the query text in the ChatGPT Service
    • The second output triggers the ChatGPT Service processing by activating its "send" input port
  3. The ChatGPT Service processes the query and returns "The capital of France is Paris"
  4. The Text widget displays the response

This sequence ensures that the ChatGPT Service receives the query text before processing begins, preventing any race conditions.

 

📌 Additional Notes

  • The widget maintains the same data type across all outputs
  • Each step must complete (including any asynchronous operations) before the next step begins
  • The sequence always executes in order: 1 → 2 → 3
  • If any step in the sequence fails, subsequent steps will not execute

 

Glossary

  • Asynchronous Operations

    Operations that don't complete immediately and may take time to finish, such as network requests or file processing.

  • ChatGPT Service

    A KEMU Hub Service that provides access to OpenAI's ChatGPT AI model. It allows you to send text queries and images for analysis, receiving responses in real-time. To use this service, you must install it from the KEMU Hub and configure your OpenAI API key in the Hub Settings → Environment Variables as OPENAI_API_KEY.

  • Race Conditions

    Situations where the behavior of a system depends on the relative timing of events, which can lead to unpredictable results.

  • Sequence Execution

    The ordered processing of steps where each step must complete before the next one begins.

  • Widget Group

    A container widget that allows you to group multiple widgets together and create custom UI controls for managing their behavior.