diff --git a/ai/provider/openai/classes/aimodel/dalle3.php b/ai/provider/openai/classes/aimodel/dalle3.php index f35124448df..93d5d918e6d 100644 --- a/ai/provider/openai/classes/aimodel/dalle3.php +++ b/ai/provider/openai/classes/aimodel/dalle3.php @@ -43,7 +43,7 @@ class dalle3 extends base implements openai_base { } #[\Override] - public function model_type(): int { - return self::MODEL_TYPE_IMAGE; + public function model_type(): array { + return [self::MODEL_TYPE_IMAGE]; } } diff --git a/ai/provider/openai/classes/aimodel/gpt4o.php b/ai/provider/openai/classes/aimodel/gpt4o.php index fceb5118264..07e89eef1ad 100644 --- a/ai/provider/openai/classes/aimodel/gpt4o.php +++ b/ai/provider/openai/classes/aimodel/gpt4o.php @@ -81,7 +81,7 @@ class gpt4o extends base implements openai_base { } #[\Override] - public function model_type(): int { - return self::MODEL_TYPE_TEXT; + public function model_type(): array { + return [self::MODEL_TYPE_TEXT]; } } diff --git a/ai/provider/openai/classes/aimodel/o1.php b/ai/provider/openai/classes/aimodel/o1.php index 34560e7cdfa..3a5c2bdc6d6 100644 --- a/ai/provider/openai/classes/aimodel/o1.php +++ b/ai/provider/openai/classes/aimodel/o1.php @@ -41,7 +41,7 @@ class o1 extends gpt4o { } #[\Override] - public function model_type(): int { - return self::MODEL_TYPE_TEXT; + public function model_type(): array { + return [self::MODEL_TYPE_TEXT]; } } diff --git a/ai/provider/openai/classes/aimodel/openai_base.php b/ai/provider/openai/classes/aimodel/openai_base.php index e81464a9d4a..9535d4ddddd 100644 --- a/ai/provider/openai/classes/aimodel/openai_base.php +++ b/ai/provider/openai/classes/aimodel/openai_base.php @@ -31,9 +31,9 @@ interface openai_base { public const MODEL_TYPE_IMAGE = 2; /** - * Get model type. + * Get model types. * - * @return int Model type. + * @return array List of model types. */ - public function model_type(): int; + public function model_type(): array; } diff --git a/ai/provider/openai/classes/form/action_form.php b/ai/provider/openai/classes/form/action_form.php index fdc1ab14b84..bbd1260c023 100644 --- a/ai/provider/openai/classes/form/action_form.php +++ b/ai/provider/openai/classes/form/action_form.php @@ -140,6 +140,7 @@ class action_form extends action_settings_form { global $PAGE; $PAGE->requires->js_call_amd('aiprovider_openai/modelchooser', 'init'); $mform = $this->_form; + $actionname = $this->actionname; // Action model to use. $mform->addElement( @@ -155,13 +156,15 @@ class action_form extends action_settings_form { (!array_key_exists($this->actionconfig['model'], $this->get_model_list($modeltype)) || !empty($this->actionconfig['modelextraparams']))) { $defaultmodel = 'custom'; + } else if (empty($this->actionconfig['model'])) { + $defaultmodel = ($actionname === 'generate_image') ? 'dall-e-3' : 'gpt-4o'; } else { - $defaultmodel = $this->actionconfig['model'] ?? 'gpt-4o'; + $defaultmodel = $this->actionconfig['model']; } $mform->setDefault('modeltemplate', $defaultmodel); $mform->addHelpButton('modeltemplate', "action:{$this->actionname}:model", 'aiprovider_openai'); - $mform->addElement('hidden', 'model', $this->actionconfig['model'] ?? 'gpt-4o'); + $mform->addElement('hidden', 'model', $defaultmodel); $mform->setType('model', PARAM_TEXT); $mform->addElement('text', 'custommodel', get_string('custom_model_name', 'aiprovider_openai')); @@ -189,7 +192,7 @@ class action_form extends action_settings_form { $models['custom'] = get_string('custom', 'core_form'); foreach (helper::get_model_classes() as $class) { $model = new $class(); - if ($model->model_type() == $modeltype) { + if (in_array($modeltype, $model->model_type())) { $models[$model->get_model_name()] = $model->get_model_display_name(); } }