Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus committed Apr 23, 2024
1 parent a681216 commit ab2fe22
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions backup/moodle2/backup_qtype_aitext_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ protected function define_question_plugin_structure() {
$plugin->add_child($pluginwrapper);

// Now create the qtype own structures.
$aitext = new backup_nested_element('aitext', ['id'], array(
$aitext = new backup_nested_element('aitext', ['id'], [
'aiprompt', 'responseformat', 'responsefieldlines', 'minwordlimit', 'maxwordlimit',
'graderinfo', 'graderinfoformat', 'responsetemplate',
'responsetemplateformat', 'maxbytes'));
'responsetemplateformat', 'maxbytes']);

// Now the own qtype tree.
$pluginwrapper->add_child($aitext);
Expand Down
10 changes: 5 additions & 5 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ public function grade_response(array $response) : array {
if (is_array($response)) {
$responsetext = strip_tags($response['answer']);
$responsetext = '[['.$responsetext.']]';
$prompt = get_config('qtype_aitext','prompt');
$prompt = get_config('qtype_aitext', 'prompt');
$prompt = preg_replace("/\[responsetext\]/", $responsetext, $prompt);
$prompt .= ' '.trim($this->aiprompt); if ($this->markscheme > '') {
$prompt .= ' '.$this->markscheme;
} else {
/** @todo should this be a plugin setting value? */
// Todo should this be a plugin setting value?.
$prompt .= ' Set marks to null in the json object.'.PHP_EOL;
}

$prompt .= ' '.trim(get_config('qtype_aitext','jsonprompt'));
$prompt .= ' '.trim(get_config('qtype_aitext', 'jsonprompt'));
$prompt .= ' respond in the language '.current_language();

$llmresponse = $ai->prompt_completion($prompt);
Expand All @@ -161,7 +161,7 @@ public function grade_response(array $response) : array {
$grade = [0 => 0, question_state::$needsgrading];
} else {
$fraction = $contentobject->marks / $this->defaultmark;
$grade = array($fraction, question_state::graded_state_for_fraction($fraction));
$grade = [$fraction, question_state::graded_state_for_fraction($fraction)];
}
// The -aicontent data is used in question preview. Only needs to happen in preview.
$this->insert_attempt_step_data('-aiprompt', $prompt);
Expand Down Expand Up @@ -189,7 +189,7 @@ public function process_feedback(string $feedback) {
} else {
$contentobject = (object) [
"feedback" => $feedback,
"marks" => null
"marks" => null,
];
}
return $contentobject;
Expand Down
40 changes: 24 additions & 16 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,30 @@
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 ChatGPT)'));
$settings->add(new admin_setting_configtextarea('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.',
PARAM_RAW,20,3));
$settings->add(new admin_setting_configtextarea('qtype_aitext/jsonprompt',
new lang_string('jsonprompt', 'qtype_aitext'),
new lang_string('jsonprompt_setting', 'qtype_aitext'),
'Return only a JSON object which enumerates a set of 2 elements.The JSON object should be in
$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 ChatGPT)'
));
$settings->add(new admin_setting_configtextarea(
'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.',
PARAM_RAW,
20,
3
));
$settings->add(new admin_setting_configtextarea(
'qtype_aitext/jsonprompt',
new lang_string('jsonprompt', 'qtype_aitext'),
new lang_string('jsonprompt_setting', 'qtype_aitext'),
'Return only a JSON object which enumerates a set of 2 elements.The JSON object should be in
this format: {feedback":"string","marks":"number"} where marks is a single value summing all marks.',
PARAM_RAW, 20, 6
));

PARAM_RAW,
20,
6
));
}

2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'qtype_aitext';
$plugin->version = 2024041401;
$plugin->version = 2024042201;
$plugin->requires = 2020110900;
$plugin->maturity = MATURITY_BETA;
$plugin->dependencies = [
Expand Down

0 comments on commit ab2fe22

Please sign in to comment.