@@ -107,35 +107,30 @@ public function test_get_question_summary(): void {
107107 }
108108
109109 /**
110- * Check on some permutations of how the prompt that is sent to the
111- * LLM is constructed
112- * @covers ::build_full_ai_prompt
110+ * Check the student response gets interpolated into the prompt ready to send
111+ * off to the LLM
112+ * @covers \qtype_aitext\question ::build_full_ai_prompt
113113 */
114114 public function test_build_full_ai_prompt (): void {
115- $ this ->resetAfterTest ();
116- if (!$ this ->islive ) {
117- $ this ->markTestSkipped ('No live connection to the AI system ' );
118- }
119-
115+ $ this ->resetAfterTest (true );
120116 $ question = qtype_aitext_test_helper::make_aitext_question ([]);
121- set_config ( ' prompt ' , ' in [responsetext] ' , ' qtype_aitext ' ) ;
122- set_config ( ' defaultprompt ' , ' check this ' , ' qtype_aitext ' ) ;
123- set_config ( ' markscheme ' , ' one mark' , ' qtype_aitext ' ) ;
124- set_config ( ' jsonprompt ' , ' testprompt ' , ' qtype_aitext ' ) ;
125-
126- $ response = ' <p> Thank you </p> ' ;
127- $ aiprompt = '' ;
128- $ defaultmark = '' ;
129- $ markscheme = '' ;
130- $ result = $ question -> build_full_ai_prompt ( $ response , $ aiprompt , $ defaultmark , $ markscheme ) ;
131-
132- $ this -> assertStringContainsString ( ' [[ Thank you ]] ' , $ result );
133- // HTML tags should be stripped out.
117+ $ question -> questiontext = ' Write an English sentence in the past tense ' ;
118+ $ aiprompt = " Is the text gramatically correct? " ;
119+ $ markscheme = ' One mark if the response is gramatically correct ' ;
120+ $ studentresponse = ' Yesterday I went to the park ' ;
121+ $ defaultmark = 1 ;
122+
123+ $ result = ( string ) $ question -> build_full_ai_prompt ( $ studentresponse , $ aiprompt , $ defaultmark , $ markscheme ) ;
124+
125+ // Student response is within [ ] delimters. Angle brackets might be better, e.g. <<<< >>>>.
126+ $ pattern = ' /\[\[ ' . $ studentresponse . ' \]\]/ ' ;
127+ $ this -> assertEquals ( 1 , preg_match ( $ pattern , $ result ));
128+
129+ // HTML tags should be stripped out, though that might change in the future .
134130 $ this ->assertStringNotContainsString ('<p> ' , $ result );
135131
136- $ markscheme = "2 points " ;
137- $ result = $ question ->build_full_ai_prompt ($ response , $ aiprompt , $ defaultmark , $ markscheme );
138- $ this ->assertStringContainsString ('2 points ' , $ result );
132+ // Marks scheme should be in result ready to send to LLm. Though it is optional.
133+ $ this ->assertStringContainsString ($ markscheme , $ result );
139134 }
140135
141136 /**
0 commit comments