Repository navigation
Expand file tree
/
Copy pathPromptLibrary.php
More file actions
389 lines (358 loc) · 10.2 KB
/
Copy pathPromptLibrary.php
File metadata and controls
389 lines (358 loc) · 10.2 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
<?php
declare(strict_types=1);
namespace ClaudeAgents\Prompts;
/**
* Library of commonly used prompt templates.
*
* Provides pre-built templates for common tasks like classification,
* summarization, extraction, analysis, and more.
*/
class PromptLibrary
{
/**
* Summarization prompt.
*/
public static function summarization(): PromptTemplate
{
return PromptTemplate::create(
"Summarize the following text in {length} or less:\n\n{text}\n\n" .
'Summary:'
);
}
/**
* Classification prompt.
*
* @param array<string> $categories List of valid categories
*/
public static function classification(array $categories): PromptTemplate
{
$categoryList = implode(', ', $categories);
return PromptTemplate::create(
"Classify the following text into one of these categories: {$categoryList}\n\n" .
"Text: {text}\n\n" .
'Category:'
);
}
/**
* Sentiment analysis prompt.
*/
public static function sentimentAnalysis(): PromptTemplate
{
return PromptTemplate::create(
'Analyze the sentiment of the following text. ' .
"Respond with: positive, negative, or neutral.\n\n" .
"Text: {text}\n\n" .
'Sentiment:'
);
}
/**
* Entity extraction prompt.
*/
public static function entityExtraction(): PromptTemplate
{
return PromptTemplate::create(
'Extract all named entities (people, places, organizations, dates) ' .
"from the following text:\n\n{text}\n\n" .
'Entities:'
);
}
/**
* Question answering prompt.
*/
public static function questionAnswering(): PromptTemplate
{
return PromptTemplate::create(
"Answer the question based on the provided context.\n\n" .
"Context: {context}\n\n" .
"Question: {question}\n\n" .
'Answer:'
);
}
/**
* Translation prompt.
*/
public static function translation(): PromptTemplate
{
return PromptTemplate::create(
"Translate the following text from {source_language} to {target_language}:\n\n" .
"{text}\n\n" .
'Translation:'
);
}
/**
* Code explanation prompt.
*/
public static function codeExplanation(): PromptTemplate
{
return PromptTemplate::create(
"Explain what the following {language} code does:\n\n" .
"```{language}\n{code}\n```\n\n" .
'Explanation:'
);
}
/**
* Code review prompt.
*/
public static function codeReview(): PromptTemplate
{
return PromptTemplate::create(
"Review the following {language} code for:\n" .
"- Bugs and errors\n" .
"- Performance issues\n" .
"- Security vulnerabilities\n" .
"- Best practices\n\n" .
"```{language}\n{code}\n```\n\n" .
'Review:'
);
}
/**
* Text rewriting prompt.
*/
public static function rewrite(): PromptTemplate
{
return PromptTemplate::create(
"Rewrite the following text to be {style}:\n\n" .
"{text}\n\n" .
'Rewritten text:'
);
}
/**
* Brainstorming prompt.
*/
public static function brainstorm(): PromptTemplate
{
return PromptTemplate::create(
"Generate {count} creative ideas for {topic}.\n\n" .
'Ideas:'
);
}
/**
* Comparison prompt.
*/
public static function comparison(): PromptTemplate
{
return PromptTemplate::create(
"Compare {item1} and {item2} in terms of:\n" .
"- Pros and cons\n" .
"- Key differences\n" .
"- Use cases\n\n" .
'Comparison:'
);
}
/**
* Pros and cons analysis.
*/
public static function prosAndCons(): PromptTemplate
{
return PromptTemplate::create(
"List the pros and cons of {topic}:\n\n" .
"Pros:\n\n" .
'Cons:'
);
}
/**
* Step-by-step explanation.
*/
public static function stepByStep(): PromptTemplate
{
return PromptTemplate::create(
"Explain how to {task} in a step-by-step manner:\n\n" .
'Steps:'
);
}
/**
* JSON output format instruction.
*/
public static function jsonOutput(): PromptTemplate
{
return PromptTemplate::create(
"{instruction}\n\n" .
"Input: {input}\n\n" .
"Provide your response as valid JSON with the following structure:\n" .
"{schema}\n\n" .
'JSON Response:'
);
}
/**
* Chain of thought reasoning.
*/
public static function chainOfThought(): PromptTemplate
{
return PromptTemplate::create(
"{problem}\n\n" .
"Let's solve this step by step:\n" .
"1. First, let's understand what we're being asked\n" .
"2. Then, let's break down the problem\n" .
"3. Finally, let's work through the solution\n\n" .
'Solution:'
);
}
/**
* Error diagnosis prompt.
*/
public static function errorDiagnosis(): PromptTemplate
{
return PromptTemplate::create(
"Diagnose the following error:\n\n" .
"Error: {error}\n\n" .
"Context: {context}\n\n" .
"Provide:\n" .
"1. Root cause\n" .
"2. Solution\n" .
"3. Prevention tips\n\n" .
'Diagnosis:'
);
}
/**
* Data formatting prompt.
*/
public static function dataFormatting(): PromptTemplate
{
return PromptTemplate::create(
"Convert the following data from {source_format} to {target_format}:\n\n" .
"{data}\n\n" .
'Converted data:'
);
}
/**
* Meeting notes summary.
*/
public static function meetingNotesSummary(): PromptTemplate
{
return PromptTemplate::create(
"Summarize the following meeting notes into:\n" .
"- Key decisions\n" .
"- Action items\n" .
"- Next steps\n\n" .
"Notes: {notes}\n\n" .
'Summary:'
);
}
/**
* Email response generator.
*/
public static function emailResponse(): PromptTemplate
{
return PromptTemplate::create(
"Generate a professional email response with a {tone} tone:\n\n" .
"Original email: {original_email}\n\n" .
"Key points to address: {key_points}\n\n" .
'Response:'
);
}
/**
* Fact checking prompt.
*/
public static function factCheck(): PromptTemplate
{
return PromptTemplate::create(
"Fact-check the following statement:\n\n" .
"{statement}\n\n" .
"Provide:\n" .
"1. Verdict (True/False/Partially True/Unverifiable)\n" .
"2. Explanation\n" .
"3. Sources (if available)\n\n" .
'Analysis:'
);
}
/**
* Create a custom template from a chat conversation style.
*/
public static function conversational(): ChatTemplate
{
return ChatTemplate::create()
->system('You are a helpful, friendly assistant. Engage in natural conversation.')
->user('{user_message}');
}
/**
* Expert advisor template.
*/
public static function expertAdvisor(): ChatTemplate
{
return ChatTemplate::create()
->system('You are an expert {expertise}. Provide detailed, professional advice.')
->user('{question}');
}
/**
* Socratic teaching template.
*/
public static function socraticTeaching(): ChatTemplate
{
return ChatTemplate::create()
->system(
'You are a Socratic teacher. Instead of giving direct answers, ' .
'ask thought-provoking questions to guide the student to discover the answer.'
)
->user('{question}');
}
/**
* Debate opponent template.
*/
public static function debateOpponent(): ChatTemplate
{
return ChatTemplate::create()
->system(
'You are a skilled debater. Argue the position that: {position}. ' .
'Use logic, evidence, and persuasive techniques.'
)
->user('{argument}');
}
/**
* Creative writing assistant.
*/
public static function creativeWriting(): PromptTemplate
{
return PromptTemplate::create(
"Write a creative {genre} story with the following elements:\n" .
"- Setting: {setting}\n" .
"- Characters: {characters}\n" .
"- Conflict: {conflict}\n\n" .
'Story:'
);
}
/**
* SQL query generator.
*/
public static function sqlGenerator(): PromptTemplate
{
return PromptTemplate::create(
"Generate a SQL query to {task}.\n\n" .
"Database schema:\n{schema}\n\n" .
"Requirements:\n{requirements}\n\n" .
'SQL Query:'
);
}
/**
* API documentation generator.
*/
public static function apiDocumentation(): PromptTemplate
{
return PromptTemplate::create(
"Generate API documentation for the following {language} code:\n\n" .
"```{language}\n{code}\n```\n\n" .
"Include:\n" .
"- Description\n" .
"- Parameters\n" .
"- Return value\n" .
"- Example usage\n\n" .
'Documentation:'
);
}
/**
* User story generator.
*/
public static function userStory(): PromptTemplate
{
return PromptTemplate::create(
"Generate a user story for: {feature}\n\n" .
"Format:\n" .
"As a [user type]\n" .
"I want to [action]\n" .
"So that [benefit]\n\n" .
"Acceptance Criteria:\n" .
"- [criterion 1]\n" .
"- [criterion 2]\n\n" .
'User Story:'
);
}
}