Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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_azureai\form;
18
 
19
use core_ai\form\action_settings_form;
20
 
21
/**
22
 * Generate text action provider settings form.
23
 *
24
 * @package    aiprovider_azureai
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_text_form extends action_settings_form {
29
    #[\Override]
30
    protected function definition() {
31
        $mform = $this->_form;
32
        $actionconfig = $this->_customdata['actionconfig']['settings'] ?? [];
33
        $returnurl = $this->_customdata['returnurl'] ?? null;
34
        $actionname = $this->_customdata['actionname'];
35
        $action = $this->_customdata['action'];
36
        $providerid = $this->_customdata['providerid'] ?? 0;
37
 
38
        // Add API deployment name.
39
        $mform->addElement(
40
            'text',
41
            'deployment',
42
            get_string("action:{$actionname}:deployment", 'aiprovider_azureai'),
43
            'maxlength="255" size="20"',
44
        );
45
        $mform->setType('deployment', PARAM_ALPHANUMEXT);
46
        $mform->addRule('deployment', null, 'required', null, 'client');
47
        $mform->setDefault('deployment', $actionconfig['deployment'] ?? '');
48
        $mform->addHelpButton('deployment', "action:{$actionname}:deployment", 'aiprovider_azureai');
49
 
50
        // Add API version.
51
        $mform->addElement(
52
            'text',
53
            'apiversion',
54
            get_string("action:{$actionname}:apiversion", 'aiprovider_azureai'),
55
            'maxlength="255" size="30"',
56
        );
57
        $mform->setType('apiversion', PARAM_ALPHANUMEXT);
58
        $mform->addRule('apiversion', null, 'required', null, 'client');
59
        $mform->setDefault('apiversion', $actionconfig['apiversion'] ?? '2024-06-01');
60
 
61
        // System Instructions.
62
        $mform->addElement(
63
            'textarea',
64
            'systeminstruction',
65
            get_string("action:{$actionname}:systeminstruction", 'aiprovider_azureai'),
66
            'wrap="virtual" rows="5" cols="20"',
67
        );
68
        $mform->setType('systeminstruction', PARAM_TEXT);
69
        $mform->setDefault('systeminstruction', $actionconfig['systeminstruction'] ?? $action::get_system_instruction());
70
        $mform->addHelpButton('systeminstruction', "action:{$actionname}:systeminstruction", 'aiprovider_azureai');
71
 
72
        if ($returnurl) {
73
            $mform->addElement('hidden', 'returnurl', $returnurl);
74
            $mform->setType('returnurl', PARAM_LOCALURL);
75
        }
76
 
77
        // Add the action class as a hidden field.
78
        $mform->addElement('hidden', 'action', $action);
79
        $mform->setType('action', PARAM_TEXT);
80
 
81
        // Add the provider class as a hidden field.
82
        $mform->addElement('hidden', 'provider', 'aiprovider_azureai');
83
        $mform->setType('provider', PARAM_TEXT);
84
 
85
        // Add the provider id as a hidden field.
86
        $mform->addElement('hidden', 'providerid', $providerid);
87
        $mform->setType('providerid', PARAM_INT);
88
 
89
        $this->set_data($actionconfig);
90
    }
91
}