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
@@ -14,6 +14,9 @@ Incoming data to the Provider plugin arrives via the Manager `core_ai\manager`.
14
14
The Manager is the connective tissue between the Provider and the [Placement](/apis/plugintypes/ai/placement.md) plugins.
15
15
Likewise, all responses from the Provider plugin are handed back to the Manager before being passed to the Placement plugin.
16
16
17
+
A Provider plugin allows many "provider instances" to be defined, each of which can support a different set of configurations.
18
+
This facilitates having providers for specific tasks. So, you can use a more efficient model for lightweight tasks like summarisation, and a more fully featured model for text generation. Another example is defaulting to using a cheaper model with a lower token limit, and then falling back to a more expensive model if a request is too large for the default model.
19
+
17
20
:::warning The Golden Rule:
18
21
19
22
Placements **do not** know about Providers, and Providers **do not** know about Placements.
@@ -28,14 +31,17 @@ The naming convention for a Provider class is `aiprovider_<plugin name>`.
28
31
For example: `aiprovider_openai`, or `aiprovider_azureai` (with a corresponding namespace).
29
32
30
33
Each Provider **must** inherit from the `\core_ai\provider` abstract class.
34
+
35
+
### Required Methods
36
+
31
37
They must also implement the following methods:
32
38
33
39
**`get_action_list(): array`**
34
40
35
41
This is the list of Actions that are supported by this Provider, for example the `aiprovider_openai` plugin defines this as:
@@ -108,18 +114,34 @@ files the developer is going to use.
108
114
109
115
```console
110
116
.
117
+
├── amd
118
+
│ ├── build
119
+
│ │ ├── modelchooser.min.js
120
+
│ │ └── modelchooser.min.js.map
121
+
│ └── src
122
+
│ └── modelchooser.js
111
123
├── classes
112
124
│ ├── abstract_processor.php
125
+
│ ├── aimodel
126
+
│ │ ├── gpt4o.php
127
+
│ │ └── o1.php
128
+
│ ├── form
129
+
│ │ ├── action_form.php
130
+
│ │ ├── action_generate_image_form.php
131
+
│ │ └── action_generate_text_form.php
132
+
│ ├── helper.php
133
+
│ ├── hook_listener.php
113
134
│ ├── privacy
114
135
│ │ └── provider.php
115
136
│ ├── process_generate_image.php
116
137
│ ├── process_generate_text.php
117
138
│ ├── process_summarise_text.php
118
139
│ └── provider.php
140
+
├── db
141
+
│ └── hooks.php
119
142
├── lang
120
143
│ └── en
121
144
│ └── aiprovider_openai.php
122
-
├── settings.php
123
145
├── tests
124
146
│ ├── fixtures
125
147
│ │ ├── image_request_success.json
@@ -135,121 +157,137 @@ files the developer is going to use.
135
157
136
158
</details>
137
159
138
-
## Settings
160
+
## Provider Settings
161
+
162
+
Settings for the Provider are defined as a [Hook](/apis/core/hooks/index.md).
163
+
Each Provider plugin should create a new `classes/hook_listener.php` file. This file should contain a class with a static method that defines the hook callback.
164
+
create a new admin settings page using `core_ai\admin\admin_settingspage_provider` class. This class should implement a `set_form_definition_for_aiprovider_<plugin name>` method.
139
165
140
-
Settings for the Provider should be defined in the `settings.php` file.
141
-
Each Provider plugin should create a new admin settings page using `core_ai\admin\admin_settingspage_provider` class.
166
+
This method should define the settings form for the provider plugin, using the provided `mform` object.
142
167
143
168
For example, the `aiprovider_openai` plugin defines this:
144
169
145
170
```php
146
-
use core_ai\admin\admin_settingspage_provider;
147
-
148
-
if ($hassiteconfig) {
149
-
// Provider specific settings heading.
150
-
$settings = new admin_settingspage_provider(
151
-
'aiprovider_openai',
152
-
new lang_string('pluginname', 'aiprovider_openai'),
153
-
'moodle/site:config',
154
-
true,
155
-
);
156
-
...
157
-
```
171
+
namespace aiprovider_openai;
172
+
use core_ai\hook\after_ai_provider_form_hook;
173
+
174
+
class hook_listener {
175
+
176
+
/**
177
+
* Hook listener for the Open AI instance setup form.
178
+
*
179
+
* @param after_ai_provider_form_hook $hook The hook to add to the AI instance setup.
180
+
*/
181
+
public static function set_form_definition_for_aiprovider_openai(after_ai_provider_form_hook $hook): void {
0 commit comments