Skip to content

Commit 725e8de

Browse files
author
Hannes Funk
committed
Merge remote-tracking branch 'origin/MBS-10346_Allow_blank_spaces_in_tenant' into MBS-10346_Allow_blank_spaces_in_tenant
2 parents 9c5d060 + d5f226c commit 725e8de

File tree

8 files changed

+78
-12
lines changed

8 files changed

+78
-12
lines changed

classes/base_instance.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ final public function store_formdata(stdClass $data): void {
580580
$this->set_apikey(!empty($data->apikey) ? trim($data->apikey) : '');
581581
$this->set_useglobalapikey(!empty($data->useglobalapikey));
582582
$this->set_connector($data->connector);
583-
$this->set_tenant(trim($data->tenant));
583+
$tenantvalue = trim($data->tenant);
584+
$this->set_tenant(empty($tenantvalue) ? tenant::DEFAULT_IDENTIFIER : $tenantvalue);
584585
if (empty($data->model)) {
585586
// This is only a fallback. If the connector does not support the selection of a model,
586587
// it is supposed to overwrite this default value in the extend_store_formdata function.
@@ -679,10 +680,6 @@ final public function supported_purposes(): array {
679680
return [];
680681
}
681682
$connector = \core\di::get(connector_factory::class)->get_connector_by_connectorname($this->connector);
682-
if (!in_array($this->get_model(), $connector->get_models())) {
683-
// This typically is the case if we are using a model that is preconfigured (for example when using Azure).
684-
return array_keys($connector->get_models_by_purpose());
685-
}
686683
$purposesofcurrentmodel = [];
687684
foreach ($connector->get_models_by_purpose() as $purpose => $models) {
688685
if (in_array($this->get_model(), $models)) {

classes/local/admin_setting_configdate.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ public function write_setting($data) {
5454
#[\Override]
5555
public function output_html($data, $query = '') {
5656
$default = $this->get_defaultsetting();
57-
if ($default) {
58-
$defaultinfo = userdate($default, get_string('strftimedatetime', 'langconfig'));
57+
if ($default && is_array($default)) {
58+
$defaultinfo = sprintf(
59+
'%02d.%02d.%04d %02d:%02d',
60+
$default['mday'],
61+
$default['mon'],
62+
$default['year'],
63+
$default['hours'],
64+
$default['minutes']
65+
);
5966
} else {
6067
$defaultinfo = 0;
6168
}

lang/en/local_ai_manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
$string['purposesdescription'] = 'Which of your configured AI tools should be used for which purpose?';
226226
$string['purposesheading'] = 'Purposes for {$a->role} ({$a->currentcount}/{$a->maxcount} assigned)';
227227
$string['purposeusageinfoheading'] = 'Usage of the purpose "{$a}"';
228+
$string['purposeusedbytool'] = 'This purpose is being used by the tool from which you landed on this page';
228229
$string['quotaconfig'] = 'Limits configuration';
229230
$string['quotadescription'] = 'Set the time window and the maximum number of requests per student and teacher here. After the time window expires, the number of requests will automatically reset.';
230231
$string['request_count'] = 'Request count';

settings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@
171171
'local_ai_manager/datawiperanonymizedate',
172172
get_string('datawiperanonymizedate', 'local_ai_manager'),
173173
get_string('datawiperanonymizedatedesc', 'local_ai_manager'),
174-
'1759269600'
174+
['year' => 2025, 'mon' => 10, 'mday' => 1, 'hours' => 0, 'minutes' => 0]
175175
)
176176
);
177177
$settings->add(
178178
new admin_setting_configdate(
179179
'local_ai_manager/datawiperdeletedate',
180180
get_string('datawiperdeletedate', 'local_ai_manager'),
181181
get_string('datawiperdeletedatedesc', 'local_ai_manager'),
182-
'1759269600'
182+
['year' => 2025, 'mon' => 10, 'mday' => 1, 'hours' => 0, 'minutes' => 0]
183183
)
184184
);
185185
}

styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,8 @@ body.limitcontentwidth #page-content {
206206
#page-local-ai_manager-tenant_config .instanceaddmodal a:hover .card-title {
207207
text-decoration: underline;
208208
}
209+
210+
.local_ai_manager-purposeinfo table tr.local_ai_manager-purpose-highlight {
211+
background-color: var(--bs-info-bg-subtle);
212+
color: var(--bs-info-text-emphasis);
213+
}

templates/purpose_info.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
</thead>
8383
<tbody>
8484
{{#purposes}}
85-
<tr class="{{#highlight}}table-info{{/highlight}}">
85+
<tr class="{{#highlight}}local_ai_manager-purpose-highlight{{/highlight}}"{{#highlight}} title="{{#str}}purposeusedbytool, local_ai_manager{{/str}}"{{/highlight}}>
8686
<td>
8787
<div class="d-flex flex-row justify-content-between align-items-center">
8888
<span>{{purpose}}</span>

tools/chatgpt/classes/connector.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class connector extends \local_ai_manager\base_connector {
4040
public function get_models_by_purpose(): array {
4141
$chatgptmodels =
4242
['gpt-3.5-turbo', 'gpt-4-turbo', 'gpt-4o', 'gpt-4o-mini', 'o1', 'o1-mini', 'o3', 'o3-mini', 'o4-mini'];
43-
return [
43+
$modelsbypurpose = [
4444
'chat' => $chatgptmodels,
4545
'feedback' => $chatgptmodels,
4646
'singleprompt' => $chatgptmodels,
@@ -52,7 +52,13 @@ public function get_models_by_purpose(): array {
5252
'agent' => $chatgptmodels,
5353
];
5454
foreach ($modelsbypurpose as $purpose => $models) {
55-
$modelsbypurpose[$purpose][] = aitool_option_azure::get_azure_model_name('chatgpt');
55+
// We assume that the azure models support all the purposes. This is kind of a blind guess, because in case
56+
// of azure we do not have any information which model lies behind the azure endpoint. So we will go for the less
57+
// restrictive definition, but of course it could be that there's a model behind the azure endpoint that, for example,
58+
// does not support vision (itt). In this case we let the user run into an error, but that's not avoidable right now.
59+
if (!empty($models)) {
60+
$modelsbypurpose[$purpose][] = aitool_option_azure::get_azure_model_name('chatgpt');
61+
}
5662
}
5763
return $modelsbypurpose;
5864
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 aitool_chatgpt;
18+
19+
use local_ai_manager\local\aitool_option_azure;
20+
use local_ai_manager\local\connector_factory;
21+
22+
/**
23+
* Tests for ChatGPT connector.
24+
*
25+
* @package aitool_chatgpt
26+
* @copyright 2026 ISB Bayern
27+
* @author Philipp Memmel
28+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
*/
30+
final class connector_test extends \advanced_testcase {
31+
/**
32+
* Test that the Azure model is only available for supported purposes.
33+
*
34+
* @throws \coding_exception
35+
* @covers \aitool_chatgpt\connector::get_models_by_purpose
36+
*/
37+
public function test_get_models_by_purpose_contains_azure_model_only_for_supported_purposes(): void {
38+
$connectorfactory = \core\di::get(connector_factory::class);
39+
$connector = $connectorfactory->get_connector_by_connectorname('chatgpt');
40+
$modelname = aitool_option_azure::get_azure_model_name('chatgpt');
41+
$modelsbypurpose = $connector->get_models_by_purpose();
42+
43+
foreach (['chat', 'feedback', 'singleprompt', 'translate', 'itt', 'questiongeneration', 'agent'] as $purpose) {
44+
$this->assertContains($modelname, $modelsbypurpose[$purpose]);
45+
}
46+
47+
$this->assertNotContains($modelname, $modelsbypurpose['tts']);
48+
$this->assertNotContains($modelname, $modelsbypurpose['imggen']);
49+
}
50+
}

0 commit comments

Comments
 (0)