-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm-prompts.osf
More file actions
478 lines (334 loc) Β· 12 KB
/
llm-prompts.osf
File metadata and controls
478 lines (334 loc) Β· 12 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
// =============================================================================
// Example: LLM Prompts Documentation
// Category: Use Cases
// Description: Document AI/LLM prompts and responses for knowledge management
// Features: Code blocks, structured documentation, versioning
// Estimated time: Study example
// =============================================================================
@meta {
title: "AI Prompt Library";
author: "AI Team";
date: "2025-10-15";
version: "2.0";
theme: technical;
}
@doc {
# AI Prompt Library
## Best Practices and Templates
This document serves as a **centralized knowledge base** for our team's AI prompts, including best practices, examples, and version history.
---
## Why Document Prompts in OSF?
1. **Version Control**: Track prompt evolution with Git
2. **Collaboration**: Team members can review and improve prompts
3. **Knowledge Sharing**: Onboard new team members faster
4. **Multi-Format Export**: Share as PDF, DOCX, or presentations
5. **AI-Friendly**: LLMs can read and learn from this format
---
# Code Generation Prompts
## Python Function Generator
**Purpose**: Generate well-documented Python functions with type hints and tests
**Prompt Template**:
```
Create a Python function that [DESCRIPTION].
Requirements:
- Use type hints for all parameters and return value
- Add comprehensive docstring (Google style)
- Include error handling for edge cases
- Write 3-5 unit tests using pytest
- Follow PEP 8 style guidelines
Function signature: def [FUNCTION_NAME]([PARAMETERS]) -> [RETURN_TYPE]:
```
**Example Use**:
```
Create a Python function that validates email addresses.
Requirements:
- Use type hints for all parameters and return value
- Add comprehensive docstring (Google style)
- Include error handling for edge cases
- Write 3-5 unit tests using pytest
- Follow PEP 8 style guidelines
Function signature: def validate_email(email: str) -> bool:
```
**Response Quality**: βββββ (5/5)
**Tokens Used**: ~800
**Model**: GPT-4
---
## TypeScript React Component
**Purpose**: Generate modern React components with TypeScript
**Prompt Template**:
```
Create a React component in TypeScript for [DESCRIPTION].
Requirements:
- Use functional components with hooks
- Implement proper TypeScript interfaces for props
- Include JSDoc comments
- Use Tailwind CSS for styling
- Make component accessible (ARIA attributes)
- Add example usage in comments
Component name: [COMPONENT_NAME]
```
**Best Practices**:
- Always specify TypeScript for type safety
- Request accessibility features explicitly
- Mention styling framework (Tailwind, styled-components, etc.)
- Ask for example usage to understand component API
---
# Documentation Prompts
## API Documentation Generator
**Purpose**: Create comprehensive API documentation from code
**Prompt**:
```
Generate API documentation for the following endpoint:
[PASTE CODE HERE]
Include:
- Endpoint description and purpose
- HTTP method and path
- Request parameters (path, query, body)
- Response format with status codes
- Example requests and responses (cURL and JavaScript)
- Error handling and error codes
- Authentication requirements
- Rate limiting information
Format: OpenAPI 3.0 specification
```
**Output Quality Tips**:
1. Provide complete function/route code, not just signature
2. Include any middleware or decorators used
3. Specify desired output format (OpenAPI, Markdown, etc.)
4. Request examples in multiple languages
---
## README Generator
**Purpose**: Create professional README files for GitHub repositories
**Prompt Template**:
```
Create a comprehensive README.md for a [PROJECT_TYPE] project called [PROJECT_NAME].
Project description: [DESCRIPTION]
Include these sections:
- Header with logo/title and badges
- Project description and features
- Installation instructions
- Quick start guide
- Usage examples
- API reference (if applicable)
- Configuration options
- Contributing guidelines
- License information
Tone: Professional but friendly
Audience: Developers with [SKILL_LEVEL] experience
```
---
# Code Review Prompts
## Security Review
**Purpose**: Identify security vulnerabilities in code
**Prompt**:
```
Perform a security review of the following code:
[PASTE CODE HERE]
Check for:
- SQL injection vulnerabilities
- XSS (Cross-Site Scripting) risks
- CSRF (Cross-Site Request Forgery) issues
- Authentication/authorization flaws
- Insecure data storage
- API key or secret exposure
- Input validation problems
- Dependency vulnerabilities
For each issue found, provide:
1. Severity level (Critical/High/Medium/Low)
2. Description of the vulnerability
3. Potential impact
4. Recommended fix with code example
```
**Notes**:
- Always review AI suggestions with security team
- Don't blindly trust AI security assessments
- Use as first-pass review, not final audit
---
## Performance Optimization
**Purpose**: Get suggestions for code performance improvements
**Prompt**:
```
Analyze this code for performance optimization opportunities:
[PASTE CODE HERE]
Context:
- Language: [LANGUAGE]
- Expected load: [REQUESTS_PER_SECOND or DATA_SIZE]
- Current bottlenecks: [KNOWN_ISSUES]
Provide:
1. List of performance issues (ranked by impact)
2. Optimized code for each issue
3. Expected performance improvement (with benchmarks if possible)
4. Trade-offs (readability, maintainability, etc.)
Focus on: [algorithmic complexity, database queries, memory usage, caching]
```
---
# Data Analysis Prompts
## SQL Query Generator
**Purpose**: Generate SQL queries from natural language
**Prompt Template**:
```
Generate a SQL query for: [NATURAL_LANGUAGE_DESCRIPTION]
Database schema:
[TABLE_DEFINITIONS]
Requirements:
- Use PostgreSQL syntax
- Optimize for performance (include indexes used)
- Add comments explaining complex parts
- Include example output
- Suggest any indexes that would improve performance
```
**Example**:
```
Generate a SQL query for: Find top 10 customers by total purchase amount in the last 90 days
Database schema:
- customers (id, name, email, created_at)
- orders (id, customer_id, total, created_at, status)
- order_items (id, order_id, product_id, quantity, price)
Requirements:
- Use PostgreSQL syntax
- Optimize for performance (include indexes used)
- Add comments explaining complex parts
- Include example output
- Suggest any indexes that would improve performance
```
---
## Data Visualization Recommendation
**Purpose**: Get recommendations for data visualization approaches
**Prompt**:
```
I have the following dataset:
[DESCRIBE DATA STRUCTURE]
I want to visualize: [GOAL]
Recommend:
1. Best chart/graph type and why
2. JavaScript library to use (Chart.js, D3.js, Recharts, etc.)
3. Sample configuration/code
4. Best practices for this visualization type
5. Common pitfalls to avoid
Audience: [TECHNICAL or NON-TECHNICAL]
Platform: [WEB, MOBILE, PRINT]
```
---
# Debugging Prompts
## Error Explanation
**Purpose**: Understand and fix error messages
**Prompt**:
```
Explain this error and how to fix it:
Error message:
[PASTE ERROR MESSAGE]
Context:
- Language/Framework: [DETAILS]
- What I was trying to do: [DESCRIPTION]
- Code that caused the error: [PASTE CODE]
- Environment: [OS, versions, etc.]
Please provide:
1. Plain English explanation of what the error means
2. Root cause of the error
3. Step-by-step fix
4. Code example of the fixed version
5. How to prevent this error in the future
```
---
# Writing Prompts
## Technical Blog Post
**Purpose**: Create engaging technical blog posts
**Prompt Template**:
```
Write a technical blog post about [TOPIC].
Target audience: [BEGINNER, INTERMEDIATE, ADVANCED] developers
Structure:
- Catchy title and subtitle
- Introduction (hook the reader)
- Problem statement (why this matters)
- Solution explanation (with code examples)
- Step-by-step tutorial
- Best practices and tips
- Common pitfalls
- Conclusion with key takeaways
Tone: [FORMAL, CONVERSATIONAL, EDUCATIONAL]
Length: [TARGET_WORD_COUNT] words
Include:
- Code examples with syntax highlighting
- Diagrams (describe what diagrams to create)
- Real-world use cases
```
---
# Best Practices for Prompt Engineering
## 1. Be Specific
β **Bad**: "Write a function"
β
**Good**: "Write a TypeScript function that validates email addresses, includes error handling, and has 5 unit tests"
## 2. Provide Context
Always include:
- Programming language/framework
- Target audience or use case
- Constraints or requirements
- Expected output format
## 3. Use Examples
When possible, provide examples of desired output. This helps the AI understand your expectations.
## 4. Iterate and Refine
Don't expect perfection on the first try. Refine prompts based on results:
- If output is too generic β Add more specific requirements
- If output is incorrect β Provide more context
- If output is too complex β Ask for simplification
## 5. Chain Prompts
For complex tasks, break into steps:
1. Generate initial code
2. Add error handling
3. Add tests
4. Add documentation
5. Optimize performance
## 6. Version Control Your Prompts
- Track prompt versions in Git
- Note which prompts work best
- Share successful prompts with team
- Document prompt parameters and outcomes
---
# Prompt Templates by Task
## Quick Reference Table
| Task | Key Elements | Recommended Model |
|------|--------------|-------------------|
| Code Generation | Language, requirements, style guide | GPT-4, Claude 3.5 |
| Code Review | Code context, focus areas | GPT-4 |
| Documentation | Audience, format, examples | GPT-3.5, GPT-4 |
| Debugging | Error message, context, environment | GPT-4 |
| Data Analysis | Data structure, goal, constraints | GPT-4, Claude 3 |
| Writing | Audience, tone, structure | Claude 3.5, GPT-4 |
---
# Measuring Prompt Effectiveness
Track these metrics for your prompts:
1. **Success Rate**: % of times prompt produces usable output
2. **Iteration Count**: Average number of refinements needed
3. **Token Efficiency**: Tokens used vs. output quality
4. **Time Saved**: Hours saved vs. manual approach
5. **Quality Score**: Team rating of output quality (1-5)
---
# Conclusion
Effective prompt engineering is a **skill that improves with practice**. Document your successful prompts, learn from failures, and continuously refine your approach.
Remember:
- **AI is a tool**, not a replacement for human judgment
- **Always review** AI-generated code before using in production
- **Test thoroughly**, especially security-critical code
- **Share knowledge** with your team
## Resources
- OpenAI Prompt Engineering Guide: https://platform.openai.com/docs/guides/prompt-engineering
- Anthropic Claude Prompting Guide: https://docs.anthropic.com/claude/docs/prompt-engineering
- Prompt Engineering Community: https://learnprompting.org
}
@doc {
# Version History
## v2.0 - October 15, 2025
- Added data analysis and debugging sections
- Expanded best practices with examples
- Added quick reference table
- Included metrics for measuring effectiveness
## v1.5 - September 1, 2025
- Added code review prompts
- Included security review templates
- Added performance optimization section
## v1.0 - August 1, 2025
- Initial prompt library
- Code generation templates
- Documentation prompts
- Basic best practices
}