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.

Conditions are attached to steps. And the following ones are supported:

- condition: x = y
  say: Check if X equals to Y
- condition: x != y
  say: Check if X is not equal to Y
- condition: x > y
  say: Cast X and Y to number, check if X is greater than Y
- condition: x >= y
  say: Cast X and Y to number, check if X is greator or equal Y
- condition: x < y
  say: Cast X and Y to number, check if X is less than Y
- condition: x <= y
  say: Cast X and Y to number, check if X is less or equal Y
- condition: x =~ y
  say: Check if X matches regex Y

Operators must be surrounded with spaces, for example:

# incorrect
- condition: x=y

# correct
- condition: x = y

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 given text.

  1. Create a custom prompt in HARPA.

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]:
{{p1}}


Corrected Text:
  1. Export custom command into YAML and open it in a text editor, e.g. Notepad, Notepad++ or Sublime.

You'll see an unmodified command text:

meta:
  title: Grammar fix
  description: ''
  category: User
  name: 70EuZUktGLAyqzxz3csDs
steps:
  - type: ask
    message: Please provide the text that needs to be corrected for grammar and syntax.
    param: p1
    default: '{{page}}'
  - type: gpt
    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]:

      {{p1}}


      Corrected Text:
version: 1

Let's add buttons for translating text to French as well as a custom language fallback. Here's how:

  - type: ask
    label: ask-for-change
    param: change
    options:
      - { label: 'βœ… DONE', value: 'no' }
      - { label: 'πŸ‡«πŸ‡· TRANSLATE TO FRENCH', value: 'french' }
      - { label: 'πŸ› οΈ CUSTOM TRANSLATE', value: 'custom'}

  - condition: '{{change}} = no'
    type: stop

  - condition: '{{change}} = french'
    type: gpt
    prompt: >-
      Translate this text to French.

      Translated text:

  - condition: '{{change}} = custom'
    type: ask
    param: translate
    message: >
      Please specify target language:

  - condition: '{{change}} = custom'
    type: gpt
    prompt: >-
      Please translate the answer you have written into the language
      I will specify below. Do not change the wording of the text;
      I only need the translation.

      [LANGUAGE]: {{translate}}

      Translated text:

  - type: jump
    to: ask-for-change
  1. We can import the command back into HARPA and test it.

# Explanation

We added an ASK step which contains 3 options. These options are rendered in chat as buttons:

  - type: ask
    label: ask-for-change
    param: change
    options:
      - { label: 'βœ… DONE', value: 'no' }
      - { label: 'πŸ‡«πŸ‡· TRANSLATE TO FRENCH', value: 'french' }
      - { label: 'πŸ› οΈ CUSTOM TRANSLATE', value: 'custom'}

Next, we added steps for three possible paths:

  • If user presses βœ… DONE, the prompt stops. Similar to ESC button.
- condition: '{{change}} = no'
  type: stop
  • French translation is performed through GPT step, which contains a short prompt:
- condition: '{{change}} = french'
  type: gpt
  prompt: >-
  	Translate this text to French.

  	Translated text:
  • Translation into any other language is performed through 2 steps: ASK and GPT. First, we ask for the language to be stored in the "translate" parameter, then you give the command to GPT to translate the text using the specified language.
  - condition: '{{change}} = custom'
    type: ask
    param: translate
    message: >
      Please specify target language:

  - condition: '{{change}} = custom'
    type: gpt
    prompt: >-
      Please translate the answer you have written into the language I will specify below. Do not change the wording of the text; I only need the translation.

      [LANGUAGE]: {{translate}}

      Translated text:
  • We specify - condition: '{{change}} = custom' for every step. An alternative option is to create a group:
- condition: '{{change}} = custom'
  type: group
  steps:
    - type: ask
      param: translate
      message: >
        Please specify target language:
    - type: gpt
      prompt: >
        Please translate the answer you have written into the language. I will specify below. Do not change the wording of the text; I only need the translation.

        [LANGUAGE]: {{translate}}

        Translated text:
  1. We added jumps, which take us to the step labelled ask-for-change. You can jump to any labelled step.
- type: jump
  to: ask-for-change
  1. Before uploading the command back to HARPA, check the validity of the YAML file. To do this, you need to copy all the text and use a YAML Validator.

If it detects any errors, they will be highlighted in the text and described below. You can fix the errors right there in the editor until you receive the message 'Valid YAML'.

  1. Done! You can import the command back into HARPA and test it.

icon

If you want to edit this command, there's no need to repeat the entire process. Just modify this YAML file and import the command again. Deleting the same command in the previous version is not required; it will automatically be replaced with the new one.

# Step silencing

Most steps log messages to chat, but can be silenced. When silenced, steps will not print any messages to chat.

NEXT POST
Contact us
HomeUse CasesGuidesPrivacy PolicyTerms of Service