Skip to content

Commit 719aab1

Browse files
authored
MBS-10644: Fix chatgpt azure model registration (#120)
1 parent ebaa345 commit 719aab1

3 files changed

Lines changed: 58 additions & 6 deletions

File tree

classes/base_instance.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,6 @@ final public function supported_purposes(): array {
680680
return [];
681681
}
682682
$connector = \core\di::get(connector_factory::class)->get_connector_by_connectorname($this->connector);
683-
if (!in_array($this->get_model(), $connector->get_models())) {
684-
// This typically is the case if we are using a model that is preconfigured (for example when using Azure).
685-
return array_keys($connector->get_models_by_purpose());
686-
}
687683
$purposesofcurrentmodel = [];
688684
foreach ($connector->get_models_by_purpose() as $purpose => $models) {
689685
if (in_array($this->get_model(), $models)) {

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)