Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250706) (a6b17d8f6bd)
core_ai\provider Class Reference
Inheritance diagram for core_ai\provider:
aiprovider_azureai\provider aiprovider_ollama\provider aiprovider_openai\provider

Public Member Functions

 __construct (public bool readonly bool $enabled, public string string $name, string $config, string $actionconfig='', public null|int readonly ?int $id=null,)
 Create a new provider.
 
 add_authentication_headers (RequestInterface $request)
 Update a request to add any headers required by the provider (if needed).
 
 generate_userid (string $userid)
 Generate a user id.
 
 get_name ()
 Get the name of the provider.
 
 get_sub_actions (string $classname)
 Given an action class name, return an array of sub actions that this provider supports.
 
 is_provider_configured ()
 Check if a provider has the minimal configuration to work.
 
 is_request_allowed (aiactions\base $action)
 Check if the request is allowed by the rate limiter.
 
 to_record ()
 Convert this object to a stdClass, suitable for saving to the database.
 

Static Public Member Functions

static get_action_list ()
 Get the actions that this provider supports.
 
static get_action_setting_defaults (string $action)
 Get the default settings for an action.
 
static get_action_settings (string $action, array $customdata=[],)
 Get any action settings for this provider.
 
static initialise_action_settings ()
 Initialise the action settings array.
 

Public Attributes

array readonly array $actionconfig
 The action specific settings for this instance.
 
array readonly array $config
 The configuration for this instance.
 
string readonly string $provider
 $provider The provider used to make this instance
 

Constructor & Destructor Documentation

◆ __construct()

core_ai\provider::__construct ( public bool readonly bool $enabled,
public string string $name,
string $config,
string $actionconfig = '',
public null|int readonly ?int $id = null )

Create a new provider.

Parameters
bool$enabledWhether the gateway is enabled
string$nameThe name of the provider config.
string$configThe configuration for this instance.
string$actionconfigThe action specific settings for this instance.
int | null$idThe id of the provider in the database.
Parameters
$enabledWhether the gateway is enabled
$nameThe name of the provider config.
$idThe ID of the provider in the database, or null if it has not been persisted yet.

Member Function Documentation

◆ add_authentication_headers()

core_ai\provider::add_authentication_headers ( RequestInterface $request)

Update a request to add any headers required by the provider (if needed).

AI providers will need to override this method to add their own headers.

Parameters
RequestInterface$request
Return values
RequestInterface

Reimplemented in aiprovider_azureai\provider, aiprovider_ollama\provider, and aiprovider_openai\provider.

◆ generate_userid()

core_ai\provider::generate_userid ( string $userid)

Generate a user id.

This is a hash of the site id and user id, this means we can determine who made the request but don't pass any personal data to the AI provider.

Parameters
string$useridThe user id.
Return values
stringThe generated user id.

◆ get_action_list()

static core_ai\provider::get_action_list ( )
staticabstract

Get the actions that this provider supports.

Returns an array of action class names.

Return values
arrayAn array of action class names.

Reimplemented in aiprovider_azureai\provider, aiprovider_ollama\provider, and aiprovider_openai\provider.

◆ get_action_setting_defaults()

static core_ai\provider::get_action_setting_defaults ( string $action)
static

Get the default settings for an action.

Parameters
string$actionThe action class name.
Return values
arrayThe default settings for the action.

Reimplemented in aiprovider_azureai\provider, aiprovider_ollama\provider, and aiprovider_openai\provider.

◆ get_action_settings()

static core_ai\provider::get_action_settings ( string $action,
array $customdata = [] )
static

Get any action settings for this provider.

Parameters
string$actionThe action class name.
array$customdataThe customdata for the form.
Return values
action_settings_form|boolThe settings form for this action or false in no settings.

Reimplemented in aiprovider_azureai\provider, aiprovider_ollama\provider, and aiprovider_openai\provider.

◆ get_name()

core_ai\provider::get_name ( )

Get the name of the provider.

Return values
stringThe name of the provider.

◆ get_sub_actions()

core_ai\provider::get_sub_actions ( string $classname)

Given an action class name, return an array of sub actions that this provider supports.

Parameters
string$classnameThe action class name.
Return values
arrayAn array of supported sub actions.

◆ initialise_action_settings()

static core_ai\provider::initialise_action_settings ( )
static

Initialise the action settings array.

Return values
arrayThe initialised action settings.

◆ is_provider_configured()

core_ai\provider::is_provider_configured ( )

Check if a provider has the minimal configuration to work.

Return values
boolReturn true if configured.

Reimplemented in aiprovider_azureai\provider, aiprovider_ollama\provider, and aiprovider_openai\provider.

◆ is_request_allowed()

core_ai\provider::is_request_allowed ( aiactions\base $action)

Check if the request is allowed by the rate limiter.

Parameters
aiactions::base$actionThe action to check.
Return values
array|boolTrue on success, array of error details on failure.

◆ to_record()

core_ai\provider::to_record ( )

Convert this object to a stdClass, suitable for saving to the database.

Return values
stdClass

The documentation for this class was generated from the following file: