AI Functions

What are AI Functions?

AI Functions operate almost exactly the same way as bots do, they have all the same settings except they also take a Name and a Slug. The purpose of an AI function is to codify a specific AI behaviour into a callable function and AI functions should have prompts set up the same way as bots do.

Functions can be called via an HTTP request, or from within scripts (which themselves are callable as API endpoints).

Calling an AI Fucntion via REST:

Functions will automatically be callable on the API at the following endpoint:

POST https://Montag.your.server/api/aifunctions/call/{slug}

They require the same headers as other API calls and take an input object:

    "input": "string", 
    "session_id": "<optional>"

The session_id property is optional, when using an AI function as a webhook, Montag will return a session ID for that response, if the AI function has a conversation window maximum set, then re-playing this value back in your follow-up request will allow the function to use the history service in it’s template engine and API call (e.g. for GPT-4 APIs). Allowing for the creation of a REST-based chatbot-like functionality. for a new window, simply exclude the session ID.

Calling AI functions from a script

AI functions are callable from scripts using the montagRun built-in function:

response := montagRun("slug", "input string")