Calc step
Discover how to use the universal Calc step in HARPA AI"
All ChatML pages
On this page
# CALC
This step allows you to:
- Set and clone parameter values.
- Extract prices, numbers, and code blocks from GPT responses.
- Utilize regular expressions to replace text in parameters.
- Increment numerical values.
- Append, update, or remove data from lists.
Add a CALC step to your custom command. Click to edit the step and get a list of available functions, organized into four groups: parameters, extraction, numbers, texts and lists.
# Parameters
Set parameter
To set a parameter value, type in value, choose parameter name and format. For example, a function to capture the current page's URL into a parameter would look like this:
Clone parameter
Use this function to make a copy of a parameter, such as gpt, or a list.
ChatML declaration
# Set parameter
- type: calc
func: set
param: saved.url
format: auto
value: '{{url}}'
# Clone parameter
- type: calc
func: clone
from: gpt
to: cloned.gpt
# Extraction
Use extraction functions to extract code blocks and data from text parameters, e.g. GPT responses.
Select the source parameter for extraction and a parameter where the extracted data will be stored.
For example, use Extract functions to extract all prices from a web page and store them in the {{prices}} parameter:
ChatML declaration
- type: calc
func: extract-data
to: prices
param: page
data: price
index: all
# Increment parameter
Use this function to increment a numerical parameter value. This can be useful if you need to count events within loops or generate unique values, such as User IDs.
ChatML declaration
- type: calc
func: increment
param: userID
delta: '1'
# Texts
The text functions within the CALC step enables you to:
- Change text case (to UPPERCASE, lowercase, Title Case, Sentence case, PascalCase, camelCase, kebab-case or underscore case). You can modify the parameter (e.g. {{text}}) or specify a different parameter where the altered text will be saved.
- Take the first / last line (Splits given parameter into lines, and takes the first/last, non-empty one).
- Split by delimiter (Splits text into a list by delimiter).
- Replace in text (Scans input by regex or text and replaces matches with a template). For instance, you can change the time format from 1:30 to "1 hour 30 minutes" like this:
- Match in text (Scans input by regex or text and extracts matched results). For example, using this function, you can find all mentions of time intervals within the text and store them in a new parameter, {{search.result}}.
ChatML declaration
# Change text case
- type: calc
func: change-case
to: text
param: text
case: upper
# Take the first line
- type: calc
func: first-line
to: first.line
param: text
# Take the last line
- type: calc
func: last-line
to: last.line
param: text
# Split by delimiter
- type: calc
func: split
to: splitted.text
param: text
delimiter: ', '
# Replace text
- type: calc
func: replace
to: text
param: text
regex: /(\d{1,2}):(\d{2})/gmi
template: $1 hours $2 minutes
# Match text
- type: calc
func: match
to: search.result
param: text
regex: /(\d{1,2}):(\d{2})/gmi
template: $1 hours $2 minutes
# Lists
HARPA AI allows you to perform a variety of operations on lists, including:
- Add list item. This function allows you to append the given {{param}} value to the end of the {{list}} parameter. You have the flexibility to change the names of the parameters used, as well as specify the position within the list where the value will be added, whether it's the at start, end, or a specific location.
- Filter list items. You can filter items in a {{list}} and perform a selected action, either excluding or retaining matched values. For example, this command can filter the list to include only the rows where 'Name = John'.
- Update list items. You can automatically modify or update the values of items in a list. For example, you can change item status from "in progress" to null.
- Merge two lists. Merge two lists either by a given field name, storing the resulting output as a new parameter. Objects with the same field value will be merged into one object. This is useful to combine data from the same source taken at different times.
ChatML declaration
# Add list item
- type: calc
func: list-add
index: last
list: list
item: param
# Filter list items
- type: calc
func: list-filter
list: list
item: param
match: '{ "name": John }'
matched: retain
# Update list items
- type: calc
func: list-update
list: list
match: '{ "status": in progress }'
prop: '{ "status": null }'
# Merge two lists
- type: calc
func: list-merge
to: merged.list
listA: a
listB: b
by: id