Skip to content

Commit 6a00cc3

Browse files
committed
Merge branch 'main' into multi_response_test
2 parents bf566c1 + 8678406 commit 6a00cc3

File tree

3 files changed

+63
-11
lines changed

3 files changed

+63
-11
lines changed

amd/src/editformhelper.js.org

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
// You should have received a copy of the GNU General Public License
1313
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1414

15-
import {get_strings} from 'core/str';
15+
import {
16+
get_strings
17+
} from 'core/str';
1618
import Ajax from 'core/ajax';
1719
import Log from 'core/log';
1820
import Notify from 'core/notification';
19-
import {exception as displayException} from 'core/notification';
21+
import {
22+
exception as displayException
23+
} from 'core/notification';
2024

2125
/**
2226
* Question AI Text Edit Form Helper
@@ -44,12 +48,17 @@ export const init = (contextid) => {
4448
return;
4549

4650
// Set up strings
47-
var strings={};
48-
get_strings([
49-
{ "key": "prompttester", "component": 'qtype_aitext'},
50-
{ "key": "sampleanswerempty", "component": 'qtype_aitext'},
51+
var strings = {};
52+
get_strings([{
53+
"key": "prompttester",
54+
"component": 'qtype_aitext'
55+
},
56+
{
57+
"key": "sampleanswerempty",
58+
"component": 'qtype_aitext'
59+
},
5160

52-
]).done(function (s) {
61+
]).done(function(s) {
5362
var i = 0;
5463
strings.prompttester = s[i++];
5564
strings.sampleanswerempty = s[i++];
@@ -70,7 +79,8 @@ export const init = (contextid) => {
7079
}
7180

7281
//put spinner in place
73-
sampleanswereval.innerHTML='<i class="icon fa fa-spinner fa-spin fa-2x"></i>';
82+
// This is an alternative https://github.com/moodle/moodle/blob/main/lib/amd/src/loadingicon.js.
83+
sampleanswereval.innerHTML = '<i class="icon fa fa-spinner fa-spin fa-2x"></i>';
7484

7585
Ajax.call([{
7686
methodname: 'qtype_aitext_fetch_ai_grade',
@@ -91,5 +101,5 @@ export const init = (contextid) => {
91101
displayException(error);
92102
sampleanswereval.innerHTML = '';
93103
});
94-
});//end of click
95-
};
104+
}); //end of click
105+
};

question.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,14 @@ public function perform_request(string $prompt, string $purpose = 'feedback'): s
176176
}
177177
return $llmresponse->get_content();
178178
} else if ($backend == 'core_ai_subsystem') {
179+
<<<<<<< HEAD
179180
global $USER, $CFG, $DB;
180181
// There was a breaking change in the move to Moodle 5x.
181182
if (str_starts_with($CFG->release, '5')) {
183+
=======
184+
global $USER,$CFG, $DB;
185+
if(str_starts_with($CFG->release, '5')) {
186+
>>>>>>> main
182187
$manager = new \core_ai\manager($DB);
183188
} else {
184189
$manager = new \core_ai\manager();
@@ -271,6 +276,12 @@ public function grade_response(array $response): array {
271276
* @return string;
272277
*/
273278
public function build_full_ai_prompt($response, $aiprompt, $defaultmark, $markscheme): string {
279+
280+
// Check if [questiontext] is in the aiprompt and replace it with the question text
281+
if (strpos($aiprompt, '[questiontext]') !== false) {
282+
$aiprompt = str_replace('[questiontext]', strip_tags($this->questiontext), $aiprompt);
283+
}
284+
274285
$responsetext = strip_tags($response);
275286
$responsetext = '[['.$responsetext.']]';
276287
$prompt = get_config('qtype_aitext', 'prompt');

tests/question_test.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
namespace qtype_aitext;
1818

1919
use coding_exception;
20+
use core_reportbuilder\external\filters\set;
2021
use PHPUnit\Framework\ExpectationFailedException;
2122
use question_attempt_step;
2223
use SebastianBergmann\RecursionContext\InvalidArgumentException;
@@ -42,9 +43,13 @@ final class question_test extends \advanced_testcase {
4243

4344
/**
4445
* Instance of the question type class
45-
* @var qtype_aitext
46+
* @var question
4647
*/
4748
public $question;
49+
<<<<<<< HEAD
50+
=======
51+
52+
>>>>>>> main
4853
/**
4954
* There is a live connection to the External AI system
5055
* When run locally it will make a connection. Otherwise the
@@ -119,6 +124,32 @@ public function test_get_question_summary(): void {
119124
$this->assertEquals('Hello [world]', $aitext->get_question_summary());
120125
}
121126

127+
/**
128+
* Check on some permutations of how the prompt that is sent to the
129+
* LLM is constructed
130+
* @covers ::build_full_ai_prompt
131+
*/
132+
public function test_build_full_ai_prompt() :void {
133+
$this->resetAfterTest();
134+
135+
$question = qtype_aitext_test_helper::make_aitext_question([]);
136+
set_config('prompt', 'in [responsetext] ','qtype_aitext');
137+
set_config('defaultprompt', 'check this','qtype_aitext');
138+
set_config('markscheme', 'one mark','qtype_aitext');
139+
set_config('jsonprompt', 'testprompt','qtype_aitext');
140+
141+
$response = '<p> Thank you </p>';
142+
$result = $question->build_full_ai_prompt($response, $aiprompt, $defaultmark, $markscheme);
143+
144+
$this->assertStringContainsString('[[ Thank you ]]', $result);
145+
// HTML tags should be stripped out.
146+
$this->assertStringNotContainsString('<p>', $result);
147+
148+
$markscheme = "2 points";
149+
$result = $question->build_full_ai_prompt($response, $aiprompt, $defaultmark, $markscheme);
150+
$this->assertStringContainsString('2 points', $result);
151+
}
152+
122153
/**
123154
* Check that non valid json returned from the LLM is
124155
* dealt with gracefully

0 commit comments

Comments
 (0)