Providers
Providers are the interface between the LMS AI subsystem and external AI systems. Their focus should be on converting the data requested by an Action into the format needed by the external AI services API, and then correctly providing the response back from the AI in an Action Response object.
Placements DO NOT know about Providers, and Providers DO NOT know about Placements. Everything should go via the Manager.
Providers are defined as classes in their own namespace according to their plugin name.
The naming convention for Action classes is aiprovider_<plugin name>
,
for example: aiprovider_openai
, aiprovider_azureai
. With corresponding namespaces.
Each Provider MUST inherit from the \core_ai\provider
abstract class.
They must also implement the following methods:
get_action_list(): array
This is the list of Actions that are supported by this Provider, for example theaiprovider_openai
plugin defines this as:
public function get_action_list(): array {
return [
\core_ai\aiactions\generate_text::class,
\core_ai\aiactions\generate_image::class,
\core_ai\aiactions\summarise_text::class,
];
}
Process classes
For each action supported by the provider, the provider plugin MUST implement a process_<action>
class,
where <action>
is the name of the action. For example: process_generate_image
.
Every process action class MUST inherit from the \core_ai\process_base
abstract class.
The process action class MUST implement a process()
method. This method is responsible for
converting the data requested by an Action into the format needed by the external AI services API,
and then correctly providing the response back from the AI in an Action Response object.
The process action classes and process method are expected by the manager to exist and be callable.
As most provider plugins will support more than one action, it is recommended to create an
abstract_processor
class that inherits from the \core_ai\process_base
class and then have each
process action class inherit from this abstract class.
For example, the aiprovider_openai
plugin defines an abstract_processor
class that inherits from
the \core_ai\process_base
class and then the process_generate_image
, process_generate_text
and
process_summarise_text
classes inherit from this abstract class.
This can be visualised as follows:
Apart from this, Providers are free to define their own structure. It should be kept in mind that Providers are designed to be a "thin wrapper" around the external AI systems API. They shouldn't store data, or have their own UI elements (beyond what is required for configuration).
Plugin Structure
Provider plugins reside in the ai/provider
directory.
Each Provider is in a separate subdirectory and consists of a number of mandatory files and any other files the developer is going to use.
The following is the typical structure of a Provider plugin, using the OpenAI Provider as an example:
.
├── classes
│ ├── abstract_processor.php
│ ├── privacy
│ │ └── provider.php
│ ├── process_generate_image.php
│ ├── process_generate_text.php
│ ├── process_summarise_text.php