Code Step

Learn how to leverage Javascript and Python in your workflow

The Code Step in AirOps Studio currently supports Javascript and Python which provides a lot of flexibility for advanced requests.

The code in a Code Step is wrapped inside a function, and the return statement is used to output results from the function. Anything that is returned will be available in subsequent steps.

Reference Inputs or Outputs in the Code Step

To reference inputs or step outputs, use the following syntax:

Step"Start" Step InputStep OutputJSON Step Output
Pythonmy_inputstep_x["output"]step_x["output"]["key"]
Javascriptmy_inputstep_x.outputstep_x.output.key

You will helpfully see all of the available variables listed below the code input textarea.

Python Code Step

Here's a Python Code Step that makes use of an input variable and the output from a previous LLM step:

# Accept 'input_question' as an input variable
question = input_question

# Get the output from a previous LLM step
llm_output = step_1['output']

# Combine the question and LLM output
combined_text = "Question: " + question + " | LLM Output: " + llm_output

# Return the combined text
return combined_text

In this example:

  1. We define question as the input variable input_question, which is defined in the start step.
  2. We reference the output from the first step (step_1), which is an LLM step in this example.
  3. We combine the question and LLM output into a single string.
  4. We return the combined text, which can be used in subsequent steps.

Javascript Code Step

An equivalent Javascript Code Step would look as follows:

// Accept 'question' as an input variable
let question = question;

// Get the output from a previous LLM step
let llm_output = step_1.output;

// Combine the question and LLM output
let combined_text = "Question: " + question + " | LLM Output: " + llm_output;

// Return the combined text
return combined_text;