Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
9 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
/**
18
 * Per-block settings
19
 *
20
 * @package    block_openai_chat
21
 * @copyright  2022 Bryce Yoder <me@bryceyoder.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once($CFG->dirroot .'/blocks/openai_chat/lib.php');
26
 
27
class block_openai_chat_edit_form extends block_edit_form {
28
 
29
    protected function specific_definition($mform) {
30
        $block_id = $this->_ajaxformdata["blockid"];
31
        $type = get_type_to_display();
32
 
33
        $mform->addElement('header', 'config_header', get_string('blocksettings', 'block'));
34
 
35
        $mform->addElement('text', 'config_title', get_string('blocktitle', 'block_openai_chat'));
36
        $mform->setDefault('config_title', 'OpenAI Chat');
37
        $mform->setType('config_title', PARAM_TEXT);
38
 
39
        $mform->addElement('advcheckbox', 'config_showlabels', get_string('showlabels', 'block_openai_chat'));
40
        $mform->setDefault('config_showlabels', 1);
41
 
42
        if ($type === 'assistant') {
43
            // Assistant settings //
44
 
45
            if (get_config('block_openai_chat', 'allowinstancesettings') === "1") {
46
                $mform->addElement('select', 'config_assistant', get_string('assistant', 'block_openai_chat'), fetch_assistants_array($block_id));
47
                $mform->setDefault('config_assistant', get_config('block_openai_chat', 'assistant'));
48
                $mform->setType('config_assistant', PARAM_TEXT);
49
                $mform->addHelpButton('config_assistant', 'config_assistant', 'block_openai_chat');
50
 
51
                $mform->addElement('advcheckbox', 'config_persistconvo', get_string('persistconvo', 'block_openai_chat'));
52
                $mform->addHelpButton('config_persistconvo', 'config_persistconvo', 'block_openai_chat');
53
                $mform->setDefault('config_persistconvo', 1);
54
 
55
                $mform->addElement('textarea', 'config_instructions', get_string('config_instructions', 'block_openai_chat'));
56
                $mform->setDefault('config_instructions', '');
57
                $mform->setType('config_instructions', PARAM_TEXT);
58
                $mform->addHelpButton('config_instructions', 'config_instructions', 'block_openai_chat');
59
 
60
                $mform->addElement('text', 'config_username', get_string('username', 'block_openai_chat'));
61
                $mform->setDefault('config_username', '');
62
                $mform->setType('config_username', PARAM_TEXT);
63
                $mform->addHelpButton('config_username', 'config_username', 'block_openai_chat');
64
 
65
                $mform->addElement('text', 'config_assistantname', get_string('assistantname', 'block_openai_chat'));
66
                $mform->setDefault('config_assistantname', '');
67
                $mform->setType('config_assistantname', PARAM_TEXT);
68
                $mform->addHelpButton('config_assistantname', 'config_assistantname', 'block_openai_chat');
69
 
70
                $mform->addElement('header', 'config_adv_header', get_string('advanced', 'block_openai_chat'));
71
 
72
                $mform->addElement('text', 'config_apikey', get_string('apikey', 'block_openai_chat'));
73
                $mform->setDefault('config_apikey', '');
74
                $mform->setType('config_apikey', PARAM_TEXT);
75
                $mform->addHelpButton('config_apikey', 'config_apikey', 'block_openai_chat');
76
            }
77
 
78
        } else {
79
            // Chat settings //
80
 
81
            $mform->addElement('textarea', 'config_sourceoftruth', get_string('sourceoftruth', 'block_openai_chat'));
82
            $mform->setDefault('config_sourceoftruth', '');
83
            $mform->setType('config_sourceoftruth', PARAM_TEXT);
84
            $mform->addHelpButton('config_sourceoftruth', 'config_sourceoftruth', 'block_openai_chat');
85
 
86
            if (get_config('block_openai_chat', 'allowinstancesettings') === "1") {
87
                $mform->addElement('textarea', 'config_prompt', get_string('prompt', 'block_openai_chat'));
88
                $mform->setDefault('config_prompt', '');
89
                $mform->setType('config_prompt', PARAM_TEXT);
90
                $mform->addHelpButton('config_prompt', 'config_prompt', 'block_openai_chat');
91
 
92
                $mform->addElement('text', 'config_username', get_string('username', 'block_openai_chat'));
93
                $mform->setDefault('config_username', '');
94
                $mform->setType('config_username', PARAM_TEXT);
95
                $mform->addHelpButton('config_username', 'config_username', 'block_openai_chat');
96
 
97
                $mform->addElement('text', 'config_assistantname', get_string('assistantname', 'block_openai_chat'));
98
                $mform->setDefault('config_assistantname', '');
99
                $mform->setType('config_assistantname', PARAM_TEXT);
100
                $mform->addHelpButton('config_assistantname', 'config_assistantname', 'block_openai_chat');
101
 
102
                $mform->addElement('header', 'config_adv_header', get_string('advanced', 'block_openai_chat'));
103
 
104
                $mform->addElement('text', 'config_apikey', get_string('apikey', 'block_openai_chat'));
105
                $mform->setDefault('config_apikey', '');
106
                $mform->setType('config_apikey', PARAM_TEXT);
107
                $mform->addHelpButton('config_apikey', 'config_apikey', 'block_openai_chat');
108
 
109
                $mform->addElement('select', 'config_model', get_string('model', 'block_openai_chat'), get_models()['models']);
110
                $mform->setDefault('config_model', get_config('block_openai_chat', 'model'));
111
                $mform->setType('config_model', PARAM_TEXT);
112
                $mform->addHelpButton('config_model', 'config_model', 'block_openai_chat');
113
 
114
                $mform->addElement('text', 'config_temperature', get_string('temperature', 'block_openai_chat'));
115
                $mform->setDefault('config_temperature', 0.5);
116
                $mform->setType('config_temperature', PARAM_FLOAT);
117
                $mform->addHelpButton('config_temperature', 'config_temperature', 'block_openai_chat');
118
 
119
                $mform->addElement('text', 'config_maxlength', get_string('maxlength', 'block_openai_chat'));
120
                $mform->setDefault('config_maxlength', 500);
121
                $mform->setType('config_maxlength', PARAM_INT);
122
                $mform->addHelpButton('config_maxlength', 'config_maxlength', 'block_openai_chat');
123
 
124
                $mform->addElement('text', 'config_topp', get_string('topp', 'block_openai_chat'));
125
                $mform->setDefault('config_topp', 1);
126
                $mform->setType('config_topp', PARAM_FLOAT);
127
                $mform->addHelpButton('config_topp', 'config_topp', 'block_openai_chat');
128
 
129
                $mform->addElement('text', 'config_frequency', get_string('frequency', 'block_openai_chat'));
130
                $mform->setDefault('config_frequency', 1);
131
                $mform->setType('config_frequency', PARAM_FLOAT);
132
                $mform->addHelpButton('config_frequency', 'config_frequency', 'block_openai_chat');
133
 
134
                $mform->addElement('text', 'config_presence', get_string('presence', 'block_openai_chat'));
135
                $mform->setDefault('config_presence', 1);
136
                $mform->setType('config_presence', PARAM_FLOAT);
137
                $mform->addHelpButton('config_presence', 'config_presence', 'block_openai_chat');
138
            }
139
        }
140
    }
141
}