|
33 | 33 | $addTests = ('true' === $_REQUEST['add_tests']); |
34 | 34 | $nQ = ($addTests ? (int) $_REQUEST['nro_questions'] : 0); |
35 | 35 |
|
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.'; |
37 | 37 | $prompt = sprintf($messageGetItems, $courseLanguage, $chaptersCount, $topic); |
38 | 38 | $resultText = $plugin->openAiGetCompletionText($prompt, 'learnpath'); |
39 | 39 |
|
|
54 | 54 | $style .= api_get_asset('ckeditor/plugins/codesnippet/lib/highlight/highlight.pack.js'); |
55 | 55 | $style .= '<script>hljs.initHighlightingOnLoad();</script>'; |
56 | 56 |
|
57 | | - $items = explode(',', $resultText); |
| 57 | + $items = explode("\n", $resultText); |
58 | 58 | $position = 1; |
59 | 59 | foreach ($items as $item) { |
| 60 | + if (substr($item, 0, 2) === '- ') { |
| 61 | + $item = substr($item, 2); |
| 62 | + } |
60 | 63 | $explodedItem = preg_split('/\d\./', $item); |
61 | 64 | $title = count($explodedItem) > 1 ? $explodedItem[1] : $explodedItem[0]; |
62 | 65 | if (!empty($title)) { |
63 | 66 | $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); |
66 | 69 | $resultContentText = $plugin->openAiGetCompletionText($promptItem, 'learnpath'); |
67 | 70 | $lpItemContent = (!empty($resultContentText) ? trim($resultContentText) : ''); |
68 | 71 | if (false !== stripos($lpItemContent, '</head>')) { |
|
0 commit comments