Skip to content

Commit

Permalink
Add the model name into the disclaimer if it contains [[model]]
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusgreen committed May 18, 2024
1 parent c9b9389 commit 81a0f77
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 3 additions & 1 deletion question.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ public function process_feedback(string $feedback) {
if (json_last_error() === JSON_ERROR_NONE) {
$contentobject->feedback = trim($contentobject->feedback);
$contentobject->feedback = preg_replace(array('/\[\[/', '/\]\]/'), '"', $contentobject->feedback);
$contentobject->feedback .= ' '.$this->llm_translate(get_config('qtype_aitext', 'disclaimer'));
$disclaimer = get_config('qtype_aitext', 'disclaimer');
$disclaimer = str_replace("[[model]]", $this->model, $disclaimer);
$contentobject->feedback .= ' '.$this->llm_translate($disclaimer);
} else {
$contentobject = (object) [
"feedback" => $feedback,
Expand Down
4 changes: 2 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$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)"));
"(Response provided by [[model]])"));

$settings->add(new admin_setting_configtextarea('qtype_aitext/defaultprompt',
new lang_string('defaultprompt', 'qtype_aitext'),
Expand All @@ -42,7 +42,7 @@
'qtype_aitext/disclaimer',
new lang_string('disclaimer', 'qtype_aitext'),
new lang_string('disclaimer_setting', 'qtype_aitext'),
'(Response provided by ChatGPT)'
'(Response provided by [[model]])'
));
$settings->add(new admin_setting_configtextarea(
'qtype_aitext/prompt',
Expand Down
17 changes: 7 additions & 10 deletions tests/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,14 @@ public function get_test_questions() {
* @return qtype_aitext_question
*/
public static function make_aitext_question(array $options) {
$optionsparam = [
'questiontext' => $options['questiontext'] ?? '',
'aiprompt' => $options['aiprompt'] ?? 0,
'markscheme' => $options['markscheme'] ?? 0,
'sampleanswer' => $options['sampleanswer'] ?? 0,
'model' => $options['model'] ?? '',
];

$type = 'aitext';
question_bank::load_question_definition_classes($type);
question_bank::load_question_definition_classes('aitext');
$question = new qtype_aitext_question();
$question->questiontext = $options['questiontext'] ?? '';
$question->model = $options['model'] ?? '';
$question->sampleanswer = $options['sampleanswer'] ?? '';
$question->markscheme = $options['markscheme'] ?? '';
$question->aiprompt = $options['aiprompt'] ?? '';

test_question_maker::initialise_a_question($question);
$question->qtype = question_bank::get_qtype('aitext');
return $question;
Expand Down
3 changes: 2 additions & 1 deletion tests/question_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ public function test_get_question_summary() {
public function test_get_feedback() {
// Create the aitext question under test.
$questiontext = 'AI question text';
$aitext = qtype_aitext_test_helper::make_aitext_question(['questiontext' => $questiontext]);
$aitext = qtype_aitext_test_helper::make_aitext_question(['questiontext' => $questiontext, 'model' => 'llama3']);
$testdata = [
"feedback" => "Feedback text",
"marks" => 0
];
$goodjson = json_encode($testdata);

$feedback = $aitext->process_feedback($goodjson);
$this->assertIsObject($feedback);
$badjson = 'Some random string'. $goodjson;
Expand Down
4 changes: 2 additions & 2 deletions tests/restore_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public function test_restore_create_missing_qtype_aitext_options() {
$contexts = new \core_question\local\bank\question_edit_contexts(\context_course::instance($course->id));
$category = question_make_default_categories($contexts->all());
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$essay = $questiongenerator->create_question('aitext', null, array('category' => $category->id));
$aitext = $questiongenerator->create_question('aitext', null, array('category' => $category->id));

// Remove the options record, which means that the backup will look like a backup made in an old Moodle.
$DB->delete_records('qtype_aitext', ['questionid' => $essay->id]);
$DB->delete_records('qtype_aitext', ['questionid' => $aitext->id]);

// Do backup and restore.
$newcourseid = $this->backup_and_restore($course);
Expand Down
2 changes: 1 addition & 1 deletion version.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/>.

/**
* Version information for the essay question type.
* Version information for the aitext question type.
*
* @package qtype_aitext
* @copyright 2024 Marcus Green
Expand Down

0 comments on commit 81a0f77

Please sign in to comment.