Plugin: AI Helper: Add styles link for header in lp content using OpenAi - refs #4606

Author: @christianbeeznest
pull/4624/head
christianbeeznest 3 years ago committed by GitHub
parent 95c138c81b
commit 03d246bc3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      plugin/ai_helper/tool/learnpath.php

@ -4,6 +4,9 @@
/**
Create a learnpath with contents based on existing knowledge.
*/
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
require_once __DIR__.'/../../../main/inc/global.inc.php';
require_once __DIR__.'/../AiHelperPlugin.php';
require_once api_get_path(SYS_CODE_PATH).'exercise/export/aiken/aiken_classes.php';
@ -44,6 +47,13 @@ switch ($apiName) {
$lpItems = [];
if (!empty($resultText)) {
$style = api_get_css_asset('bootstrap/dist/css/bootstrap.min.css');
$style .= api_get_css_asset('fontawesome/css/font-awesome.min.css');
$style .= api_get_css(ChamiloApi::getEditorDocStylePath());
$style .= api_get_css_asset('ckeditor/plugins/codesnippet/lib/highlight/styles/default.css');
$style .= api_get_asset('ckeditor/plugins/codesnippet/lib/highlight/highlight.pack.js');
$style .= '<script>hljs.initHighlightingOnLoad();</script>';
$items = explode(',', $resultText);
$position = 1;
foreach ($items as $item) {
@ -54,7 +64,13 @@ switch ($apiName) {
$messageGetItemContent = 'In the context of "%s", generate a document with HTML tags in "%s" with %d words of content or less, about "%s"';
$promptItem = sprintf($messageGetItemContent, $topic, $courseLanguage, $wordsCount, $title);
$resultContentText = $plugin->openAiGetCompletionText($promptItem, 'learnpath');
$lpItems[$position]['content'] = (!empty($resultContentText) ? trim($resultContentText) : '');
$lpItemContent = (!empty($resultContentText) ? trim($resultContentText) : '');
if (false !== stripos($lpItemContent, '</head>')) {
$lpItemContent = preg_replace("|</head>|i", "\r\n$style\r\n\\0", $lpItemContent);
} else {
$lpItemContent = '<html><head><title>'.trim($title).'</title>'.$style.'</head><body>'.$lpItemContent.'</body></html>';
}
$lpItems[$position]['content'] = $lpItemContent;
$position++;
}
}

Loading…
Cancel
Save