MDL-87267 aiplacement_courseassist: Improve response formatting

This commit is contained in:
raortegar
2025-12-03 11:16:44 +07:00
committed by Huong Nguyen
parent 672b2a9074
commit 83ee815775
2 changed files with 4 additions and 2 deletions
@@ -92,10 +92,11 @@ class explain_text extends external_api {
// Send the action to the AI manager.
$manager = \core\di::get(\core_ai\manager::class);
$response = $manager->process_action($action);
$generatedcontent = $response->get_response_data()['generatedcontent'] ?? '';
// Return the response.
return [
'success' => $response->get_success(),
'generatedcontent' => $response->get_response_data()['generatedcontent'] ?? '',
'generatedcontent' => \core_external\util::format_text($generatedcontent, FORMAT_PLAIN, $contextid)[0],
'finishreason' => $response->get_response_data()['finishreason'] ?? '',
'errorcode' => $response->get_errorcode(),
'error' => $response->get_errormessage(),
@@ -92,10 +92,11 @@ class summarise_text extends external_api {
// Send the action to the AI manager.
$manager = \core\di::get(\core_ai\manager::class);
$response = $manager->process_action($action);
$generatedcontent = $response->get_response_data()['generatedcontent'] ?? '';
// Return the response.
return [
'success' => $response->get_success(),
'generatedcontent' => $response->get_response_data()['generatedcontent'] ?? '',
'generatedcontent' => \core_external\util::format_text($generatedcontent, FORMAT_PLAIN, $contextid)[0],
'finishreason' => $response->get_response_data()['finishreason'] ?? '',
'errorcode' => $response->get_errorcode(),
'error' => $response->get_errormessage(),