Skip to content

Commit 384d2a3

Browse files
committed
fix unit test & remove double space
1 parent 0ffce72 commit 384d2a3

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

classes/local/question_generator.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,14 @@ public function generate_question(stdClass $dataobject, bool $sendexistingquesti
7474

7575
$provider = get_config('qbank_questiongen', 'provider');
7676
if ($provider === 'local_ai_manager') {
77-
$systemprompt = $primer . " " . $instructions . " " . $example;
78-
77+
$systemprompt = '## PRIMER\n' .
78+
$primer .
79+
'\n\n## INSTRUCTIONS\n' .
80+
$instructions .
81+
'\n\n## EXAMPLE MOODLE XML QUESTION\n'
82+
. $example;
83+
84+
// Append existing questions to the prompt if option is chosen.
7985
if ($sendexistingquestionsascontext) {
8086
$questionidsincategory = question_bank::get_finder()->get_questions_from_categories([$dataobject->category], null);
8187
if (!empty($questionidsincategory)) {
@@ -89,25 +95,30 @@ public function generate_question(stdClass $dataobject, bool $sendexistingquesti
8995
];
9096
}
9197
$rs->close();
92-
9398
$questiontextsinqbankprompt = 'The question that will be generated by you has to be different '
9499
. 'from all of the following questions in this JSON string: "'
95100
. json_encode($questiontextsinqbankcat) . '"';
96-
$systemprompt = $systemprompt . " " . $questiontextsinqbankprompt;
101+
102+
$systemprompt .= '\n\n## EXISTING QUESTIONS GENERATED QUESTIONS MUST DIFFER FROM\n' .
103+
$questiontextsinqbankprompt;
97104
}
98105
}
99-
106+
$modeheader = '\n\n## QUESTION GENERATION MODE - ';
100107
switch ($dataobject->mode) {
101108
case story_form::QUESTIONGEN_MODE_TOPIC:
102109
$storyprompt =
110+
$modeheader . 'TOPIC\n' .
103111
'Create a question about the following topic. Use your own training data to generate it: "' .
104112
$story . '"';
105113
break;
106114
case story_form::QUESTIONGEN_MODE_STORY:
107115
case story_form::QUESTIONGEN_MODE_COURSECONTENTS:
108116
$storyprompt =
109-
'Create a question from the following contents. '
110-
. 'Only use this content and do not use any training data: "' . $story . '"';
117+
$modeheader . 'COURSE CONTENTS\n' .
118+
'Create a question from the following contents. ' .
119+
'Only use this content and do not use any training data: "' .
120+
$story .
121+
'"';
111122
break;
112123
}
113124

tests/local/question_generator_test.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public function test_generate_question(): void {
7171
$this->assertEquals($presetjson->primer, $questionobject->primer);
7272
$this->assertEquals($presetjson->instructions, $questionobject->instructions);
7373
$this->assertEquals($presetjson->example, $questionobject->example);
74-
$expectedstoryprompt = 'Create a question about the following topic. Use your own training data to generate it: "' .
74+
$expectedstoryprompt = '\n\n## QUESTION GENERATION MODE - TOPIC\n' .
75+
'Create a question about the following topic. Use your own training data to generate it: "' .
7576
$dataobject->story . '"';
7677
$this->assertEquals($expectedstoryprompt, $questionobject->storyprompt);
7778
$this->assertEmpty($questionobject->questiontextsinqbankprompt);
@@ -110,7 +111,8 @@ public function test_generate_question(): void {
110111
$this->assertEquals($presetjson->primer, $questionobject->primer);
111112
$this->assertEquals($presetjson->instructions, $questionobject->instructions);
112113
$this->assertEquals($presetjson->example, $questionobject->example);
113-
$expectedstoryprompt = 'Create a question about the following topic. Use your own training data to generate it: "' .
114+
$expectedstoryprompt = '\n\n## QUESTION GENERATION MODE - TOPIC\n' .
115+
'Create a question about the following topic. Use your own training data to generate it: "' .
114116
$dataobject->story . '"';
115117
$this->assertEquals($expectedstoryprompt, $questionobject->storyprompt);
116118
$this->assertStringContainsString('The question that will be generated by you has to be different '
@@ -133,7 +135,7 @@ public function test_generate_question(): void {
133135
$this->assertEquals($presetjson->primer, $questionobject->primer);
134136
$this->assertEquals($presetjson->instructions, $questionobject->instructions);
135137
$this->assertEquals($presetjson->example, $questionobject->example);
136-
$expectedstoryprompt = 'Create a question from the following contents. '
138+
$expectedstoryprompt = '\n\n## QUESTION GENERATION MODE - COURSE CONTENTS\nCreate a question from the following contents. '
137139
. 'Only use this content and do not use any training data: "' . $dataobject->story . '"';
138140
$this->assertEquals($expectedstoryprompt, $questionobject->storyprompt);
139141
$this->assertEmpty($questionobject->questiontextsinqbankprompt);
@@ -148,7 +150,7 @@ public function test_generate_question(): void {
148150
$this->assertEquals($presetjson->primer, $questionobject->primer);
149151
$this->assertEquals($presetjson->instructions, $questionobject->instructions);
150152
$this->assertEquals($presetjson->example, $questionobject->example);
151-
$expectedstoryprompt = 'Create a question from the following contents. '
153+
$expectedstoryprompt = '\n\n## QUESTION GENERATION MODE - COURSE CONTENTS\nCreate a question from the following contents. '
152154
. 'Only use this content and do not use any training data: "' . $dataobject->story . '"';
153155
$this->assertEquals($expectedstoryprompt, $questionobject->storyprompt);
154156
$this->assertEmpty($questionobject->questiontextsinqbankprompt);

0 commit comments

Comments
 (0)