You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/apis/plugintypes/ai/placement.md
+74-33Lines changed: 74 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,30 +6,37 @@ tags:
6
6
- Placement
7
7
---
8
8
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).
10
10
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).
12
12
This means plugin authors can focus on how users interact with the AI functionality, without needing to
13
13
implement the AI functionality itself.
14
14
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.
17
20
18
21
:::warning The Golden Rule:
19
22
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.
21
24
Everything should go via the Manager.
22
25
23
26
:::
24
27
28
+
## Class implementation
29
+
25
30
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).
28
33
29
-
Each Placement MUST inherit from the `\core_ai\placement` abstract class.
34
+
Each Placement **must** inherit from the `\core_ai\placement` abstract class.
30
35
They must also implement the following methods:
31
36
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:
33
40
34
41
```php
35
42
public function get_action_list(): array {
@@ -40,17 +47,43 @@ public function get_action_list(): array {
40
47
}
41
48
```
42
49
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.
44
55
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
+
```
47
70
48
-
## Action Processing
71
+
## Action processing
49
72
50
73
The following is the basic workflow in order for a placement to have an action processed for a user request:
51
74
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:
54
87
55
88
```php
56
89
// Prepare the action.
@@ -65,65 +98,73 @@ $action = new \core_ai\aiactions\generate_image(
65
98
);
66
99
```
67
100
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:
0 commit comments