HARPA.AI
USE CASESGUIDESAI COMMANDSBLOGPRIVACY

Function Calling

CONTENTS
NAVIGATE

Function calling is available for OpenAI API and Cloud GPT connections, allowing you to instruct AI to make decisions and create complex custom AI agents.

In function calling you can describe functions and have the AI model intelligently choose to output a JSON object containing arguments to call one of the functions.

Function declarations follow the OpenAI function specifications. You can learn more on this topic by referring to these pages:

# Function calling in HARPA

In HARPA, you can declare functions in GPT steps. Function will be selected by AI based on the GPT prompt.

We recommend combining ASK and GPT steps. In the ASK step, you ask {{text}}, and in the GPT step, you send {{text}} for processing and function selection.

Within the GPT step, you can declare any number of functions as objects in an array. Your JSON object or array must be valid.

Function specification example:

{
  "name": "get_current_weather",
  "description": "Get the current weather",
  "parameters": {
    "type": "object",
    "properties": {
      "location": {
        "type": "string",
        "description": "The city and state, e.g. San Francisco, CA"
      },
      "format": {
        "type": "string",
        "enum": ["celsius", "fahrenheit"],
        "description": "The temperature unit to use. Infer this from the users location."
      }
    },
    "required": ["location", "format"]
  }
}

In this example "location" has a type of "string".

"location": {
  "type": "string",
  "description": "The city and state, e.g. San Francisco, CA",
},

And "format" is a choice of 2 options, "celsius" or "fahrenheit".

"format": {
  "type": "string",
  "enum": ["celsius", "fahrenheit"],
  "description": "The temperature unit to use. Infer this from the users location.",
},

The "enum" keyword is used to restrict a value to a fixed set of values. It must be an array with at least one element, where each element is unique.

After you have declared the functions, select how to call them:

  • None - Do not call functions.
  • Auto - AI may either call a function or provide a text answer.
  • Required - force GPT to always call the first function.

Function name is then stored in the {{gptFunc}} parameter, and arguments are stored in the {{gptArgs}}. Both can be interpreted by the command.

Once you have a function name, you can add GROUP steps to interpret each function.

Use function name to specify the GROUP condition, e.g.: {{gptFunc}} = get_current_weather

You can perform any steps or actions needed to interpret the function, such as getting the desired weather data, e.g.: {{serp query}} or {{page URL}}.

You can use arguments specified by GPT, which in the example are {{gptArgs.location}} and {{gptArgs.format}}:

This way you can interpret GPT functions and create custom tools for your AI command.

# Use Case: Learning Agent

Let's go step by step making a Spanish learning agent.

The agent will include two functions:

  • If the text is English, it will translate it to Spanish, and explain the translation.
  • If the text is Spanish, it checks it for errors.
  1. Create a custom command and add a single ASK step to prompt for text.

  1. Add a GPT step which references the text parameter. Click the "functions" button and declare 2 functions:

Functions:

[
  {
    "name": "translate",
    "description": "If I sent something in English, Translates the received English text into Spanish.",
    "parameters": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "description": "The text I sent for processing."
        }
      },
      "required": [
        "text"
      ]
    }
  },
  {
    "name": "grammar_check",
    "description": "If I sent something in Spanish, Analyzes the Spanish text and checks its grammar and spelling.",
    "parameters": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "description": "The text I sent for processing."
        }
      },
      "required": [
        "text"
      ]
    }
  }
]
  1. Create two extra groups, each handling a separate function call, and set a conditions for each group.

  1. Drill down into groups to declare GPT steps for translation and grammar checks.

Translate:

Please ignore all previous instructions.
Act as a professional Spanish teacher and grammar expert.

Concisely translate into Spanish using universally understandable words and expressions, enhance readability. Instructions:

- Firstly, show the translation to Spanish in the markdown code block.
- Secondly, briefly explain the main grammar rules and tenses applied in English in bullet points, so that I understand how you performed the translation.
- For example, if you used a word in the plural, indicate how the word formation occurs. If you used a verb in the past tense, say what it is in the infinitive and so on.
- Strictly follow the output format and do not echo my prompt.

Text for translation:
"{{gptArgs.text}}"

Follow the output format:

\```markdown
\markdown formatted translation without quotes
\```

**Brief Explanation:**
- ...

Your response:

Grammar check:

Please ignore all previous instructions.
Act as a professional Spanish teacher and grammar expert.
You are tasked with examining provided text in Spanish and highlighting the mistakes.
I want you to explain the mistakes in English, but when demonstrating the mistakes, do not change the original language of the text.

Instructions:
- Firstly, show the corrected sentence in Spanish in the markdown code block.
- Secondly, briefly explain in English the main mistakes I made in bullet points, so that I understand the rules of the Spanish language.
- Carefully evaluate the text for any grammatical, syntax and spelling errors, including incorrect verb tenses, misplaced punctuation, improper word usage, and any other mistakes that may detract from its clarity and coherence.
- Strictly follow the output format and do not echo my prompt.

Text for evaluation:
"{{gptArgs.text}}"

Follow the output format:

**Corrected text:**

\```markdown
\properly structured sentence in Spanish
\```

**List of mistakes made:**
- ...

Your response:
  1. Then test your new Spanish learning command.

NEXT POST
Contact us
HomeUse CasesGuidesPrivacy PolicyTerms of Service