Skip to content

Commit

Permalink
Merge branch 'main' into mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusgreen committed Jun 22, 2024
2 parents 99af5b6 + 02af46f commit 37f3351
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
13 changes: 7 additions & 6 deletions classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
]
);

}
Expand All @@ -62,14 +62,15 @@ 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.
$type = 'aitext';
\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);
Expand All @@ -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),
]);

Expand Down
4 changes: 2 additions & 2 deletions edit_aitext_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions lang/en/qtype_aitext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 3 additions & 3 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;

}
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 10 additions & 7 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* TODO describe file settings
* Default settings for the aitext question type
*
* @package qtype_aitext
* @copyright 2024 Marcus Green
Expand All @@ -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'),
Expand All @@ -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'),
Expand All @@ -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
Expand All @@ -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']
));

}

Binary file modified tests/fixtures/aitext_questions.mbz
Binary file not shown.

0 comments on commit 37f3351

Please sign in to comment.