Skip to content

Commit

Permalink
Type hints on function return valuesw
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusgreen committed May 30, 2024
1 parent 94ac09c commit fdee5f8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ class qtype_aitext_external extends external_api {
*
* @return void
*/
public static function fetch_ai_grade_parameters() {
public static function fetch_ai_grade_parameters(): external_function_parameters {
return new external_function_parameters(
array('response' => new external_value(PARAM_TEXT, 'The students response to question'),
['response' => new external_value(PARAM_TEXT, 'The students response to question'),
'defaultmark' => new external_value(PARAM_INT, 'The total possible score'),
'prompt' => new external_value(PARAM_TEXT, 'The AI Prompt'),
'marksscheme' => new external_value(PARAM_TEXT, 'The marks scheme')
)
]
);

}
Expand All @@ -62,14 +62,15 @@ public static function fetch_ai_grade_parameters() {
*/
public static function fetch_ai_grade($response, $defaultmark, $prompt, $marksscheme) {
// Get our AI helper.
xdebug_break();

$ai = new ai\ai();

// Build an aitext question instance so we can call the same code that the question type uses when it grades.
$type = 'aitext';
\question_bank::load_question_definition_classes($type);
$aiquestion = new qtype_aitext_question();
$aiquestion->qtype = \question_bank::get_qtype('aitext');

// Make sure we have the right data for AI to work with.
if (!empty($response) && !empty($prompt) && $defaultmark > 0) {
$fullaiprompt = $aiquestion->build_full_ai_prompt($response, $prompt, $defaultmark, $marksscheme);
Expand All @@ -90,9 +91,9 @@ public static function fetch_ai_grade($response, $defaultmark, $prompt, $markssc
*
* @return void
*/
public static function fetch_ai_grade_returns() {
public static function fetch_ai_grade_returns(): external_single_structure {
return new external_single_structure([
'feedback' => new external_value(PARAM_TEXT, 'text feedback for display to student', VALUE_DEFAULT),
'feedback' => new external_value(PARAM_CLEANHTML, 'text feedback for display to student', VALUE_DEFAULT),
'marks' => new external_value(PARAM_FLOAT, 'AI grader awarded marks for student response', VALUE_DEFAULT),
]);

Expand Down

0 comments on commit fdee5f8

Please sign in to comment.