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
 * Plugin settings
19
 *
20
 * @package    block_openai_chat
21
 * @copyright  2024 Bryce Yoder <me@bryceyoder.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
if ($hassiteconfig) {
28
 
29
    $ADMIN->add('reports', new admin_externalpage(
30
        'openai_chat_report',
31
        get_string('openai_chat_logs', 'block_openai_chat'),
32
        new moodle_url("$CFG->wwwroot/blocks/openai_chat/report.php", ['courseid' => 1]),
33
        'moodle/site:config'
34
    ));
35
 
36
    if ($ADMIN->fulltree) {
37
 
38
        require_once($CFG->dirroot .'/blocks/openai_chat/lib.php');
39
 
40
        $type = get_type_to_display();
41
        $assistant_array = [];
42
        if ($type === 'assistant') {
43
            $assistant_array = fetch_assistants_array();
44
        }
45
 
46
        global $PAGE;
47
        $PAGE->requires->js_call_amd('block_openai_chat/settings', 'init');
48
 
49
        $settings->add(new admin_setting_configtext(
50
            'block_openai_chat/apikey',
51
            get_string('apikey', 'block_openai_chat'),
52
            get_string('apikeydesc', 'block_openai_chat'),
53
            '',
54
            PARAM_TEXT
55
        ));
56
 
57
        $settings->add(new admin_setting_configselect(
58
            'block_openai_chat/type',
59
            get_string('type', 'block_openai_chat'),
60
            get_string('typedesc', 'block_openai_chat'),
61
            'chat',
62
            ['chat' => 'chat', 'assistant' => 'assistant', 'azure' => 'azure']
63
        ));
64
 
65
        $settings->add(new admin_setting_configcheckbox(
66
            'block_openai_chat/restrictusage',
67
            get_string('restrictusage', 'block_openai_chat'),
68
            get_string('restrictusagedesc', 'block_openai_chat'),
69
            1
70
        ));
71
 
72
        $settings->add(new admin_setting_configtext(
73
            'block_openai_chat/assistantname',
74
            get_string('assistantname', 'block_openai_chat'),
75
            get_string('assistantnamedesc', 'block_openai_chat'),
76
            'Assistant',
77
            PARAM_TEXT
78
        ));
79
 
80
        $settings->add(new admin_setting_configtext(
81
            'block_openai_chat/username',
82
            get_string('username', 'block_openai_chat'),
83
            get_string('usernamedesc', 'block_openai_chat'),
84
            'User',
85
            PARAM_TEXT
86
        ));
87
 
88
        $settings->add(new admin_setting_configcheckbox(
89
            'block_openai_chat/logging',
90
            get_string('logging', 'block_openai_chat'),
91
            get_string('loggingdesc', 'block_openai_chat'),
92
 
93
        ));
94
 
95
        // Assistant settings //
96
 
97
        if ($type === 'assistant') {
98
            $settings->add(new admin_setting_heading(
99
                'block_openai_chat/assistantheading',
100
                get_string('assistantheading', 'block_openai_chat'),
101
                get_string('assistantheadingdesc', 'block_openai_chat')
102
            ));
103
 
104
            if (count($assistant_array)) {
105
                $settings->add(new admin_setting_configselect(
106
                    'block_openai_chat/assistant',
107
                    get_string('assistant', 'block_openai_chat'),
108
                    get_string('assistantdesc', 'block_openai_chat'),
109
                    count($assistant_array) ? reset($assistant_array) : null,
110
                    $assistant_array
111
                ));
112
            } else {
113
                $settings->add(new admin_setting_description(
114
                    'block_openai_chat/noassistants',
115
                    get_string('assistant', 'block_openai_chat'),
116
                    get_string('noassistants', 'block_openai_chat'),
117
                ));
118
            }
119
 
120
            $settings->add(new admin_setting_configcheckbox(
121
                'block_openai_chat/persistconvo',
122
                get_string('persistconvo', 'block_openai_chat'),
123
                get_string('persistconvodesc', 'block_openai_chat'),
124
                1
125
            ));
126
 
127
        } else {
128
 
129
            // Chat settings //
130
 
131
            if ($type === 'azure') {
132
                $settings->add(new admin_setting_heading(
133
                    'block_openai_chat/azureheading',
134
                    get_string('azureheading', 'block_openai_chat'),
135
                    get_string('azureheadingdesc', 'block_openai_chat')
136
                ));
137
 
138
                $settings->add(new admin_setting_configtext(
139
                    'block_openai_chat/resourcename',
140
                    get_string('resourcename', 'block_openai_chat'),
141
                    get_string('resourcenamedesc', 'block_openai_chat'),
142
                    "",
143
                    PARAM_TEXT
144
                ));
145
 
146
                $settings->add(new admin_setting_configtext(
147
                    'block_openai_chat/deploymentid',
148
                    get_string('deploymentid', 'block_openai_chat'),
149
                    get_string('deploymentiddesc', 'block_openai_chat'),
150
                    "",
151
                    PARAM_TEXT
152
                ));
153
 
154
                $settings->add(new admin_setting_configtext(
155
                    'block_openai_chat/apiversion',
156
                    get_string('apiversion', 'block_openai_chat'),
157
                    get_string('apiversiondesc', 'block_openai_chat'),
158
                    "2023-09-01-preview",
159
                    PARAM_TEXT
160
                ));
161
            }
162
 
163
            $settings->add(new admin_setting_heading(
164
                'block_openai_chat/chatheading',
165
                get_string('chatheading', 'block_openai_chat'),
166
                get_string('chatheadingdesc', 'block_openai_chat')
167
            ));
168
 
169
            $settings->add(new admin_setting_configtextarea(
170
                'block_openai_chat/prompt',
171
                get_string('prompt', 'block_openai_chat'),
172
                get_string('promptdesc', 'block_openai_chat'),
173
                "Below is a conversation between a user and a support assistant for a Moodle site, where users go for online learning.",
174
                PARAM_TEXT
175
            ));
176
 
177
            $settings->add(new admin_setting_configtextarea(
178
                'block_openai_chat/sourceoftruth',
179
                get_string('sourceoftruth', 'block_openai_chat'),
180
                get_string('sourceoftruthdesc', 'block_openai_chat'),
181
                '',
182
                PARAM_TEXT
183
            ));
184
        }
185
 
186
 
187
        // Advanced Settings //
188
 
189
        $settings->add(new admin_setting_heading(
190
            'block_openai_chat/advanced',
191
            get_string('advanced', 'block_openai_chat'),
192
            get_string('advanceddesc', 'block_openai_chat')
193
        ));
194
 
195
        $settings->add(new admin_setting_configcheckbox(
196
            'block_openai_chat/allowinstancesettings',
197
            get_string('allowinstancesettings', 'block_openai_chat'),
198
            get_string('allowinstancesettingsdesc', 'block_openai_chat'),
199
 
200
        ));
201
 
202
        if ($type === 'assistant') {
203
 
204
        } else {
205
            $settings->add(new admin_setting_configselect(
206
                'block_openai_chat/model',
207
                get_string('model', 'block_openai_chat'),
208
                get_string('modeldesc', 'block_openai_chat'),
209
                'text-davinci-003',
210
                get_models()['models']
211
            ));
212
 
213
            $settings->add(new admin_setting_configtext(
214
                'block_openai_chat/temperature',
215
                get_string('temperature', 'block_openai_chat'),
216
                get_string('temperaturedesc', 'block_openai_chat'),
217
                0.5,
218
                PARAM_FLOAT
219
            ));
220
 
221
            $settings->add(new admin_setting_configtext(
222
                'block_openai_chat/maxlength',
223
                get_string('maxlength', 'block_openai_chat'),
224
                get_string('maxlengthdesc', 'block_openai_chat'),
225
                500,
226
                PARAM_INT
227
            ));
228
 
229
            $settings->add(new admin_setting_configtext(
230
                'block_openai_chat/topp',
231
                get_string('topp', 'block_openai_chat'),
232
                get_string('toppdesc', 'block_openai_chat'),
233
                1,
234
                PARAM_FLOAT
235
            ));
236
 
237
            $settings->add(new admin_setting_configtext(
238
                'block_openai_chat/frequency',
239
                get_string('frequency', 'block_openai_chat'),
240
                get_string('frequencydesc', 'block_openai_chat'),
241
                1,
242
                PARAM_FLOAT
243
            ));
244
 
245
            $settings->add(new admin_setting_configtext(
246
                'block_openai_chat/presence',
247
                get_string('presence', 'block_openai_chat'),
248
                get_string('presencedesc', 'block_openai_chat'),
249
                1,
250
                PARAM_FLOAT
251
            ));
252
        }
253
    }
254
}