Skip to content

Commit dc387cf

Browse files
committed
MBS-10621: Use constants for default endpoints in openai tools
1 parent 37fd41f commit dc387cf

File tree

9 files changed

+16
-9
lines changed

9 files changed

+16
-9
lines changed

tools/chatgpt/classes/connector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3737
*/
3838
class connector extends \local_ai_manager\base_connector {
39+
40+
public const DEFAULT_OPENAI_COMPLETIONS_ENDPOINT = 'https://api.openai.com/v1/chat/completions';
41+
3942
#[\Override]
4043
public function get_models_by_purpose(): array {
4144
$chatgptmodels =
@@ -177,7 +180,7 @@ protected function get_headers(): array {
177180

178181
#[\Override]
179182
protected function get_endpoint_url(): string {
180-
return $this->instance->get_endpoint() ?: 'https://api.openai.com/v1/chat/completions';
183+
return $this->instance->get_endpoint() ?: self::DEFAULT_OPENAI_COMPLETIONS_ENDPOINT;
181184
}
182185

183186
#[\Override]

tools/chatgpt/classes/instance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class instance extends base_instance {
3434
protected function extend_form_definition(\MoodleQuickForm $mform): void {
3535
aitool_option_temperature::extend_form_definition($mform, ['o1', 'o1-mini', 'o3', 'o3-mini', 'o4-mini']);
3636
aitool_option_azure::extend_form_definition($mform);
37-
$defaultendpoint = 'https://api.openai.com/v1/chat/completions';
37+
$defaultendpoint = connector::DEFAULT_OPENAI_COMPLETIONS_ENDPOINT;
3838
$insertat = $mform->elementExists('useglobalapikey') ? 'useglobalapikey' : 'apikey';
3939
$mform->insertElementBefore(
4040
$mform->createElement(

tools/chatgpt/tests/connector_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private function make_connector(string $endpoint): connector {
5454
*/
5555
public function test_get_endpoint_url_returns_default_when_empty(): void {
5656
$this->assertEquals(
57-
'https://api.openai.com/v1/chat/completions',
57+
connector::DEFAULT_OPENAI_COMPLETIONS_ENDPOINT,
5858
$this->call_get_endpoint_url($this->make_connector(''))
5959
);
6060
}

tools/dalle/classes/connector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3636
*/
3737
class connector extends base_connector {
38+
39+
public const DEFAULT_DALLE_COMPLETIONS_ENDPOINT = 'https://api.openai.com/v1/images/generations';
3840
#[\Override]
3941
public function get_models_by_purpose(): array {
4042
$modelsbypurpose = base_purpose::get_installed_purposes_array();
@@ -91,7 +93,7 @@ public function get_unit(): unit {
9193

9294
#[\Override]
9395
protected function get_endpoint_url(): string {
94-
return $this->instance->get_endpoint() ?: 'https://api.openai.com/v1/images/generations';
96+
return $this->instance->get_endpoint() ?: self::DEFAULT_DALLE_COMPLETIONS_ENDPOINT;
9597
}
9698

9799
#[\Override]

tools/dalle/classes/instance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class instance extends base_instance {
3232
#[\Override]
3333
protected function extend_form_definition(\MoodleQuickForm $mform): void {
3434
aitool_option_azure::extend_form_definition($mform);
35-
$defaultendpoint = 'https://api.openai.com/v1/images/generations';
35+
$defaultendpoint = connector::DEFAULT_DALLE_COMPLETIONS_ENDPOINT;
3636
$insertat = $mform->elementExists('useglobalapikey') ? 'useglobalapikey' : 'apikey';
3737
$mform->insertElementBefore(
3838
$mform->createElement(

tools/dalle/tests/connector_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private function make_connector(string $endpoint): connector {
4646

4747
public function test_get_endpoint_url_returns_default_when_empty(): void {
4848
$this->assertEquals(
49-
'https://api.openai.com/v1/images/generations',
49+
connector::DEFAULT_DALLE_COMPLETIONS_ENDPOINT,
5050
$this->call_get_endpoint_url($this->make_connector(''))
5151
);
5252
}

tools/openaitts/classes/connector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3333
*/
3434
class connector extends \local_ai_manager\base_connector {
35+
36+
public const DEFAULT_OPENAI_TTS_ENDPOINT = 'https://api.openai.com/v1/audio/speech';
3537
#[\Override]
3638
public function get_models_by_purpose(): array {
3739
$modelsbypurpose = base_purpose::get_installed_purposes_array();
@@ -97,7 +99,7 @@ public function get_unit(): unit {
9799

98100
#[\Override]
99101
protected function get_endpoint_url(): string {
100-
return $this->instance->get_endpoint() ?: 'https://api.openai.com/v1/audio/speech';
102+
return $this->instance->get_endpoint() ?: self::DEFAULT_OPENAI_TTS_ENDPOINT;
101103
}
102104

103105
#[\Override]

tools/openaitts/classes/instance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class instance extends base_instance {
3232
#[\Override]
3333
protected function extend_form_definition(\MoodleQuickForm $mform): void {
3434
aitool_option_azure::extend_form_definition($mform, true);
35-
$defaultendpoint = 'https://api.openai.com/v1/audio/speech';
35+
$defaultendpoint = connector::DEFAULT_OPENAI_TTS_ENDPOINT;
3636
$insertat = $mform->elementExists('useglobalapikey') ? 'useglobalapikey' : 'apikey';
3737
$mform->insertElementBefore(
3838
$mform->createElement(

tools/openaitts/tests/connector_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private function make_connector(string $endpoint): connector {
4646

4747
public function test_get_endpoint_url_returns_default_when_empty(): void {
4848
$this->assertEquals(
49-
'https://api.openai.com/v1/audio/speech',
49+
connector::DEFAULT_OPENAI_TTS_ENDPOINT,
5050
$this->call_get_endpoint_url($this->make_connector(''))
5151
);
5252
}

0 commit comments

Comments
 (0)