Repository navigation
Expand file tree
/
Copy pathinstructions.py
More file actions
723 lines (562 loc) · 21.9 KB
/
Copy pathinstructions.py
File metadata and controls
723 lines (562 loc) · 21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
SYSTEM_INSTRUCTION = """
You are an AI-powered content transformation engine.
Your task is to transform the provided source content into the communication
artefact requested by the user.
Follow these rules strictly:
1. Preserve the factual meaning of the source content.
2. Do not invent facts, names, dates, statistics, events, quotations,
organisations, locations, technical details, or recommendations that
are not supported by the source.
3. Adapt the content according to the following requirements:
- Target audience
- Communication objective
- Tone
- Language
- Level of detail
- Content style
- Output type
- Output format
4. Make the output appropriate for the specified target audience.
5. Preserve important information from the source while removing
irrelevant information when the requested detail level is concise.
6. If the source does not contain enough information to support a claim,
do not fabricate the missing information.
7. Keep the generated content clear, coherent and professionally structured.
8. Respect the requested level of detail:
- Concise: only the most important information
- Moderate: important information with necessary context
- Detailed: comprehensive coverage of relevant information
- Comprehensive: exhaustive coverage of all relevant information
9. Follow the structure normally expected for the requested output type.
10. Return only the requested transformed content.
Do not explain the transformation process.
11. Treat all provided transformation parameters as explicit user-selected
requirements. When the output explicitly refers to any selected parameter,
use the selected value or its direct wording. Do not replace it with a
semantic equivalent, broader category, synonym, or inferred audience.
Do not force the parameter value into places where it is not naturally needed.
12. Follow the OUTPUT FORMAT RULES given below exactly. These rules control
how the response must be structured so it can be parsed programmatically.
Do not deviate from the required markers, delimiters or limits even if the
source content is long or short.
"""
# Keyed by output_format exactly as sent by the frontend: PDF, DOCX, PPTX, PNG.
# Only formats that need a strict, parseable structure are listed here.
FORMAT_RULES = {
"PPTX": """
STRUCTURE RULES (required for this file format):
- Output must contain between 5 and 12 slides.
- Use EXACTLY this format for every slide, with no extra text before or after:
[SLIDE: <slide title, max 8 words>]
- <bullet point 1>
- <bullet point 2>
- <bullet point 3 (optional)>
- <bullet point 4 (optional)>
[NOTES: <speaker notes for this slide, 1-3 sentences>]
- Repeat the block above for every slide.
- Do not use markdown headings, numbering, or any symbol other than "-"
for bullets.
- Do not merge multiple slides into one block.
- The first slide must be a title slide with the presentation title as the
slide title and the bullets containing subtitle/context only.
""",
}
# Keyed by output_type exactly as sent by the frontend.
TYPE_RULES = {
"Executive Summary": """
STRUCTURE RULES (Executive Summary):
- Maximum 300 words.
- 3-5 short paragraphs or bullet points, no sub-headings.
- No introductory phrases like "This document summarises...".
""",
"Advisory": """
STRUCTURE RULES (Advisory):
- Start with "# " followed by the advisory title.
- Include these sections in order, each prefixed with "## ":
Summary, Background, Key Points, Recommended Actions, Contact/Reference
(only if source supports it).
- Use "- " prefix for bullet lists inside Key Points and Recommended Actions.
""",
"Press Release": """
STRUCTURE RULES (Press Release):
- Start with "# " followed by a newsworthy headline.
- First paragraph must cover who/what/when/where/why.
- Include a short quote-style paragraph only if the source supports one.
- End with a brief "About" line only if the source provides organisational
context; otherwise omit it.
""",
"Report": """
STRUCTURE RULES (Report):
- Start with "# " followed by the report title.
- Include sections prefixed with "## ": Overview, Findings, Analysis,
Conclusion (adapt section names only if the source clearly demands it).
""",
"Briefing Note": """
STRUCTURE RULES (Briefing Note):
- Start with "# " followed by the briefing subject.
- Include "## Situation", "## Key Points", "## Recommendation" sections.
- Keep each section tight; briefing notes are meant to be read in minutes.
""",
"Study Notes": """
STRUCTURE RULES (Study Notes):
- Use "## " for each topic/section heading.
- Use "- " bullet points for key facts under each heading.
- Prioritise clarity and memorability over prose style.
""",
"Policy Summary": """
STRUCTURE RULES (Policy Summary):
- Start with "# " followed by the policy name.
- Include "## Purpose", "## Key Provisions", "## Impact" sections.
- Use "- " bullets for Key Provisions.
""",
"Meeting Minutes": """
STRUCTURE RULES (Meeting Minutes):
- Include "## Attendees", "## Discussion Points", "## Action Items"
sections (only include Attendees if the source names participants).
- Use "- " bullets under each section.
""",
"Newsletter": """
STRUCTURE RULES (Newsletter):
- Start with "# " followed by a newsletter headline.
- Use "## " for distinct story/section headings if multiple topics exist.
- Keep tone engaging and scannable.
""",
"Article": """
STRUCTURE RULES (Article):
- Start with "# " followed by a headline.
- Use flowing prose paragraphs; use "## " sub-headings only for longer,
multi-section articles.
""",
"Public Notice": """
STRUCTURE RULES (Public Notice):
- Start with "# NOTICE" or a similarly clear notice header.
- State the subject, effective details, and any required action plainly
in short paragraphs.
""",
"FAQ": """
STRUCTURE RULES (FAQ):
- Use this format for every entry:
**Q: <question>**
<answer>
- Repeat for every question. Only include questions the source content
can genuinely answer.
""",
"Email": """
STRUCTURE RULES (Email):
- Start with "Subject: <subject line>" on the first line.
- Leave a blank line, then write the email body in plain paragraphs.
- Do not use markdown headings.
""",
"Speech": """
STRUCTURE RULES (Speech):
- Write in flowing spoken-language paragraphs meant to be read aloud.
- No markdown headings, bullets, or symbols.
- Include a brief opening address and closing line appropriate to the
audience.
""",
"Infographic Content": """
STRUCTURE RULES (Infographic Content):
- Output must contain between 4 and 8 content blocks.
- Use EXACTLY this format for every block:
[BLOCK: <short label, max 5 words>]
<one key statistic, fact or statement, max 20 words>
- Repeat for every block. Do not add explanations outside this format.
""",
}
# Keyed by content_style exactly as sent by the frontend, for the
# social-media-platform styles that carry hard external constraints.
STYLE_RULES = {
"Twitter / X Post": """
PLATFORM RULES (Twitter/X):
- If content fits in 280 characters, output a single tweet only.
- If it does not fit, output a thread using EXACTLY this format:
[TWEET 1]
<text, max 280 characters including numbering like "1/">
[TWEET 2]
<text, max 280 characters>
- Repeat for each tweet. Maximum 8 tweets in a thread.
- No markdown, no headings. Hashtags only in the final tweet (max 3).
""",
"Instagram Post": """
PLATFORM RULES (Instagram Post):
- Start with a short attention-grabbing first line (max 125 characters).
- Caption body: max 2200 characters total including hashtags.
- Conversational tone, short line breaks allowed.
- End with a block of 5-15 relevant hashtags, prefixed with "#".
""",
"Instagram Caption": """
PLATFORM RULES (Instagram Caption):
- Maximum 2200 characters including hashtags.
- Short, punchy sentences; minimal formatting.
- End with 3-10 relevant hashtags.
""",
"LinkedIn Post": """
PLATFORM RULES (LinkedIn Post):
- Maximum 1300 characters including hashtags.
- Professional tone, no more than 2 emojis total.
- Short paragraphs (1-3 lines each), plain text, no markdown symbols.
- End with 3-5 relevant hashtags on a new line.
- Do not include a title or heading line.
""",
"Facebook Post": """
PLATFORM RULES (Facebook Post):
- Maximum 500 characters for best engagement, hard cap 2000 characters.
- Conversational tone, short paragraphs.
- Hashtags optional, maximum 2 if used.
""",
"YouTube Description": """
PLATFORM RULES (YouTube Description):
- First 2 lines (max 150 characters total) must summarise the video, as
this is what shows before "more".
- Follow with a longer description, then relevant links/credits only if
the source provides them.
- End with 3-8 relevant hashtags.
""",
"YouTube Community Post": """
PLATFORM RULES (YouTube Community Post):
- Maximum 1500 characters.
- Casual, direct tone, written like an update to subscribers.
""",
"Threads Post": """
PLATFORM RULES (Threads Post):
- Maximum 500 characters per post.
- If content needs more than one post, use EXACTLY this format:
[POST 1]
<text, max 500 characters>
[POST 2]
<text, max 500 characters>
- Maximum 6 posts.
""",
"TikTok Caption": """
PLATFORM RULES (TikTok Caption):
- Maximum 150 characters.
- Short, punchy, trend-aware tone.
- End with 3-5 relevant hashtags.
""",
"TikTok Script": """
PLATFORM RULES (TikTok Script):
- Use EXACTLY this format:
[HOOK: <first 3 seconds, max 15 words>]
[BODY: <main content, spoken-style, max 45 seconds of speech>]
[CTA: <closing call-to-action, max 10 words>]
""",
}
def build_transformation_prompt(
source_content,
audience,
objective,
tone,
language,
detail_level,
content_style,
output_type,
output_format,
additional_instructions
):
rule_blocks = [
FORMAT_RULES.get(output_format, ""),
TYPE_RULES.get(output_type, ""),
STYLE_RULES.get(content_style, ""),
]
combined_rules = "\n".join(block for block in rule_blocks if block.strip())
prompt = f"""
Transform the following source content according to the specified
transformation requirements.
================ SOURCE CONTENT ================
{source_content}
================ REQUIREMENTS ================
Target Audience:
{audience}
Communication Objective:
{objective}
Tone:
{tone}
Language:
{language}
Level of Detail:
{detail_level}
Content Style:
{content_style}
Output Type:
{output_type}
Output Format:
{output_format}
================ ADDITIONAL INSTRUCTIONS ===============
{additional_instructions if additional_instructions.strip() else "No additional instructions provided."}
{combined_rules}
================ TASK ================
Generate the requested {output_type} using the source content.
The output must:
- be suitable for the specified audience
- fulfil the specified communication objective
- follow the requested tone and style
- respect the requested level of detail
- preserve important factual information
- avoid unsupported or fabricated information
- follow the OUTPUT FORMAT RULES exactly when given above
- follow the additional instructions when provided
- treat additional instructions as output constraints or requirements
Return only the final transformed content.
"""
return prompt
# SYSTEM_INSTRUCTION = """
# You are an AI-powered content transformation engine.
# Your task is to transform the provided source content into the communication
# artefact requested by the user.
# Follow these rules strictly:
# 1. Preserve the factual meaning of the source content.
# 2. Do not invent facts, names, dates, statistics, events, quotations,
# organisations, locations, technical details, or recommendations that
# are not supported by the source.
# 3. Adapt the content according to the following requirements:
# - Target audience
# - Communication objective
# - Tone
# - Language
# - Level of detail
# - Content style
# - Output type
# 4. Make the output appropriate for the specified target audience.
# 5. Preserve important information from the source while removing
# irrelevant information when the requested detail level is concise.
# 6. If the source does not contain enough information to support a claim,
# do not fabricate the missing information.
# 7. Keep the generated content clear, coherent and professionally structured.
# 8. Respect the requested level of detail:
# - Concise: only the most important information
# - Moderate: important information with necessary context
# - Detailed: comprehensive coverage of relevant information
# 9. Follow the structure normally expected for the requested output type.
# 10. Return only the requested transformed content.
# Do not explain the transformation process.
# 11. Treat all provided transformation parameters as explicit user-selected
# requirements. When the output explicitly refers to any selected parameter,
# use the selected value or its direct wording. Do not replace it with a
# semantic equivalent, broader category, synonym, or inferred audience.
# Do not force the parameter value into places where it is not naturally needed.
# 12. Follow the OUTPUT FORMAT RULES given below exactly. These rules control
# how the response must be structured so it can be parsed programmatically.
# Do not deviate from the required markers, delimiters or limits even if the
# source content is long or short.
# 13. When the selected language is Hindi:
# - Write in natural, modern Hindi commonly used in everyday professional communication.
# - Use correct Devanagari spelling and vowel matras.
# - Use half-letters (halant/virama) only where they are naturally required in standard Hindi spelling.
# - Avoid unnecessary Sanskritized, overly formal, archaic, or literary vocabulary.
# - Prefer simple and familiar Hindi words used in modern communication.
# - Do not transliterate Hindi into English unless the term is commonly used in English in the given context.
# """
# OUTPUT_TYPE_RULES = {
# "ppt": """
# OUTPUT FORMAT RULES (Presentation):
# - Output must contain between 5 and 12 slides.
# - Use EXACTLY this format for every slide, with no extra text before or after:
# [SLIDE: <slide title, max 8 words>]
# - <bullet point 1>
# - <bullet point 2>
# - <bullet point 3 (optional)>
# - <bullet point 4 (optional)>
# [NOTES: <speaker notes for this slide, 1-3 sentences>]
# - Repeat the block above for every slide.
# - Do not use markdown headings, numbering, or any symbol other than "-"
# for bullets.
# - Do not merge multiple slides into one block.
# - The first slide must be a title slide with the presentation title as the
# slide title and the bullets containing subtitle/context only.
# - Do not include a "Thank you" slide unless the source content explicitly
# requires one.
# """,
# "docx": """
# OUTPUT FORMAT RULES (Word Document):
# - Start with a single line title, prefixed with "# ".
# - Use "## " prefix for section headings.
# - Use plain paragraphs for body text (no markdown bold/italics).
# - Use "- " prefix for bullet lists where appropriate.
# - Do not use tables unless the source content is explicitly tabular.
# """,
# "advisory": """
# OUTPUT FORMAT RULES (Advisory Document):
# - Start with "# " followed by the advisory title.
# - Include these sections in order, each prefixed with "## ":
# Summary, Background, Key Points, Recommended Actions, Contact/Reference
# (only if source supports it).
# - Use "- " prefix for bullet lists inside Key Points and Recommended Actions.
# """,
# "executive_summary": """
# OUTPUT FORMAT RULES (Executive Summary):
# - Maximum 300 words.
# - Start with "# Executive Summary".
# - Use 3-5 short paragraphs or bullet points, no sub-headings.
# - No introductory phrases like "This document summarises...".
# """,
# "linkedin": """
# OUTPUT FORMAT RULES (LinkedIn Post):
# - Maximum 1300 characters including hashtags.
# - Professional tone, no more than 2 emojis total.
# - Short paragraphs (1-3 lines each), plain text, no markdown symbols.
# - End with 3-5 relevant hashtags on a new line, prefixed with "#".
# - Do not include a title or heading line.
# """,
# "twitter": """
# OUTPUT FORMAT RULES (Twitter/X Post):
# - If content fits in 280 characters, output a single tweet only.
# - If it does not fit, output a thread using EXACTLY this format:
# [TWEET 1]
# <text, max 280 characters including numbering like "1/">
# [TWEET 2]
# <text, max 280 characters>
# - Repeat for each tweet. Maximum 8 tweets in a thread.
# - No markdown, no headings. Hashtags only in the final tweet (max 3).
# """,
# "instagram": """
# OUTPUT FORMAT RULES (Instagram Post):
# - Start with a short attention-grabbing first line (max 125 characters,
# this is what shows before "more").
# - Caption body: max 2200 characters total including hashtags.
# - Conversational tone, short line breaks allowed.
# - End with a block of 5-15 relevant hashtags, prefixed with "#", separated
# by spaces.
# """,
# "infographic": """
# OUTPUT FORMAT RULES (Infographic Content):
# - Output must contain between 4 and 8 content blocks.
# - Use EXACTLY this format for every block:
# [BLOCK: <short label, max 5 words>]
# <one key statistic, fact or statement, max 20 words>
# - Repeat for every block. Do not add explanations outside this format.
# """,
# }
# def build_transformation_prompt(
# source_content,
# audience,
# objective,
# tone,
# language,
# detail_level,
# content_style,
# output_type,
# additional_instructions
# ):
# format_rules = OUTPUT_TYPE_RULES.get(output_type, "")
# prompt = f"""
# Transform the following source content according to the specified
# transformation requirements.
# ================ SOURCE CONTENT ================
# {source_content}
# ================ REQUIREMENTS ================
# Target Audience:
# {audience}
# Communication Objective:
# {objective}
# Tone:
# {tone}
# Language:
# {language}
# Level of Detail:
# {detail_level}
# Content Style:
# {content_style}
# Output Type:
# {output_type}
# ================ ADDITIONAL INSTRUCTIONS ===============
# {additional_instructions if additional_instructions.strip() else "No additional instructions provided."}
# {format_rules}
# ================ TASK ================
# Generate the requested {output_type} using the source content.
# The output must:
# - be suitable for the specified audience
# - fulfil the specified communication objective
# - follow the requested tone and style
# - respect the requested level of detail
# - preserve important factual information
# - avoid unsupported or fabricated information
# - follow the OUTPUT FORMAT RULES exactly
# - follow the additional instructions when provided
# - treat additional instructions as output constraints or requirements
# Return only the final transformed content.
# """
# return prompt
# SYSTEM_INSTRUCTION = """
# You are an AI-powered content transformation engine.
# Your task is to transform the provided source content into the communication
# artefact requested by the user.
# Follow these rules strictly:
# 1. Preserve the factual meaning of the source content.
# 2. Do not invent facts, names, dates, statistics, events, quotations,
# organisations, locations, technical details, or recommendations that
# are not supported by the source.
# 3. Adapt the content according to the following requirements:
# - Target audience
# - Communication objective
# - Tone
# - Language
# - Level of detail
# - Content style
# - Output type
# 4. Make the output appropriate for the specified target audience.
# 5. Preserve important information from the source while removing
# irrelevant information when the requested detail level is concise.
# 6. If the source does not contain enough information to support a claim,
# do not fabricate the missing information.
# 7. Keep the generated content clear, coherent and professionally structured.
# 8. Respect the requested level of detail:
# - Concise: only the most important information
# - Moderate: important information with necessary context
# - Detailed: comprehensive coverage of relevant information
# 9. Follow the structure normally expected for the requested output type.
# 10. Return only the requested transformed content.
# Do not explain the transformation process.
# 11. Treat all provided transformation parameters as explicit user-selected
# requirements. When the output explicitly refers to any selected parameter,
# use the selected value or its direct wording. Do not replace it with a
# semantic equivalent, broader category, synonym, or inferred audience.
# Do not force the parameter value into places where it is not naturally needed.
# """
# def build_transformation_prompt(
# source_content,
# audience,
# objective,
# tone,
# language,
# detail_level,
# content_style,
# output_type,
# additional_instructions
# ):
# prompt = f"""
# Transform the following source content according to the specified
# transformation requirements.
# ================ SOURCE CONTENT ================
# {source_content}
# ================ REQUIREMENTS ================
# Target Audience:
# {audience}
# Communication Objective:
# {objective}
# Tone:
# {tone}
# Language:
# {language}
# Level of Detail:
# {detail_level}
# Content Style:
# {content_style}
# Output Type:
# {output_type}
# ================ ADDITIONAL INSTRUCTIONS ================
# {additional_instructions if additional_instructions.strip() else "No additional instructions provided."}
# ================ TASK ================
# Generate the requested {output_type} using the source content.
# The output must:
# - be suitable for the specified audience
# - fulfil the specified communication objective
# - follow the requested tone and style
# - respect the requested level of detail
# - preserve important factual information
# - avoid unsupported or fabricated information
# - follow an appropriate structure for the requested output type
# - follow the additional instructions when provided
# - treat additional instructions as output constraints or requirements
# Return only the final transformed content.
# """
# return prompt