1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace aiprovider_openai\form;
|
|
|
18 |
|
|
|
19 |
use aiprovider_openai\aimodel\openai_base;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Generate image action provider settings form.
|
|
|
23 |
*
|
|
|
24 |
* @package aiprovider_openai
|
|
|
25 |
* @copyright 2024 Matt Porritt <matt.porritt@moodle.com>
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
*/
|
|
|
28 |
class action_generate_image_form extends action_form {
|
|
|
29 |
#[\Override]
|
|
|
30 |
protected function definition(): void {
|
|
|
31 |
parent::definition();
|
|
|
32 |
$mform = $this->_form;
|
|
|
33 |
|
|
|
34 |
$this->add_model_fields(openai_base::MODEL_TYPE_IMAGE);
|
|
|
35 |
|
|
|
36 |
// API endpoint.
|
|
|
37 |
$mform->addElement(
|
|
|
38 |
'text',
|
|
|
39 |
'endpoint',
|
|
|
40 |
get_string("action:{$this->actionname}:endpoint", 'aiprovider_openai'),
|
|
|
41 |
'maxlength="255" size="30"',
|
|
|
42 |
);
|
|
|
43 |
$mform->setType('endpoint', PARAM_URL);
|
|
|
44 |
$mform->addRule('endpoint', null, 'required', null, 'client');
|
|
|
45 |
$mform->setDefault('endpoint', $this->actionconfig['endpoint'] ?? 'https://api.openai.com/v1/images/generations');
|
|
|
46 |
|
|
|
47 |
if ($this->returnurl) {
|
|
|
48 |
$mform->addElement('hidden', 'returnurl', $this->returnurl);
|
|
|
49 |
$mform->setType('returnurl', PARAM_LOCALURL);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
// Add the action class as a hidden field.
|
|
|
53 |
$mform->addElement('hidden', 'action', $this->action);
|
|
|
54 |
$mform->setType('action', PARAM_TEXT);
|
|
|
55 |
|
|
|
56 |
// Add the provider class as a hidden field.
|
|
|
57 |
$mform->addElement('hidden', 'provider', $this->providername);
|
|
|
58 |
$mform->setType('provider', PARAM_TEXT);
|
|
|
59 |
|
|
|
60 |
// Add the provider id as a hidden field.
|
|
|
61 |
$mform->addElement('hidden', 'providerid', $this->providerid);
|
|
|
62 |
$mform->setType('providerid', PARAM_INT);
|
|
|
63 |
|
|
|
64 |
$this->set_data($this->actionconfig);
|
|
|
65 |
}
|
|
|
66 |
}
|