diff --git a/classes/external.php b/classes/external.php index 957b987..65fd835 100644 --- a/classes/external.php +++ b/classes/external.php @@ -62,9 +62,6 @@ public static function fetch_ai_grade_parameters(): external_function_parameters * @return array the response array */ public static function fetch_ai_grade($response, $defaultmark, $prompt, $marksscheme): stdClass { - // Get our AI helper. - $ai = new local_ai_manager\manager('feedback'); - // Build an aitext question instance so we can call the same code that the question type uses when it grades. $type = 'aitext'; \question_bank::load_question_definition_classes($type); @@ -73,12 +70,8 @@ public static function fetch_ai_grade($response, $defaultmark, $prompt, $markssc // Make sure we have the right data for AI to work with. if (!empty($response) && !empty($prompt) && $defaultmark > 0) { $fullaiprompt = $aiquestion->build_full_ai_prompt($response, $prompt, $defaultmark, $marksscheme); - $llmresponse = $ai->perform_request($fullaiprompt); - if ($llmresponse->get_code() !== 200) { - throw new moodle_exception('err_retrievingtranslation', 'qtype_aitext', '', - $llmresponse->get_errormessage()); - } - $feedback = format_text($llmresponse->get_content(), FORMAT_HTML); + $feedback = $aiquestion->perform_request($fullaiprompt); + $feedback = format_text($feedback, FORMAT_HTML); $contentobject = $aiquestion->process_feedback($feedback); } else { $contentobject = (object)["feedback" => get_string('error_parammissing', 'qtype_aitext'), "marks" => 0]; diff --git a/db/install.xml b/db/install.xml old mode 100644 new mode 100755 index 50f5a99..b2751ba --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -28,5 +28,16 @@ + + + + + + + + + + +
diff --git a/db/services.php b/db/services.php old mode 100644 new mode 100755 diff --git a/db/upgrade.php b/db/upgrade.php old mode 100644 new mode 100755 index f753863..e4891c0 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -76,7 +76,21 @@ function xmldb_qtype_aitext_upgrade($oldversion) { // Aitext savepoint reached. upgrade_plugin_savepoint(true, 2024051101, 'qtype', 'aitext'); } - + if ($oldversion < 2024051109) { + $table = new xmldb_table(name: 'qtype_aitext_testprompts'); + + // Adding fields to table qtype_stack_qtest_results. + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL); + $table->add_field('testprompt', XMLDB_TYPE_TEXT); + // Conditionally launch create table for tool_dataprivacy_contextlist. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + // Aitext savepoint reached. + upgrade_plugin_savepoint(true, 2024051109, 'qtype', 'aitext'); + } return true; } diff --git a/question.php b/question.php index 5909edf..979d92c 100755 --- a/question.php +++ b/question.php @@ -151,7 +151,7 @@ public function apply_attempt_state(question_attempt_step $step) { * @param string $prompt * @return string $response */ - public function perform_request(string $prompt, string $purpose): string { + public function perform_request(string $prompt, string $purpose = 'feedback'): string { if (get_config('qtype_aitext', 'uselocalaimanager')) { $manager = new local_ai_manager\manager($purpose); $llmresponse = (object) $manager->perform_request($prompt, ['component' => 'qtype_aitext', 'contextid' => $this->contextid]); diff --git a/questiontype.php b/questiontype.php index 5979735..7430bce 100755 --- a/questiontype.php +++ b/questiontype.php @@ -382,8 +382,13 @@ protected function export_errorcmid($cmid) { } public function menu_name() { - $tenant = \core\di::get(\local_ai_manager\local\tenant::class); - return $tenant->is_tenant_allowed() ? parent::menu_name() : ''; + if (class_exists('\local_ai_manager\local\tenant')) { + $tenant = \core\di::get(\local_ai_manager\local\tenant::class); + return $tenant->is_tenant_allowed() ? parent::menu_name() : ''; + } else { + return ''; + } } + } diff --git a/version.php b/version.php index 0254e01..7c35827 100755 --- a/version.php +++ b/version.php @@ -24,11 +24,14 @@ defined('MOODLE_INTERNAL') || die(); +/** + * This plugin can use either the local_ai_manager back end + * or the Moodle 4.4 AI subsystem, so it is not possible to + * include a dependency statement. + */ $plugin->component = 'qtype_aitext'; -$plugin->version = 2024051101; +$plugin->version = 2024051109; $plugin->requires = 2020110900; $plugin->release = '0.01'; $plugin->maturity = MATURITY_BETA; -/*$plugin->dependencies = [ - 'local_ai_manager' => ANY_VERSION, -];*/ +