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_openai\form;
18
 
19
use aiprovider_openai\aimodel\openai_base;
20
 
21
/**
22
 * Generate text 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_text_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_TEXT);
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', $actionconfig['endpoint'] ?? 'https://api.openai.com/v1/chat/completions');
46
 
47
        // System Instructions.
48
        $mform->addElement(
49
            'textarea',
50
            'systeminstruction',
51
            get_string("action:{$this->actionname}:systeminstruction", 'aiprovider_openai'),
52
            'wrap="virtual" rows="5" cols="20"',
53
        );
54
        $mform->setType('systeminstruction', PARAM_TEXT);
55
        $mform->setDefault('systeminstruction', $actionconfig['systeminstruction'] ?? $this->action::get_system_instruction());
56
        $mform->addHelpButton('systeminstruction', "action:{$this->actionname}:systeminstruction", 'aiprovider_openai');
57
 
58
        if ($this->returnurl) {
59
            $mform->addElement('hidden', 'returnurl', $this->returnurl);
60
            $mform->setType('returnurl', PARAM_LOCALURL);
61
        }
62
 
63
        // Add the action class as a hidden field.
64
        $mform->addElement('hidden', 'action', $this->action);
65
        $mform->setType('action', PARAM_TEXT);
66
 
67
        // Add the provider class as a hidden field.
68
        $mform->addElement('hidden', 'provider', $this->providername);
69
        $mform->setType('provider', PARAM_TEXT);
70
 
71
        // Add the provider id as a hidden field.
72
        $mform->addElement('hidden', 'providerid', $this->providerid);
73
        $mform->setType('providerid', PARAM_INT);
74
 
75
        $this->set_data($this->actionconfig);
76
    }
77
 
78
}