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.
To reference inputs or step outputs, use the following syntax:
|Step||"Start" Step Input||Step Output||JSON Step Output|
You will helpfully see all of the available variables listed below the code input textarea.
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:
- We define question as the input variable input_question, which is defined in the start step.
- We reference the output from the first step (step_1), which is an LLM step in this example.
- We combine the question and LLM output into a single string.
- We return the combined text, which can be used in subsequent steps.
// 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;
Updated about 2 months ago