Skip to content

Commit 58d4934

Browse files
committed
Add structure to prompt with newlines and headers.
1 parent 0ffce72 commit 58d4934

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

classes/local/question_generator.php

Lines changed: 20 additions & 9 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)) {
@@ -90,24 +96,29 @@ public function generate_question(stdClass $dataobject, bool $sendexistingquesti
9096
}
9197
$rs->close();
9298

93-
$questiontextsinqbankprompt = 'The question that will be generated by you has to be different '
94-
. 'from all of the following questions in this JSON string: "'
95-
. json_encode($questiontextsinqbankcat) . '"';
96-
$systemprompt = $systemprompt . " " . $questiontextsinqbankprompt;
99+
$systemprompt .= '\n\n## EXISTING QUESTIONS GENERATED QUESTIONS MUST DIFFER FROM\n' .
100+
'The question that will be generated by you has to be different from' .
101+
'all the questions in this JSON string:\n"' .
102+
json_encode($questiontextsinqbankcat) .
103+
'"';
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

0 commit comments

Comments
 (0)