HARPA.AI
LIBRARYUSE CASESGUIDESAI COMMANDSBLOG

Conditions and Jumps

CONTENTS

# Conditions

Conditions allow switching steps ON and OFF based on user input and parameter values. Any step may declare a condition property.

To add a Condition to a Command Step, click the diamond-shaped button at the top of the Step:

And the following ones are supported:

  • x = y (Check if X equals to Y)
  • x != y (Check if X is not equal to Y)
  • x > y or x < y (Cast X and Y to number, check if X is greater / less than Y)
  • x >= y or x <= y (Cast X and Y to number, check if X is greater / less or equal Y)
  • x =~ y (Check if X matches regex Y)

Both X and Y may be parameters:

  • {{x}} - check if X is not empty.
  • {{x}} = - check if X is empty.
  • {{x}} = true - check if {{x}} parameter value is "true".

Multiple conditions can be set at once. For example, the SAY step below will run if English is set as the {{language}}, and the "translate" option was previously chosen as the {{option}} parameter value.

Operators must be surrounded with spaces, for example:

Incorrect: {{x}}=1 Correct: {{x}} = 1

ChatML engine computes the left and the right part of condition before performing a step. If x or y is a parameter name, it is substituted with the parameter value.

When comparing strings with = and != commands, strings are compared case-insensitively.

# How to use conditions and jumps

Let's explore how to write a custom command that utilizes jumps and conditions to check grammar of a selected text.

  1. Create a custom command in HARPA. Add the first GPT step:

Prompt:

Please ignore all previous instructions.
I want you to only respond in {{language}}.

Act as a professional editor, specializing in grammar and syntax
correction. Your task is to examine the given text and fix any grammatical
or syntactical errors without altering the original style and tone. Change
as little as possible to make it correct, and ensure it's well written.

[TEXT TO CORRECT]:
{{selection}}

Corrected Text:

Since this prompt only works when text is selected on the page, it makes sense to add the condition to check if {{selection}} is not empty: {{selection}}

  1. In such a case, it makes sense to add a STOP step that will be executed otherwise, if {{selection}} is Empty:

  1. Add the ASK step with some next options:
- label: ⛔️ STOP
  value: stop
- label: ⬆️ EXPAND
  value: expand
- label: ⬇️ SHORTEN
  value: shorten
- label: ♻️ NEW TEXT

  1. Next, we need to create 3 Steps that will correspond to these options:
  • In the first case, it will be a STOP step with the condition: {{option}} = stop

  • In the second case, it will be a GPT step with the condition: {{option}} = expand
  • In the third case, it will be a GPT step with the condition: {{option}} = shorten

NOTE: There is no need to create a fourth STEP, since we did not specify a value for the button with "♻️ NEW TEXT", which means that nothing will be sent to the chat, and the command will proceed to the next step.

  1. At the end, add the JUMP step that will jump to the beginning of the command to create a loop.

For this, you need to add a LABEL for the first step of the command, for example, "START".

After all actions on one selected text, a JUMP will occur to the very first GPT step of the custom command. For example, there could be scenarios like:

  • grammar check > text expansion > Jump to Start
  • grammar check > stop
  • grammar check > "♻️ NEW TEXT" > Jump to Start

In the proposed scenario, remember to highlight some new text on the page before clicking the new menu button, otherwise, after the JUMP step, the previously selected text will be processed again.

NEXT POST
Contact us
HomeUse CasesGuidesPrivacy PolicyTerms of Service