Skip to content

Commit 52e8379

Browse files
authored
Merge pull request #1172 from davewoloszyn/MDL-83402
[docs] AI: Update AI documentation (MDL-83402)
2 parents 0da7e83 + 8344e78 commit 52e8379

File tree

6 files changed

+466
-300
lines changed

6 files changed

+466
-300
lines changed

docs/apis/plugintypes/ai/index.md

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,56 @@ tags:
77
- Placement
88
---
99

10-
The AI subsystem in the LMS is designed to be extensible, allowing for the integration of external AI services.
11-
This is achieved through the use of AI plugins, which are divided into two types: Providers and Placements.
10+
The [AI subsystem](/apis/subsystems/ai/index.md) provides a way for developers to integrate external AI services into Moodle LMS.
1211

13-
### Placements
12+
The design of the AI subsystem features two distinct plugin types:
1413

15-
The aim of Placements is to provide a consistent UX and UI for users when they use AI backed functionality.
14+
- [Provider plugins](/apis/plugintypes/ai/provider.md)
15+
- [Placement plugins](/apis/plugintypes/ai/placement.md)
1616

17-
Placement plugins leverage the functionality of the other components of the AI subsystem.
18-
This means plugin authors can focus on how users interact with the AI functionality, without needing to
19-
implement the AI functionality itself.
17+
This design allows for independent development of each plugin. The Provider plugin is not aware of the
18+
Placement plugin, and the Placement plugin is not aware of the Provider plugin. All communication between the two plugins
19+
travels through the Manager.
2020

21-
Because Placements are LMS plugins in their own right and are not "other" types of LMS plugins,
22-
it gives great flexibility in how AI functionality is presented to users.
21+
```mermaid
22+
sequenceDiagram
23+
User->>Placement: Input action
24+
Placement->>Manager: Action data
25+
Manager->>Provider: Formatted action data
26+
Provider->>External AI: Send data
27+
External AI-->>Provider: Receive response
28+
Provider-->>Manager: Response data
29+
Manager-->>Placement: Formatted response data
30+
Placement-->>User: Action completed
31+
```
2332

24-
See the [Placements](/apis/plugintypes/ai/placement.md) documentation for more information
25-
on developing Placement plugins.
33+
### Provider plugins
2634

27-
### Providers
35+
Providers are the interface between the [AI subsystem](/apis/subsystems/ai/index.md) and external AI.
36+
Their focus is on formatting actions, passing them to the external AI system, and providing the response.
2837

29-
Provider plugins are the interface between the LMS AI subsystem and external AI systems.
30-
Their focus is on converting the data requested by an Action into the format needed by the
31-
external AI services API, and then correctly providing the response back from the AI
32-
in an Action Response object.
38+
Currently, Moodle supports the following AI Providers in core:
3339

34-
Because of this design the Providers that provide the AI Actions can be swapped out, mix and matched
35-
or upgraded; both without the need to update the Placement code and without the need to change the
36-
way users interact with the functionality.
40+
- OpenAI `aiprovider_openai`
41+
- Azure AI `aiprovider_azureai`
3742

3843
See the [Providers](/apis/plugintypes/ai/provider.md) documentation for more information
3944
on developing Provider plugins.
45+
46+
### Placement plugins
47+
48+
Placements provide a consistent UX and UI for users when they use AI backed functionality (e.g. generating an image).
49+
50+
Placement plugins leverage the functionality of the other components of the [AI subsystem](/apis/subsystems/ai/index.md).
51+
This means plugin authors can focus on how users interact with the AI functionality, without needing to
52+
implement the AI functionality itself.
53+
54+
Because Placements are plugins in their own right, it allows for greater flexibility in how AI functionality is presented to users.
55+
56+
Currently, Moodle supports the following AI Placements:
57+
58+
- Course Assistance `aiplacement_courseassist`
59+
- HTML Text Editor `aiplacement_editor`
60+
61+
See the [Placements](/apis/plugintypes/ai/placement.md) documentation for more information
62+
on developing Placement plugins.

docs/apis/plugintypes/ai/placement.md

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,37 @@ tags:
66
- Placement
77
---
88

9-
The aim of Placements is to provide a consistent UX and UI for users when they use AI backed functionality.
9+
Placements provide a consistent UX and UI for users when they use AI backed functionality (e.g. generating an image).
1010

11-
Placement plugins leverage the functionality of the other components of the AI subsystem.
11+
Placement plugins leverage the functionality of the other components of the [AI subsystem](/apis/subsystems/ai/index.md).
1212
This means plugin authors can focus on how users interact with the AI functionality, without needing to
1313
implement the AI functionality itself.
1414

15-
Because Placements are LMS plugins in their own right and are not "other" types of LMS plugins,
16-
it gives great flexibility in how AI functionality is presented to users.
15+
Because Placements are plugins in their own right, it allows for greater flexibility in how AI functionality is presented to users.
16+
17+
Outgoing data from the Placement plugin travels via the Manager `core_ai\manager`.
18+
The Manager is the connective tissue between the [Provider](/apis/plugintypes/ai/provider.md) and the Placement plugins.
19+
Likewise, all responses from the Provider plugin are handed back to the Manager before being passed to the Placement plugin.
1720

1821
:::warning The Golden Rule:
1922

20-
Placements DO NOT know about Providers, and Providers DO NOT know about Placements.
23+
Placements **do not** know about Providers, and Providers **do not** know about Placements.
2124
Everything should go via the Manager.
2225

2326
:::
2427

28+
## Class implementation
29+
2530
Placements are defined as classes in their own namespace according to their plugin name.
26-
The naming convention for Action classes is `aiplacement_<plugin name>`,
27-
for example: `aiplacement_editor`. With corresponding namespaces.
31+
The naming convention for a Placement class is `aiplacement_<plugin name>`.
32+
For example: `aiplacement_editor` (with a corresponding namespace).
2833

29-
Each Placement MUST inherit from the `\core_ai\placement` abstract class.
34+
Each Placement **must** inherit from the `\core_ai\placement` abstract class.
3035
They must also implement the following methods:
3136

32-
- `get_action_list(): array` This is the list of Actions that are supported by this Placement, for example the `aiplacement_editor` plugin defines this as:
37+
**`get_action_list(): array`**
38+
39+
This is the list of Actions that are supported by this Placement, for example the `aiplacement_editor` plugin defines this as:
3340

3441
```php
3542
public function get_action_list(): array {
@@ -40,17 +47,43 @@ public function get_action_list(): array {
4047
}
4148
```
4249

43-
## Capabilities and Permissions
50+
## Capabilities and permissions
51+
52+
Placements provide a way for a user to carry out an Action.
53+
Placements are responsible for determining who can use a particular Action, and where it can be used.
54+
It is not the job of Providers to determine access.
4455

45-
Placements are responsible for determining who and where a Placement (and by extension an Action can be used).
46-
It is not the job of Actions or Providers to determine access.
56+
```php
57+
$capabilities = [
58+
'aiplacement/editor:generate_image' => [
59+
'captype' => 'write',
60+
'contextlevel' => CONTEXT_COURSE,
61+
'archetypes' => [
62+
'manager' => CAP_ALLOW,
63+
'editingteacher' => CAP_ALLOW,
64+
'teacher' => CAP_ALLOW,
65+
'student' => CAP_ALLOW,
66+
],
67+
],
68+
...
69+
```
4770

48-
## Action Processing
71+
## Action processing
4972

5073
The following is the basic workflow in order for a placement to have an action processed for a user request:
5174

52-
- The Placement instantiates a new action object of type they wish to use.
53-
- The action must be instantiated and passing it the required data. Each action will define what configuration it needs. As an example:
75+
```mermaid
76+
sequenceDiagram
77+
Placement->>Manager: New action
78+
Manager->>Provider: Process action
79+
Provider->>Manager: Get response
80+
Manager->>Placement: Pass response
81+
```
82+
83+
### Step 1
84+
85+
- The Placement instantiates a new Action object of type they wish to use.
86+
- The Action must be instantiated with the required data. Each action will define what configuration it needs. As an example:
5487

5588
```php
5689
// Prepare the action.
@@ -65,65 +98,73 @@ $action = new \core_ai\aiactions\generate_image(
6598
);
6699
```
67100

68-
- The Placement then instantiates the Manager class and calls `process_action()`
69-
- passing in the configured action object:
101+
### Step 2
102+
103+
- The Placement then instantiates the Manager class `core_ai\manager`.
104+
- The Manager calls `process_action()`, passing in the configured Action object. As an example:
70105

71106
```php
72107
// Send the action to the AI manager.
73108
$manager = \core\di::get(\core_ai\manager::class);
74109
$response = $manager->process_action($action);
75110
```
76111

77-
- The process_action() method will then return a response object (instance of `responses\response_base`).
78-
- It is up to the Placement to check for success (or not) of the response and pass the result back to the
79-
user or for further processing.
112+
### Step 3
113+
114+
- The `process_action()` method then returns a response object (instance of `responses\response_base`).
115+
- It is up to the Placement to check for success/failure of the response and pass the result back to the
116+
user.
80117

81-
## Plugin Structure
118+
## Plugin structure
82119

83-
Placement plugins reside in the `ai/placement` directory.
120+
The Placement plugins reside in the `ai/placement` directory.
84121

85-
Each Placement is in a separate subdirectory and consists of a number of mandatory files and any other
86-
files the developer is going to use.
122+
Each Placement is in a separate subdirectory and consists of a number of mandatory and supportive files that will
123+
be necessary for development.
87124

88-
The following is the typical structure of a Placement plugin, using the Editor Placement as an example:
125+
<details>
126+
<summary>The typical directory layout for the Placement plugin, using the Editor Placement as an example:</summary>
89127

90-
```bash
128+
```console
91129
.
92130
├── classes
93131
│   ├── external
94132
│   │   ├── generate_image.php
95133
│   │   └── generate_text.php
96134
│   ├── placement.php
97-
│   └── privacy
98-
│   └── provider.php
135+
│   ├── privacy
136+
│   │ └── provider.php
137+
│ └── utils.php
99138
├── db
100139
│   ├── access.php
101140
│   └── services.php
102141
├── lang
103142
│   └── en
104143
│   └── aiplacement_editor.php
144+
├── tests
145+
│   └── utils_test.php
105146
└── version.php
106-
107147
```
108148

149+
</details>
150+
109151
## Settings
110152

111153
Settings for the Placement should be defined in the `settings.php` file.
112154
Each Placement plugin should create a new admin settings page using `core_ai\admin\admin_settingspage_provider` class.
113155

114-
This is the same as for Provider plugins, for example:
156+
This is the same for Provider plugins, for example:
115157

116158
```php
117159
use core_ai\admin\admin_settingspage_provider;
118160

119161
if ($hassiteconfig) {
120162
// Placement specific settings heading.
121163
$settings = new admin_settingspage_provider(
122-
'aiprovider_openai',
123-
new lang_string('pluginname', 'aiprovider_openai'),
164+
'aiplacement_courseassist',
165+
new lang_string('pluginname', 'aiplacement_courseassist'),
124166
'moodle/site:config',
125167
true,
126168
);
127-
128169
...
129170
```

0 commit comments

Comments
 (0)