From bd523c7269dcd558a2445eeb88678b43e2e45949 Mon Sep 17 00:00:00 2001 From: Marcus Green Date: Tue, 14 May 2024 22:07:15 +0100 Subject: [PATCH] Model can be selected for each question --- .../backup_qtype_aitext_plugin.class.php | 2 +- .../restore_qtype_aitext_plugin.class.php | 1 + classes/external.php | 2 +- db/install.xml | 3 ++- db/upgrade.php | 16 ++++++++++++++++ edit_aitext_form.php | 11 ++++++++++- question.php | 18 ++++++++++++++++-- questiontype.php | 8 +++++++- renderer.php | 1 + tests/behat/add.feature | 2 +- tests/helper.php | 7 +++++++ version.php | 2 +- 12 files changed, 64 insertions(+), 9 deletions(-) diff --git a/backup/moodle2/backup_qtype_aitext_plugin.class.php b/backup/moodle2/backup_qtype_aitext_plugin.class.php index b6b8ae5..f1bd5fe 100755 --- a/backup/moodle2/backup_qtype_aitext_plugin.class.php +++ b/backup/moodle2/backup_qtype_aitext_plugin.class.php @@ -48,7 +48,7 @@ protected function define_question_plugin_structure() { // Now create the qtype own structures. $aitext = new backup_nested_element('aitext', ['id'], [ - 'aiprompt', 'markscheme', 'sampleanswer', 'responseformat', 'responsefieldlines', 'minwordlimit', 'maxwordlimit', + 'aiprompt', 'markscheme', 'sampleanswer', 'model', 'responseformat', 'responsefieldlines', 'minwordlimit', 'maxwordlimit', 'graderinfo', 'graderinfoformat', 'responsetemplate', 'responsetemplateformat', 'maxbytes']); diff --git a/backup/moodle2/restore_qtype_aitext_plugin.class.php b/backup/moodle2/restore_qtype_aitext_plugin.class.php index 2a5ce1a..1461fca 100755 --- a/backup/moodle2/restore_qtype_aitext_plugin.class.php +++ b/backup/moodle2/restore_qtype_aitext_plugin.class.php @@ -120,6 +120,7 @@ protected function after_execute_question() { $defaultoptions->aiprompt = ''; $defaultoptions->markscheme = ''; $defaultoptions->sampleanswer = ''; + $defaultoptions->model = 'gpt-4'; $defaultoptions->responseformat = 'editor'; $defaultoptions->responsefieldlines = 15; $defaultoptions->minwordlimit = null; diff --git a/classes/external.php b/classes/external.php index e182052..a8a4ddf 100644 --- a/classes/external.php +++ b/classes/external.php @@ -18,7 +18,7 @@ * External * * @package qtype_aitext - * @author Justin Hunt - poodll.com + * @copyright Justin Hunt - poodll.com * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); diff --git a/db/install.xml b/db/install.xml index d25b862..9b43000 100755 --- a/db/install.xml +++ b/db/install.xml @@ -20,7 +20,8 @@ - + + diff --git a/db/upgrade.php b/db/upgrade.php index 0d53c44..6468b74 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -18,6 +18,7 @@ * AI Text question type upgrade code. * * @package qtype_aitext + * @copyright Marcus Green 2024 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -46,5 +47,20 @@ function xmldb_qtype_aitext_upgrade($oldversion) { } + if ($oldversion < 2024051100) { + + // Define field model to be added to qtype_aitext. + $table = new xmldb_table('qtype_aitext'); + $field = new xmldb_field('model', XMLDB_TYPE_CHAR, '60', null, null, null, null, 'sampleanswer'); + + // Conditionally launch add field model. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Aitext savepoint reached. + upgrade_plugin_savepoint(true, 2024051100, 'qtype', 'aitext'); + } + return true; } diff --git a/edit_aitext_form.php b/edit_aitext_form.php index 089f0dc..5eeecdc 100755 --- a/edit_aitext_form.php +++ b/edit_aitext_form.php @@ -57,7 +57,16 @@ protected function definition_inner($mform) { $mform->setType('markscheme', PARAM_RAW); $mform->setDefault('markscheme', get_config('qtype_aitext', 'defaultmarksscheme')); $mform->addHelpButton('markscheme', 'markscheme', 'qtype_aitext'); + $models = explode(",", get_config('tool_aiconnect', 'model')); + if (count($models) > 1 ) { + $models = array_combine($models, $models); + $mform->addElement('select', 'model', 'Models', $models); + } else { + $mform->addElement('hidden', 'model', $models[0]); + } + $mform->setType('model', PARAM_RAW); + // The question_edit_form that this class extends expects a general feedback field. $mform->addElement('html', '