diff --git a/classes/external.php b/classes/external.php index a8a4ddf..e1b110e 100644 --- a/classes/external.php +++ b/classes/external.php @@ -41,13 +41,13 @@ class qtype_aitext_external extends external_api { * * @return void */ - public static function fetch_ai_grade_parameters() { + public static function fetch_ai_grade_parameters(): external_function_parameters { return new external_function_parameters( - array('response' => new external_value(PARAM_TEXT, 'The students response to question'), + ['response' => new external_value(PARAM_TEXT, 'The students response to question'), 'defaultmark' => new external_value(PARAM_INT, 'The total possible score'), 'prompt' => new external_value(PARAM_TEXT, 'The AI Prompt'), 'marksscheme' => new external_value(PARAM_TEXT, 'The marks scheme') - ) + ] ); } @@ -62,6 +62,8 @@ public static function fetch_ai_grade_parameters() { */ public static function fetch_ai_grade($response, $defaultmark, $prompt, $marksscheme) { // Get our AI helper. + xdebug_break(); + $ai = new ai\ai(); // Build an aitext question instance so we can call the same code that the question type uses when it grades. @@ -69,7 +71,6 @@ public static function fetch_ai_grade($response, $defaultmark, $prompt, $markssc \question_bank::load_question_definition_classes($type); $aiquestion = new qtype_aitext_question(); $aiquestion->qtype = \question_bank::get_qtype('aitext'); - // 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); @@ -90,9 +91,9 @@ public static function fetch_ai_grade($response, $defaultmark, $prompt, $markssc * * @return void */ - public static function fetch_ai_grade_returns() { + public static function fetch_ai_grade_returns(): external_single_structure { return new external_single_structure([ - 'feedback' => new external_value(PARAM_TEXT, 'text feedback for display to student', VALUE_DEFAULT), + 'feedback' => new external_value(PARAM_CLEANHTML, 'text feedback for display to student', VALUE_DEFAULT), 'marks' => new external_value(PARAM_FLOAT, 'AI grader awarded marks for student response', VALUE_DEFAULT), ]); diff --git a/edit_aitext_form.php b/edit_aitext_form.php index 989776c..1f977d9 100755 --- a/edit_aitext_form.php +++ b/edit_aitext_form.php @@ -44,7 +44,7 @@ protected function definition_inner($mform) { $mform->removeelement('generalfeedback'); $mform->removeelement('questiontext'); $mform->addElement('editor', 'questiontext', get_string('questiontext', 'mod_quiz'), - ['maxlen' => 50, 'rows' => 5, 'size' => 30], $this->editoroptions); + ['maxlen' => 50, 'rows' => 8, 'size' => 30], $this->editoroptions); $mform->addElement('textarea', 'aiprompt', get_string('aiprompt', 'qtype_aitext'), ['maxlen' => 50, 'rows' => 5, 'size' => 30]); @@ -87,7 +87,7 @@ protected function definition_inner($mform) { $mform->addElement('select', 'responseformat', get_string('responseformat', 'qtype_aitext'), $qtype->response_formats()); - $mform->setDefault('responseformat', $this->get_default_value('responseformat', 'editor')); + $mform->setDefault('responseformat', get_config('qtype_aitext', 'responseformat')); $mform->addElement('select', 'responsefieldlines', get_string('responsefieldlines', 'qtype_aitext'), $qtype->response_sizes()); diff --git a/lang/en/qtype_aitext.php b/lang/en/qtype_aitext.php index 377d96a..0259ff3 100755 --- a/lang/en/qtype_aitext.php +++ b/lang/en/qtype_aitext.php @@ -83,6 +83,7 @@ $string['prompttester'] = 'Prompt Tester'; $string['responsefieldlines'] = 'Input box size'; $string['responseformat'] = 'Response format'; +$string['responseformat_setting'] = 'The editor the student uses when responding'; $string['responseoptions'] = 'Response options'; $string['responsenotrequired'] = 'Text input is optional'; $string['responseisrequired'] = 'Require the student to enter text'; diff --git a/question.php b/question.php index 0b88a0c..f3b634d 100755 --- a/question.php +++ b/question.php @@ -188,7 +188,7 @@ public function grade_response(array $response) : array { * @param string $markscheme * @return string; */ - public function build_full_ai_prompt($response, $aiprompt, $defaultmark, $markscheme) { + public function build_full_ai_prompt($response, $aiprompt, $defaultmark, $markscheme): string { $responsetext = strip_tags($response); $responsetext = '[['.$responsetext.']]'; $prompt = get_config('qtype_aitext', 'prompt'); @@ -204,7 +204,7 @@ public function build_full_ai_prompt($response, $aiprompt, $defaultmark, $marksc $prompt .= ' Set marks to null in the json object.'.PHP_EOL; } $prompt .= ' '.trim(get_config('qtype_aitext', 'jsonprompt')); - $prompt .= ' translate to the language '.current_language(); + $prompt .= ' translate the feedback to the language '.current_language(); return $prompt; } @@ -244,7 +244,7 @@ public function process_feedback(string $feedback) { * @param string $text * @return string */ - protected function llm_translate(string $text) :string { + protected function llm_translate(string $text): string { if (current_language() == 'en') { return $text; } diff --git a/renderer.php b/renderer.php index a924d27..a6c7dfe 100755 --- a/renderer.php +++ b/renderer.php @@ -23,13 +23,12 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use Random\RandomException; defined('MOODLE_INTERNAL') || die(); /** * Generates the output for aitext questions. * - * @copyright 2023 Marcus Green + * @copyright 2024 Marcus Green * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class qtype_aitext_renderer extends qtype_renderer { diff --git a/settings.php b/settings.php index dd18d6d..78a2da9 100644 --- a/settings.php +++ b/settings.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * TODO describe file settings + * Default settings for the aitext question type * * @package qtype_aitext * @copyright 2024 Marcus Green @@ -24,10 +24,6 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { - $settings->add(new admin_setting_configtext('qtype_aitext/disclaimer', - new lang_string('disclaimer', 'qtype_aitext'), - new lang_string('disclaimer_setting', 'qtype_aitext'), - "(Response provided by [[model]])")); $settings->add(new admin_setting_configtextarea('qtype_aitext/defaultprompt', new lang_string('defaultprompt', 'qtype_aitext'), @@ -38,7 +34,7 @@ new lang_string('defaultmarksscheme', 'qtype_aitext'), new lang_string('defaultmarksscheme_setting', 'qtype_aitext'), new lang_string('thedefaultmarksscheme', 'qtype_aitext'))); - $settings->add(new admin_setting_configtext( + $settings->add(new admin_setting_configtext( 'qtype_aitext/disclaimer', new lang_string('disclaimer', 'qtype_aitext'), new lang_string('disclaimer_setting', 'qtype_aitext'), @@ -48,7 +44,7 @@ 'qtype_aitext/prompt', new lang_string('prompt', 'qtype_aitext'), new lang_string('prompt_setting', 'qtype_aitext'), - 'in [responsetext] analyse the part between [[ and ]] as follows:', + 'in [responsetext] analyse but do not mention the part between [[ and ]] as follows:', PARAM_RAW, 20, 3 @@ -64,5 +60,12 @@ 20, 6 )); + $settings->add(new admin_setting_configselect( + 'qtype_aitext/responseformat', + new lang_string('responseformat', 'qtype_aitext'), + new lang_string('responseformat_setting', 'qtype_aitext'), + 0, ['plain' => 'plain', 'editor' => 'editor', 'monospaced' => 'monospaced'] + )); + } diff --git a/tests/fixtures/aitext_questions.mbz b/tests/fixtures/aitext_questions.mbz index bdcef4f..e3d918e 100644 Binary files a/tests/fixtures/aitext_questions.mbz and b/tests/fixtures/aitext_questions.mbz differ