Skip to content

Commit

Permalink
Add testprompts table to dbxml and upgrade.php
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusgreen committed Nov 9, 2024
1 parent fa82331 commit 424f0e4
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
11 changes: 2 additions & 9 deletions classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
Expand Down
13 changes: 12 additions & 1 deletion db/install.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="question/type/aitext/db" VERSION="20240718" COMMENT="XMLDB file for Moodle question/type/aitext"
<XMLDB PATH="question/type/aitext/db" VERSION="20241108" COMMENT="XMLDB file for Moodle question/type/aitext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -28,5 +28,16 @@
<KEY NAME="questionid" TYPE="foreign-unique" FIELDS="questionid" REFTABLE="question" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="qtype_aitext_testprompts" COMMENT="id of the question being linked to">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="id of the question the testprompts are linked to"/>
<FIELD NAME="testprompt" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Prompts to be tested during question authoring"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="testprompt_question" TYPE="foreign" FIELDS="question" REFTABLE="qtype_aitext" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
Empty file modified db/services.php
100644 → 100755
Empty file.
16 changes: 15 additions & 1 deletion db/upgrade.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion question.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
9 changes: 7 additions & 2 deletions questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
}


}
11 changes: 7 additions & 4 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];*/

0 comments on commit 424f0e4

Please sign in to comment.