AI integrations

 

Overview

Totara’s AI integrations grant Totara sites the ability to use AI features from external services to enhance the functionality of Totara’s product offerings. AI services are incorporated into Totara as plugins, providing specific AI features that other plugins can utilise via interactions to deliver AI capabilities within the platform. The structure of the AI plugin subsystem makes it easy for developers to:

  • Create AI plugins to offer AI features

  • Create interactions within Totara plugins to utilise AI features

image-20240114-175427.png

AI plugin subsystem

AI integrations represent experimental configurations. Given the rapid and dynamic nature of AI in today’s world, these integrations will deviate from the established Totara feature release/deprecation approach. Users should anticipate numerous disruptive alterations.

Enabling AI

To enable AI integrations on your Totara site, follow these steps:

  1. Navigate to Quick-access menu > Development > Experimental > Experimental settings.

  2. Tick the Enable AI checkbox.

  3. Click Save changes.

Turning on Enable AI setting in Experimental features.

A new Artificial intelligence section will now appear in the Development menu on the left-hand side. You can now navigate to the Artificial intelligence > Manage AI to see an overview of what’s available in the system:

  • The table lists the available plugins offering AI features. The features supported by the plugin are listed in the Supported features column.

  • Available features: This is a list of AI features defined by the AI subsystem.

  • Available interactions: This is a list of Interactions from other plugins using AI features.

Setting the default AI plugin

From the list of available plugins on the Manage AI page, click on the icon of a crossed-out eye under the Enable column to enable an AI plugin.

After the plugin has been enabled, it will be set as default in the Default column. This sets the AI plugin as the default plugin to be used when a feature is requested by an interaction.

Note that this functionality may be replaced in the future by making it possible for interactions to select which plugin should be used when using a feature.

Reporting

The usage of features by interactions is logged in the system. This can be reviewed by creating a report from the Interaction logs report source.

What are AI features?

AI features are a defined set of AI capabilities available in Totara for use by other plugins. They serve as a common ground for communication between AI plugins and other plugins that define interactions. AI plugins offer features by implementing the feature’s defined interface. Plugins implement interaction classes to utilise AI features. In these interaction classes, plugins can get features by requesting the feature’s defined interface. Currently, there is only one feature (generative prompt) available. This is intended to be shared as a proof of concept, showing an example of how features can be built.

How to create a new feature

As features are defined structures, creating a new feature can be done by following these steps:

  1. Extend the base feature class in the core_ai\feature namespace.

  2. Implement the feature’s request and response classes.

1. Extend the base feature class

Create a new abstract class in the core_ai\feature namespace extending the core_ai\feature class, and give the feature a name by implementing the get_name method.

abstract class new_feature_name extends feature { public static function get_name(): string { return "Name of new feature"; } }

2. Implement the feature’s request and response classes

This requires thinking on what the feature is about. Depending on the feature’s specification, the request class should be structured to collect and validate the input, and the response class should be structured to process and clean the result.

Generative prompt

The generative prompt is an AI capability that allows users to make requests to an AI model by providing a sequence of prompts. The AI model processes the prompts, drawing on the knowledge gained during its training, and provides a response in the form of another sequence of prompts. Each prompt has a role signifying the user role and a message.

Implementing the generative prompt feature

To implement the generative prompt in an AI plugin:

  1. Create a class extending the generative_prompt class and implement the call_api method.

  2. Process the request prompts by calling the plugin's AI model.

  3. Validate and parse the result from the AI model to an instance of the response object.

    $prompts = [ new prompt('#1 AI response'), new prompt('#2 AI response'), ]; return new response($prompts);
  4. If there's an error, return an empty list of prompts and pass the error message.

return new response([], 'error details here');

What are AI plugins?

AI plugins serve as Totara's interface for integrating AI models from various providers. By incorporating Totara's AI features, these plugins bring AI capabilities into Totara. The following is the list of preinstalled AI plugins along with their configuration settings and supported features in Totara.

Plugin

Configuration settings

Supported features

Plugin

Configuration settings

Supported features

OpenAI

  • API key*

  • Model

Generative prompt

The following OpenAI models have been tested and confirmed to be functional: gpt-3.5-turbo, gpt-4 and gpt-4o

Creating an AI plugin

Creating a new AI plugin can be completed in four steps:

  1. Create the plugin folder.

  2. Specify plugin's version information.

  3. Define the plugininfo.php class.

  4. Implement at least one AI feature.

1. Create the plugin folder

Totara’s AI plugins can be found in the integrations/ai folder. To create a plugin, create a new folder with the plugin name as the folder name in the integrations/ai folder.

2. Specify plugin's version information

According to Totara's plugin specification, all plugins must have a version.php file, where the plugin's version, component name and minimum compatible Totara version are defined. Create a version.php file in the plugin's root directory (integrations/ai/$plugin_name) and specify the information required.

3. Define the plugininfo.php class

In the plugin's folder, add a classes folder and define a plugininfo class extending the \core\plugininfo\ai class. By default, no configuration settings are defined. To provide configuration settings for the plugin, override the get_config_collection and return a config_collection containing the list of options.

Understanding the config_collection and option class

The config_collection class is used to manage AI plugin configuration settings. It is responsible for:

  • Adding admin configuration settings to the settings page

  • Getting the value of an admin’s configuration setting

  • Serialising the values of the list of configuration settings and skipping the ones marked as secure

The option class is a wrapper for admin_setting used by AI plugins. When creating an option instance, you need to pass in an instance of admin_setting. You can also mark an option as secure. When features are used by interactions, all the configuration settings are logged so they can be reported on. Marking an admin setting as secure will ensure that the value is not logged for reporting. This is used to prevent secret values from being exposed.

4. Implement at least one AI feature

AI plugins are only valid when they offer a feature that can be used by other plugins. To implement a feature, create a class extending the feature class you want to implement in the feature namespace (integrations\ai\{plugin_name}\classes\feature) and implement the call_api method. Details on the feature's request and response objects can be found in the individual feature documentation. The saved plugin's configuration can be fetched by calling the get_config() method.

Every AI plugin must implement at least one feature. Look at the integrations\ai\classes\feature namespace to see the defined features. Currently only the generative prompt feature is defined.

To implement a feature:

  1. Create the feature namespace in your plugin (integrations\ai\{plugin_name}\classes\feature).

  2. Add a class to this namespace extending the feature class you want to implement (e.g. my_prompt extends generative_prompt).

  3. Implement the call_api method. The saved configuration options can be fetched by calling the get_config() method.

Cost implications

Plugins are wrappers for AI services which come with a cost implication. The cost associated with using AI services vary. Please refer to the AI service for cost estimates of using their APIs.

What are AI interactions?

Interactions are the classes defined in Totara plugins that use AI features provided by AI plugins. The following are preinstalled interactions available in Totara.

Interaction

Description