likhonsheikh commited on
Commit
1f3223c
·
verified ·
1 Parent(s): 289ad55

Add MDX-composable prompt templates

Browse files
Files changed (1) hide show
  1. mdx_templates.js +203 -0
mdx_templates.js ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // MDX-Composable Prompt Templates for Prothom Alo Model
2
+ // Production-ready templates with Bangla as default
3
+
4
+ import React from 'react';
5
+
6
+ // Base interface for prompt props
7
+ interface PromptProps {
8
+ language?: 'bn' | 'en';
9
+ style?: 'news' | 'opinion' | 'headline' | 'summary';
10
+ topic?: string;
11
+ context?: string;
12
+ }
13
+
14
+ // ===============================
15
+ // Core MDX Components (Production)
16
+ // ===============================
17
+
18
+ export const NewsTemplate: React.FC<PromptProps> = ({
19
+ language = 'bn',
20
+ style = 'news',
21
+ topic = 'সাম্প্রতিক ঘটনাবলী',
22
+ context = 'বাংলাদেশী প্রেক্ষাপট'
23
+ }) => {
24
+ const prompts = {
25
+ bn: {
26
+ news: `
27
+ <news-article>
28
+ <headline>${topic} সম্পর্কে নতুন প্রতিবেদন</headline>
29
+ <context>${context}</context>
30
+ <instructions>
31
+ আপনি একজন পেশাদার সাংবাদিক। নিচের নির্দেশনা অনুসরণ করে খবর লিখুন:
32
+ 1. স্পষ্ট এবং বাস্তবসম্মত ভাষা ব্যবহার করুন
33
+ 2. তথ্যগুলো বিশ্বস্ত উৎস থেকে নিশ্চিত করুন
34
+ 3. পাঠকদের জন্য উপযুক্ত টোন বজায় রাখুন
35
+ </instructions>
36
+ <format>
37
+ <lead>প্রথম প্যারাগ্রাফে মূল বার্তা দিন</lead>
38
+ <body>বিস্তারিত তথ্য এবং বিশ্লেষণ যোগ করুন</body>
39
+ <quote>সংশ্লিষ্ট ব্যক্তির উদ্ধৃতি অন্তর্ভুক্ত করুন</quote>
40
+ </format>
41
+ </news-article>`,
42
+ opinion: `
43
+ <opinion-piece>
44
+ <topic>${topic}</topic>
45
+ <position>মতামত ভিত্তিক বিশ্লেষণ প্রস্তুত করুন</position>
46
+ <context>${context}</context>
47
+ <instructions>
48
+ একটি বুদ্ধিদীপ্ত মতামত প্রবন্ধ লিখুন যা:
49
+ 1. ব্যক্তিগত দৃষ্টিভঙ্গি প্রকাশ করে
50
+ 2. যুক্তি ও প্রমাণ ভিত্তিক
51
+ 3. পাঠকদের চিন্তায় উদ্দীপনা জোগায়
52
+ </instructions>
53
+ </opinion-piece>`,
54
+ headline: `
55
+ <headline-generator>
56
+ <topic>${topic}</topic>
57
+ <context>${context}</context>
58
+ <instructions>
59
+ আকর্ষণীয় এবং তথ্যবহুল হেডলাইন তৈরি করুন:
60
+ 1. ১০-১৫ শব্দের মধ্যে রাখুন
61
+ 2. মূল খবরের ইঙ্গিত দিন
62
+ 3. পাঠকদের আগ্রহ বাড়ানোর উদ্দেশ্যে লিখুন
63
+ </instructions>
64
+ </headline-generator>`
65
+ },
66
+ en: {
67
+ news: `
68
+ <news-article>
69
+ <headline>New report on ${topic}</headline>
70
+ <context>${context}</context>
71
+ <instructions>
72
+ You are a professional journalist. Follow these guidelines to write news:
73
+ 1. Use clear and factual language
74
+ 2. Verify information from reliable sources
75
+ 3. Maintain appropriate tone for readers
76
+ </instructions>
77
+ <format>
78
+ <lead>Provide main message in first paragraph</lead>
79
+ <body>Add detailed information and analysis</body>
80
+ <quote>Include relevant person quotes</quote>
81
+ </format>
82
+ </news-article>`,
83
+ opinion: `
84
+ <opinion-piece>
85
+ <topic>${topic}</topic>
86
+ <position>Provide opinion-based analysis</position>
87
+ <context>${context}</context>
88
+ <instructions>
89
+ Write an insightful opinion piece that:
90
+ 1. Expresses personal perspective
91
+ 2. Is based on reasoning and evidence
92
+ 3. Stimulates reader thinking
93
+ </instructions>
94
+ </opinion-piece>`,
95
+ headline: `
96
+ <headline-generator>
97
+ <topic>${topic}</topic>
98
+ <context>${context}</context>
99
+ <instructions>
100
+ Create attractive and informative headlines:
101
+ 1. Keep within 10-15 words
102
+ 2. Indicate main news
103
+ 3. Aim to increase reader interest
104
+ </instructions>
105
+ </headline-generator>`
106
+ }
107
+ };
108
+
109
+ return <>{prompts[language][style]}</>;
110
+ };
111
+
112
+ // ===============================
113
+ // Composable News Components
114
+ // ===============================
115
+
116
+ export const NewsComponents: React.FC<{
117
+ components: Array<{
118
+ type: 'lead' | 'body' | 'quote' | 'conclusion';
119
+ content: string;
120
+ source?: string;
121
+ }>;
122
+ }> = ({ components }) => {
123
+ const renderedComponents = components.map((comp, index) => {
124
+ switch (comp.type) {
125
+ case 'lead':
126
+ return (
127
+ <lead key={index}>
128
+ {comp.content}
129
+ </lead>
130
+ );
131
+ case 'quote':
132
+ return (
133
+ <quote key={index} source={comp.source}>
134
+ "{comp.content}"
135
+ </quote>
136
+ );
137
+ case 'conclusion':
138
+ return (
139
+ <conclusion key={index}>
140
+ {comp.content}
141
+ </conclusion>
142
+ );
143
+ default:
144
+ return (
145
+ <body key={index}>
146
+ {comp.content}
147
+ </body>
148
+ );
149
+ }
150
+ });
151
+
152
+ return <>{renderedComponents}</>;
153
+ };
154
+
155
+ // ===============================
156
+ // Production-Ready Prompt Generator
157
+ // ===============================
158
+
159
+ export const generateNewsPrompt: React.FC<{
160
+ topic: string;
161
+ language?: 'bn' | 'en';
162
+ style?: 'news' | 'opinion' | 'headline';
163
+ includeSources?: boolean;
164
+ maxLength?: number;
165
+ }> = ({
166
+ topic,
167
+ language = 'bn',
168
+ style = 'news',
169
+ includeSources = true,
170
+ maxLength = 200
171
+ }) => {
172
+ const basePrompt = NewsTemplate({ language, style, topic });
173
+
174
+ if (includeSources) {
175
+ return (
176
+ <production-news>
177
+ {basePrompt}
178
+ <source-requirement>
179
+ সত্যায়িত তথ্য এবং উৎস উল্লেখ করুন
180
+ </source-requirement>
181
+ <length-control>
182
+ সর্বোচ্চ {maxLength} শব্দে সীমাবদ্ধ রাখুন
183
+ </length-control>
184
+ </production-news>
185
+ );
186
+ }
187
+
188
+ return <production-news>{basePrompt}</production-news>;
189
+ };
190
+
191
+ // ===============================
192
+ // Template Categories (Production)
193
+ export const NewsTemplates = {
194
+ breaking: NewsTemplate,
195
+ analysis: NewsTemplate,
196
+ sports: NewsTemplate,
197
+ economy: NewsTemplate,
198
+ politics: NewsTemplate,
199
+ opinion: NewsTemplate,
200
+ headline: NewsTemplate
201
+ } as const;
202
+
203
+ export default NewsTemplate;