From cbd9d34d3789afbd361ce0bd0b9d160d5bdabb24 Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Thu, 20 Mar 2025 11:19:17 +1100 Subject: [PATCH] MDL-84819 aiprovider_openai: Fix default model for generate_image --- ai/provider/openai/classes/form/action_form.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ai/provider/openai/classes/form/action_form.php b/ai/provider/openai/classes/form/action_form.php index fdc1ab14b84..8e8e648903e 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'));