Skip to content

Commit 59cc88e

Browse files
committed
Plugin: AI Helper: Improve prompt for learning path items
1 parent 63d9dec commit 59cc88e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

plugin/ai_helper/tool/learnpath.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
$addTests = ('true' === $_REQUEST['add_tests']);
3434
$nQ = ($addTests ? (int) $_REQUEST['nro_questions'] : 0);
3535

36-
$messageGetItems = 'Generate the table of contents of a course in "%s" in %d or less chapters on the topic of "%s" in a list separated with comma, without chapter number. Do not include a conclusion chapter.';
36+
$messageGetItems = 'Generate the table of contents of a course in "%s" in %d or less chapters on the topic of "%s" and return it as a list of items separated by CRLF. Do not provide chapter numbering. Do not include a conclusion chapter.';
3737
$prompt = sprintf($messageGetItems, $courseLanguage, $chaptersCount, $topic);
3838
$resultText = $plugin->openAiGetCompletionText($prompt, 'learnpath');
3939

@@ -54,15 +54,18 @@
5454
$style .= api_get_asset('ckeditor/plugins/codesnippet/lib/highlight/highlight.pack.js');
5555
$style .= '<script>hljs.initHighlightingOnLoad();</script>';
5656

57-
$items = explode(',', $resultText);
57+
$items = explode("\n", $resultText);
5858
$position = 1;
5959
foreach ($items as $item) {
60+
if (substr($item, 0, 2) === '- ') {
61+
$item = substr($item, 2);
62+
}
6063
$explodedItem = preg_split('/\d\./', $item);
6164
$title = count($explodedItem) > 1 ? $explodedItem[1] : $explodedItem[0];
6265
if (!empty($title)) {
6366
$lpItems[$position]['title'] = trim($title);
64-
$messageGetItemContent = 'In the context of "%s", generate a document with HTML tags in "%s" with %d words of content or less, about "%s"';
65-
$promptItem = sprintf($messageGetItemContent, $topic, $courseLanguage, $wordsCount, $title);
67+
$messageGetItemContent = 'In the context of "%s", generate a document with HTML tags in "%s" with %d words of content or less, about "%s", as to be included as one chapter in a larger document on "%s". Consider the context is established for the reader and you do not need to repeat it.';
68+
$promptItem = sprintf($messageGetItemContent, $topic, $courseLanguage, $wordsCount, $title, $topic);
6669
$resultContentText = $plugin->openAiGetCompletionText($promptItem, 'learnpath');
6770
$lpItemContent = (!empty($resultContentText) ? trim($resultContentText) : '');
6871
if (false !== stripos($lpItemContent, '</head>')) {

0 commit comments

Comments
 (0)