Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/tutorai/Prompts.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Helper class for creating the AI prompts for text generation.
4
+
*
5
+
* @package TutorPro\TutorAI
6
+
* @author Themeum <support@themeum.com>
7
+
* @link https://themeum.com
8
+
* @since 3.0.0
9
+
*/
10
+
11
+
namespace TutorPro\TutorAI;
12
+
13
+
if ( ! defined( 'ABSPATH' ) ) {
14
+
exit;
15
+
}
16
+
17
+
/**
18
+
* Helper class for generating AI prompts used by openai.
19
+
*
20
+
* @since 3.0.0
21
+
*/
22
+
final class Prompts {
23
+
/**
24
+
* Create the system message for generating text content using tone, format, language, etc.
25
+
*
26
+
* @since 3.0.0
27
+
*
28
+
* @param array $input The request payload inputs for generating the prompt.
29
+
*
30
+
* @return string
31
+
*/
32
+
private static function create_system_message( array $input ) {
33
+
$system_content = 'You are a friendly and helpful assistant. You will be given a prompt, and your task is to generate a {format} for an online course. The content should be in {language} and have a {tone} tone. Ensure the content does not exceed {characters} characters.';
34
+
35
+
if ( ! $input['is_html'] ) {
36
+
$system_content .= ' Please respond with plain text only. Do not use markdown, quotation marks, or HTML.';
37
+
}
38
+
39
+
foreach ( $input as $key => $value ) {
40
+
$system_content = str_replace( '{' . $key . '}', $value, $system_content );
41
+
}
42
+
43
+
return $system_content;
44
+
}
45
+
46
+
/**
47
+
* Prepare the input array for generating text content from the request prompt.
48
+
*
49
+
* @since 3.0.0
50
+
*
51
+
* @param array $input The request payload inputs for generating the prompt.
52
+
*
53
+
* @return array
54
+
*/
55
+
public static function prepare_text_generation_messages( array $input ) {
56
+
return array(
57
+
array(
58
+
'role' => 'system',
59
+
'content' => self::create_system_message( $input ),
60
+
),
61
+
array(
62
+
'role' => 'user',
63
+
'content' => $input['prompt'],
64
+
),
65
+
);
66
+
}
67
+
68
+
/**
69
+
* Prepare the input array for translating content to a specific language.
70
+
*
71
+
* @since 3.0.0
72
+
*
73
+
* @param string $content The content to modify.
74
+
* @param bool $is_html If the should come in HTML or plain text.
75
+
* @param string $language The target language.
76
+
*
77
+
* @return array
78
+
*/
79
+
public static function prepare_translation_messages( string $content, bool $is_html, string $language ) {
80
+
$system_content = 'Your task is to translate the provided text into {language}. Identify the original language if needed and ensure the translation accurately conveys the meaning of the original content.';
81
+
$system_content = str_replace( '{language}', $language, $system_content );
82
+
83
+
if ( ! $is_html ) {
84
+
$system_content .= ' Please respond with plain text only. Do not use markdown or HTML.';
85
+
}
86
+
87
+
return array(
88
+
array(
89
+
'role' => 'system',
90
+
'content' => $system_content,
91
+
),
92
+
array(
93
+
'role' => 'user',
94
+
'content' => $content,
95
+
),
96
+
);
97
+
}
98
+
99
+
/**
100
+
* Prepare the input array for rephrasing content
101
+
*
102
+
* @since 3.0.0
103
+
*
104
+
* @param string $content The content to modify.
105
+
* @param bool $is_html If the should come in HTML or plain text.
106
+
*
107
+
* @return array
108
+
*/
109
+
public static function prepare_rephrase_messages( string $content, bool $is_html ) {
110
+
$system_content = 'Your task is to rephrase any text content provided to you, ensuring that the original meaning is preserved while expressing it differently.';
111
+
112
+
if ( ! $is_html ) {
113
+
$system_content .= ' Please respond with plain text only. Do not use markdown or HTML.';
114
+
}
115
+
116
+
return array(
117
+
array(
118
+
'role' => 'system',
119
+
'content' => $system_content,
120
+
),
121
+
array(
122
+
'role' => 'user',
123
+
'content' => $content,
124
+
),
125
+
);
126
+
}
127
+
128
+
/**
129
+
* Prepare the input array for making the content shorten.
130
+
*
131
+
* @since 3.0.0
132
+
*
133
+
* @param string $content The content to modify.
134
+
* @param bool $is_html If the should come in HTML or plain text.
135
+
*
136
+
* @return array
137
+
*/
138
+
public static function prepare_make_shorter_messages( string $content, bool $is_html ) {
139
+
$system_content = 'Your task is to shorten the provided text, retaining the key points and meaning while making it as concise as possible.';
140
+
141
+
if ( ! $is_html ) {
142
+
$system_content .= ' Please respond with plain text only. Do not use markdown or HTML.';
143
+
}
144
+
145
+
return array(
146
+
array(
147
+
'role' => 'system',
148
+
'content' => $system_content,
149
+
),
150
+
array(
151
+
'role' => 'user',
152
+
'content' => $content,
153
+
),
154
+
);
155
+
}
156
+
157
+
/**
158
+
* Prepare the input array for changing the tone of the content.
159
+
*
160
+
* @since 3.0.0
161
+
*
162
+
* @param string $content The content to modify.
163
+
* @param bool $is_html If the should come in HTML or plain text.
164
+
* @param string $tone The target content tone.
165
+
*
166
+
* @return array
167
+
*/
168
+
public static function prepare_change_tone_messages( string $content, bool $is_html, string $tone ) {
169
+
$system_content = "Your task is to change the tone of the provided text to match the specified style, which is {tone}. Ensure that the content's meaning remains consistent while reflecting this new tone.";
170
+
$system_content = str_replace( '{tone}', $tone, $system_content );
171
+
172
+
if ( ! $is_html ) {
173
+
$system_content .= ' Please respond with plain text only. Do not use markdown or HTML.';
174
+
}
175
+
176
+
return array(
177
+
array(
178
+
'role' => 'system',
179
+
'content' => $system_content,
180
+
),
181
+
array(
182
+
'role' => 'user',
183
+
'content' => $content,
184
+
),
185
+
);
186
+
}
187
+
188
+
/**
189
+
* Prepare the input array for converting the content into bullet points.
190
+
*
191
+
* @since 3.0.0
192
+
*
193
+
* @param string $content The content to modify.
194
+
* @param bool $is_html If the should come in HTML or plain text.
195
+
*
196
+
* @return array
197
+
*/
198
+
public static function prepare_write_as_bullets_messages( string $content, bool $is_html ) {
199
+
$system_content = 'Your task is to rewrite the provided text as bullet points. Ensure that each point is clear and concise while preserving the original meaning.';
200
+
201
+
if ( ! $is_html ) {
202
+
$system_content .= ' Please respond with plain text only. Do not use markdown or HTML.';
203
+
}
204
+
205
+
return array(
206
+
array(
207
+
'role' => 'system',
208
+
'content' => $system_content,
209
+
),
210
+
array(
211
+
'role' => 'user',
212
+
'content' => $content,
213
+
),
214
+
);
215
+
}
216
+
217
+
/**
218
+
* Prepare the input array for making the content larger.
219
+
*
220
+
* @since 3.0.0
221
+
*
222
+
* @param string $content The content to modify.
223
+
* @param bool $is_html If the should come in HTML or plain text.
224
+
*
225
+
* @return array
226
+
*/
227
+
public static function prepare_make_longer_messages( string $content, bool $is_html ) {
228
+
$system_content = 'Your task is to expand the provided text, adding more detail and depth while maintaining the original meaning and intent.';
229
+
230
+
if ( ! $is_html ) {
231
+
$system_content .= ' Please respond with plain text only. Do not use markdown or HTML.';
232
+
}
233
+
234
+
return array(
235
+
array(
236
+
'role' => 'system',
237
+
'content' => $system_content,
238
+
),
239
+
array(
240
+
'role' => 'user',
241
+
'content' => $content,
242
+
),
243
+
);
244
+
}
245
+
246
+
/**
247
+
* Prepare the input array for simplifying the language of the generated content.
248
+
*
249
+
* @since 3.0.0
250
+
*
251
+
* @param string $content The content to modify.
252
+
* @param bool $is_html If the should come in HTML or plain text.
253
+
*
254
+
* @return array
255
+
*/
256
+
public static function prepare_simplify_language_messages( string $content, bool $is_html ) {
257
+
$system_content = 'Your task is to simplify the language of the provided text, making it easier to understand while preserving the original meaning.';
258
+
259
+
if ( ! $is_html ) {
260
+
$system_content .= ' Please respond with plain text only. Do not use markdown or HTML.';
261
+
}
262
+
263
+
return array(
264
+
array(
265
+
'role' => 'system',
266
+
'content' => $system_content,
267
+
),
268
+
array(
269
+
'role' => 'user',
270
+
'content' => $content,
271
+
),
272
+
);
273
+
}
274
+
275
+
/**
276
+
* Prepare the input array for creating the course title.
277
+
*
278
+
* @since 3.0.0
279
+
*
280
+
* @param string $prompt The input prompt for generating course title.
281
+
*
282
+
* @return array
283
+
*/
284
+
public static function prepare_course_title_messages( string $prompt ) {
285
+
return array(
286
+
array(
287
+
'role' => 'system',
288
+
'content' => 'You are a highly skilled assistant specialized in generating course titles for an e-learning platform. When provided with a prompt describing a course, your task is to create a concise, compelling, and marketable course title. The title should be clear, engaging, and appropriate for the specified audience, which could range from beginners to advanced learners. Ensure that the title reflects the course content accurately and consider the use of impactful language that highlights the value of the course. Do not use markdown or HTML, do not wrap the content with quotes, and the title should not exceed 100 characters.',
289
+
),
290
+
array(
291
+
'role' => 'user',
292
+
'content' => $prompt,
293
+
),
294
+
);
295
+
}
296
+
297
+
/**
298
+
* Prepare the course description with the help of the course title.
299
+
*
300
+
* @since 3.0.0
301
+
*
302
+
* @param string $title The course title.
303
+
*
304
+
* @return array
305
+
*/
306
+
public static function prepare_course_description_messages( string $title ) {
307
+
return array(
308
+
array(
309
+
'role' => 'system',
310
+
'content' => 'You are an AI assistant that specializes in generating detailed course descriptions for an e-learning platform. Based on the provided course title, your task is to create a compelling and informative course description that includes the following elements: an overview of the course content, key learning outcomes, and a clear identification of the target audience. The description should be engaging, informative, and accurately reflect the skills and knowledge students will gain. Ensure that the language is accessible, with a tone that is both motivating and professional, and tailored to the specified audience, whether they are beginners, intermediate learners, or advanced professionals. Please respond with plain text only.',
311
+
),
312
+
array(
313
+
'role' => 'user',
314
+
'content' => $title,
315
+
),
316
+
);
317
+
}
318
+
319
+
/**
320
+
* Prepare the messages for openai for generating topic names.
321
+
*
322
+
* @since 3.0.0
323
+
*
324
+
* @param string $title The course title.
325
+
*
326
+
* @return array
327
+
*/
328
+
public static function prepare_course_topic_names_messages( string $title ) {
329
+
$system_content = 'You are an AI assistant specialized in generating course module names. You are tasked with generating course module names for a given course title. Based on this course title, create at most 5 modules names that follow a logical progression, starting with introductory topics and moving toward more advanced concepts. Ensure that the module names include standard course elements like an introduction, a course outline, and a conclusion. The names should be clear, concise, and directly related to the content of the course. Return the module names as a JSON array in the format: [{title: "Module title"}].';
330
+
331
+
return array(
332
+
array(
333
+
'role' => 'system',
334
+
'content' => $system_content,
335
+
),
336
+
array(
337
+
'role' => 'user',
338
+
'content' => $title,
339
+
),
340
+
);
341
+
}
342
+
343
+
/**
344
+
* Prepare the messages for openai for generating topic contents.
345
+
*
346
+
* @since 3.0.0
347
+
*
348
+
* @param string $title The course title.
349
+
* @param string $topic_name The topic name.
350
+
*
351
+
* @return array
352
+
*/
353
+
public static function prepare_course_topic_content_messages( string $title, string $topic_name ) {
354
+
$is_assignment_addon_enabled = tutor_utils()->is_addon_enabled( TUTOR_ASSIGNMENTS()->basename );
355
+
356
+
$content_types = array( 'lesson', 'quiz' );
357
+
if ( $is_assignment_addon_enabled ) {
358
+
$content_types[] = 'assignment';
359
+
}
360
+
361
+
$content_types_string = implode( "', '", $content_types );
362
+
363
+
$system_content = 'You are an AI assistant specialized in generating course contents. Generate at most 5 content items based on the provided course title and module name. The content can include any of the following types: \'' . $content_types_string . '\'. For each content item, provide a title and a description that accurately reflects the content. Return the generated content as a JSON array with the structure: [{type: "' . implode( '|', $content_types ) . '", title: "the content title", description: "the content description"}].';
364
+
365
+
return array(
366
+
array(
367
+
'role' => 'system',
368
+
'content' => $system_content,
369
+
),
370
+
array(
371
+
'role' => 'user',
372
+
'content' => 'The course title is: ' . $title,
373
+
),
374
+
array(
375
+
'role' => 'user',
376
+
'content' => 'The module name is: ' . $topic_name,
377
+
),
378
+
);
379
+
}
380
+
381
+
/**
382
+
* Prepare the messages for the openai chat API for generating quiz content.
383
+
*
384
+
* @since 3.0.0
385
+
*
386
+
* @param string $title The course title.
387
+
* @param string $topic_name The course module/topic name.
388
+
* @param string $quiz_title The quiz title.
389
+
*
390
+
* @return array
391
+
*/
392
+
public static function prepare_quiz_questions_messages( string $title, string $topic_name, string $quiz_title ) {
393
+
$system_content = "You are an intelligent assistant tasked with creating quiz questions for a course. You are provided a course title, a course module name, and a quiz title.
394
+
Please generate at most 3 quiz questions of the following types:
395
+
- True/False
396
+
- Multiple Choice
397
+
- Open-Ended
398
+
399
+
Each question must have:
400
+
- A clear question title.
401
+
- A brief description that adds context to the question.
402
+
- For true/false questions: two options - 'true' and 'false'.
403
+
- For multiple-choice questions: several answer options with one correct answer.
404
+
- For open-ended questions: no options (only the question and description).
405
+
406
+
Special reminder, **please generate the true/false questions as less as possible, prioritize multiple-choice questions more**.
407
+
Additionally, please ensure that some of the questions have a question mark ('?') as the value of the title.
408
+
409
+
The response should be in **valid JSON** format as follows, and make sure not to use any suffix or prefix with the response:
410
+
411
+
[
412
+
{
413
+
'title': 'the question title?',
414
+
'type': 'true_false|open_ended|multiple_choice',
415
+
'options': [
416
+
{
417
+
'name': 'option name',
418
+
'is_correct': true
419
+
},
420
+
{
421
+
'name': 'option name',
422
+
'is_correct': false
423
+
}
424
+
]
425
+
}
426
+
]
427
+
428
+
Please ensure that the provided JSON is valid and properly structured. Include a variety of question types (true/false, multiple-choice, and open-ended), and make sure the content relates to the course and module.
429
+
Make sure the number of questions falls between 3 to 5, with some having '?' as the title.
430
+
";
431
+
432
+
return array(
433
+
array(
434
+
'role' => 'system',
435
+
'content' => $system_content,
436
+
),
437
+
array(
438
+
'role' => 'user',
439
+
'content' => 'The course title: ' . $title,
440
+
),
441
+
array(
442
+
'role' => 'user',
443
+
'content' => 'The module name: ' . $topic_name,
444
+
),
445
+
array(
446
+
'role' => 'user',
447
+
'content' => 'The quiz title: ' . $quiz_title,
448
+
),
449
+
);
450
+
}
451
+
}
452
+