This commit is contained in:
2026-04-12 01:06:31 +07:00
commit 10d660cbcb
1066 changed files with 228596 additions and 0 deletions

View File

@@ -0,0 +1,184 @@
# Advanced Prompt Engineering
## Prompt Optimization
### DSPy Framework
Automatic prompt optimization through:
1. Define task with input/output signatures
2. Compile with optimizer (BootstrapFewShot, MIPRO)
3. Model learns optimal prompting strategy
4. Export optimized prompts for production
### Meta-Prompting
```
You are a prompt engineer. Create 5 variations for [task]:
1. Direct instruction approach
2. Role-based approach
3. Few-shot example approach
4. Chain of thought approach
5. Constraint-focused approach
Evaluate each, select best.
```
### Self-Refinement Loop
```
Generate: [Initial response]
Critique: "What's wrong? Score 1-10."
Refine: "Fix issues, improve score."
Repeat until score ≥ 8.
```
## Prompt Chaining
### Sequential Chain
```
Chain 1: [Input] → Extract key points
Chain 2: Key points → Create outline
Chain 3: Outline → Write draft
Chain 4: Draft → Edit and polish
```
### Parallel Chain
Run independent subtasks simultaneously, merge results.
### Conditional Chain
```
If [condition A]: Execute prompt variant 1
If [condition B]: Execute prompt variant 2
Else: Execute default prompt
```
### Loop Pattern
```
While not [success condition]:
Generate attempt
Evaluate against criteria
If pass: break
Else: refine with feedback
```
## Evaluation Methods
### LLM-as-Judge
```
Rate this [output] on:
1. Accuracy (1-10)
2. Completeness (1-10)
3. Clarity (1-10)
4. Relevance (1-10)
Provide reasoning for each score.
Final: Pass/Fail threshold = 7 average.
```
### A/B Testing Protocol
1. Single variable per test
2. 20+ samples minimum
3. Score on defined criteria
4. Statistical significance check (p < 0.05)
5. Document winner, roll out
### Regression Testing
- Maintain test set of critical examples
- Run before deploying prompt changes
- Compare scores to baseline
- Block deployment if regression detected
## Agent Prompting
### Tool Use Design
```
You have access to these tools:
- search(query): Search the web
- calculate(expression): Math operations
- code(language, code): Execute code
To use: <tool_name>arguments</tool_name>
Wait for result before continuing.
```
### Planning Prompt
```
Task: [Complex goal]
Before acting:
1. Break into subtasks
2. Identify dependencies
3. Plan execution order
4. Note potential blockers
Then execute step by step.
```
### Reflection Pattern
```
After each step:
- What worked?
- What didn't?
- Adjust approach for next step.
```
## Parameter Tuning
| Parameter | Low | High | Use Case |
|-----------|-----|------|----------|
| Temperature | 0.0-0.3 | 0.7-1.0 | Factual vs Creative |
| Top-P | 0.8 | 0.95 | Focused vs Diverse |
| Top-K | 10 | 100 | Conservative vs Exploratory |
**Rule**: Tune temperature first. Only adjust top-p if needed. Never both at once.
## Safety Patterns
### Output Filtering
```
Before responding, check:
- No PII exposure
- No harmful content
- No policy violations
- Aligned with guidelines
If any fail: "I can't help with that."
```
### Jailbreak Prevention
- Clear system boundaries upfront
- Repeat constraints at end
- "Ignore previous" pattern detection
- Role-lock: "You are ONLY [role], never anything else"
### Confidence Calibration
```
For each claim, provide:
- Confidence: High/Medium/Low
- Source: [citation if available]
- Caveat: [limitations]
```
## Production Patterns
### Version Control
- Git for prompt files
- Semantic versioning (1.0.0, 1.1.0)
- Changelog per version
- Rollback capability
### Caching
- Cache common queries
- TTL based on content freshness
- Invalidate on prompt update
### Fallbacks
```
Try: Primary prompt
If fail: Simplified fallback prompt
If still fail: Human escalation
Log all failures for analysis.
```
### Cost Optimization
- Shorter prompts = fewer tokens
- Remove redundant examples
- Use smaller model for simple tasks
- Batch similar requests

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,66 @@
# Code Generation Patterns
## Function Implementation
```
Write a [language] function:
- Input: [params with types]
- Output: [return type]
- Behavior: [logic]
Requirements:
- Edge cases: [list]
- Error handling: [approach]
- Performance: O([complexity])
```
## Code Review
```
Review for:
1. Bugs/logic errors
2. Security vulnerabilities
3. Performance issues
4. Style violations
5. Missing edge cases
Format: Issue, line number, severity, fix.
```
## Refactoring
```
Refactor to:
- [Improvement goal]
- Maintain backward compatibility
- Keep public API
- Add comments for complex logic
Show before/after.
```
## Debugging
```
<error>[Error message/behavior]</error>
<code>[Relevant code]</code>
<context>[When it occurs]</context>
Analyze:
1. Root cause
2. Why it happens
3. Fix with explanation
4. Prevention strategy
```
## Test Generation
```
Generate tests for [function/class]:
- Framework: [jest/pytest/etc]
- Coverage: happy path, edge cases, errors
- Include: setup, assertion, cleanup
- Mock: [external dependencies]
```
## Documentation
```
Document this [function/class/API]:
- Format: [JSDoc/docstring/OpenAPI]
- Include: description, params, returns, examples
- Note: edge cases, errors, deprecations
```

View File

@@ -0,0 +1,72 @@
# Data & Analysis Patterns
## Structured Extraction
```
Extract from text:
<text>[content]</text>
Return JSON:
{
"field1": "value or null",
"field2": ["array"]
}
Rules:
- Exact matches only
- Confidence score if uncertain
- null for missing
```
## Document Analysis
```
Analyze [document type]:
1. Summary (2-3 sentences)
2. Key entities (people, orgs, dates)
3. Main topics (ranked)
4. Sentiment: positive/neutral/negative
5. Action items
```
## Comparison
```
Compare [A] and [B]:
| Criterion | A | B |
|-----------|---|---|
| [Factor 1] | | |
| [Factor 2] | | |
Recommendation: [choice] for [use case]
```
## Problem Solving
```
Problem: [description]
Analyze:
1. Root cause (5 whys)
2. Contributing factors
3. Options (pros/cons)
4. Recommendation
5. Implementation steps
6. Risk mitigation
```
## Data Transformation
```
Transform data:
- Input format: [CSV/JSON/etc]
- Output format: [target]
- Rules: [mapping logic]
- Validation: [constraints]
Handle: missing values, type mismatches.
```
## Summarization
```
Summarize [content]:
- Length: [sentences/words]
- Focus: [key themes]
- Audience: [technical/general]
- Preserve: [critical details]
```

View File

@@ -0,0 +1,66 @@
# Marketing Copy Patterns
## Headlines
```
Write 5 headline variations for [product].
Frameworks:
1. How to [benefit]
2. [Number] ways to [solve problem]
3. The secret to [outcome]
4. Why [audience] love [product]
5. [Timeframe] to [transformation]
```
## Product Descriptions
```
<product>[Name, features]</product>
<audience>[Demographics, pain points]</audience>
Write description that:
- Opens with benefit (not feature)
- Addresses [main objection]
- Social proof placeholder
- Clear CTA
- Tone: [brand voice]
- Length: [word count]
```
## Email Subject Lines
```
Generate 10 subject lines for [campaign].
Mix approaches:
- Curiosity gap
- Urgency/scarcity
- Personalization
- Question format
- Number/list
Under 50 chars. Test 2-3 with emojis.
```
## Ad Copy
```
Platform: [Google/Meta/LinkedIn]
Objective: [awareness/conversion]
Character limit: [limit]
Create [N] variations with:
- Hook (first 5 words critical)
- Value proposition
- Social proof element
- CTA matching platform norms
```
## Landing Pages
```
<offer>[Product/service]</offer>
<goal>[signup/purchase/download]</goal>
Write sections:
1. Hero headline + subhead
2. Problem agitation
3. Solution introduction
4. 3-5 benefit bullets
5. Social proof
6. CTA with urgency
7. FAQ (3 objections)
```

View File

@@ -0,0 +1,33 @@
# Domain-Specific Prompt Patterns
Quick reference index. Load specific domain file for detailed patterns.
## Domains
| Domain | File | Use Cases |
|--------|------|-----------|
| Marketing | `domain-marketing.md` | Headlines, product copy, emails, ads |
| Code | `domain-code.md` | Functions, review, refactoring, debugging |
| Writing | `domain-writing.md` | Stories, characters, dialogue, editing |
| Data | `domain-data.md` | Extraction, analysis, comparison, reasoning |
## Universal Pattern
All domain prompts follow:
```
<context>
[Domain-specific background]
</context>
<task>
[Specific action]
</task>
<constraints>
[Quality criteria, format, length, tone]
</constraints>
<output>
[Expected structure]
</output>
```

View File

@@ -0,0 +1,68 @@
# Creative Writing Patterns
## Story Outline
```
Create [length] story outline:
- Genre: [genre]
- Protagonist: [brief]
- Conflict: [type]
- Setting: [time/place]
Structure:
1. Hook/Opening
2. Inciting incident
3. Rising action (3 beats)
4. Climax
5. Resolution
```
## Character Voice
```
Write as [character]:
- Background: [history]
- Speech: [patterns, vocab]
- Emotion: [current state]
- Goal: [scene objective]
Maintain voice consistency.
```
## Dialogue
```
Write dialogue between [A] and [B]:
- Scene: [context]
- Tension: [conflict source]
- Subtext: [what's unsaid]
Each character distinct voice. Show don't tell.
```
## Scene Description
```
Describe [scene]:
- POV: [character/omniscient]
- Focus: [sensory details]
- Mood: [atmosphere]
- Pacing: [fast/slow/measured]
Use active verbs, concrete details.
```
## Editing Pass
```
Edit this [content type]:
Focus: [clarity/flow/voice/grammar]
Preserve: [author's style]
Flag: [major issues only]
Provide tracked changes with rationale.
```
## Genre Adaptation
```
Rewrite [content] as [genre]:
- Keep: core plot/message
- Add: genre conventions
- Tone: [genre-appropriate]
- Tropes: [use/subvert specific tropes]
```

View File

@@ -0,0 +1,141 @@
# Image Generation Prompting
## Universal Structure
```
[Subject + Details] [Action/Pose] [Setting/Environment]
[Style/Medium] [Artist/Movement Reference]
[Lighting] [Camera/Lens] [Composition]
[Quality Modifiers] [Aspect Ratio]
```
## Platform Reference
### Midjourney v6.1
```
[prompt] --ar 16:9 --style raw --v 6.1
```
| Parameter | Values | Effect |
|-----------|--------|--------|
| `--ar` | 1:1, 16:9, 9:16, 4:3, 3:2, 21:9 | Aspect ratio |
| `--style` | raw, default | raw=photorealistic |
| `--stylize` | 0-1000 | Artistic interpretation (0=literal) |
| `--chaos` | 0-100 | Variation between outputs |
| `--weird` | 0-3000 | Unusual/experimental elements |
| `--quality` | .25, .5, 1, 2 | Detail level (cost) |
| `--seed` | number | Reproducibility |
| `--no` | [term] | Negative prompt inline |
| `--tile` | - | Seamless patterns |
**Multi-prompt weighting**: `cat::2 dog::1` (cat 2x stronger)
**Describe**: Upload image → get prompt suggestions
**Blend**: `/blend` to merge 2-5 images
### DALL-E 3
- Natural language only, no parameters
- Be descriptive, not keyword-heavy
- Specify: "HD quality" or "vivid style" in prompt
- Text rendering: Describe font, placement, content explicitly
- Avoid: Lists of keywords, technical jargon
### Stable Diffusion / SDXL / Flux
```
(important term:1.3), normal term, (less important:0.8)
Negative prompt: ugly, blurry, deformed, watermark
```
| Feature | Syntax |
|---------|--------|
| Weight up | `(word:1.2)` to `(word:1.5)` |
| Weight down | `(word:0.5)` to `(word:0.8)` |
| LoRA | `<lora:model_name:0.8>` |
| Embedding | `embedding:name` |
| Blend | `[cat|dog]` alternating |
**CFG Scale**: 7-12 typical (higher=more prompt adherence)
**Samplers**: DPM++ 2M Karras (quality), Euler a (speed)
### Nano Banana (Gemini)
```
[Narrative description, not keywords]
Captured with 85mm lens, soft bokeh, natural lighting
```
**Key features**:
- 32K token context (complex prompts OK)
- Narrative paragraphs > keyword lists
- Hex colors for precision: `#9F2B68`
- Text rendering: Describe font, placement explicitly
- Multi-image: Up to 14 reference images
- Search grounding: Real-time data (weather, events)
- Thinking mode: Complex composition reasoning
**Aspect ratios**: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
**Resolution**: 1K, 2K, 4K (use uppercase K)
**Best practices**:
- ALL CAPS for critical requirements
- Markdown lists for multiple rules
- "NEVER include..." for negative constraints
- Photography terms anchor quality
### Imagen 4 / Veo 3.1
- Natural language, descriptive
- Aspect ratio in text: "16:9 landscape format"
- Veo: Cinematography keywords most powerful
- Camera movements: pan, tilt, dolly, crane, tracking
- Scene transitions: cut, fade, dissolve
## Style Keywords
### Art Movements
photorealistic, hyperrealistic, impressionist, expressionist,
surrealist, art nouveau, art deco, pop art, cyberpunk, steampunk,
solarpunk, vaporwave, synthwave, brutalist, minimalist
### Media Types
oil painting, watercolor, digital art, 3D render, vector art,
pencil sketch, ink drawing, pastel, charcoal, gouache, fresco
### Photography Styles
portrait, landscape, macro, street, documentary, fashion,
editorial, product, architectural, aerial, underwater
## Lighting Vocabulary
| Term | Effect |
|------|--------|
| Golden hour | Warm, soft, directional |
| Blue hour | Cool, moody, twilight |
| Rembrandt | Triangle on cheek, dramatic |
| Butterfly | Shadow under nose, glamorous |
| Split | Half face lit, mysterious |
| Rim/back | Edge highlight, separation |
| Volumetric | Light rays visible |
| Neon glow | Colorful, cyberpunk |
## Camera/Lens Terms
- 50mm (standard), 85mm (portrait), 35mm (wide)
- Telephoto (compressed), Macro (close-up), Fisheye (distorted)
- Shallow DOF, Deep DOF, Bokeh
- Low angle, High angle, Dutch angle, Bird's eye, Worm's eye
## Composition Keywords
rule of thirds, golden ratio, centered, symmetrical,
leading lines, framing, negative space, filling frame,
foreground interest, layered depth
## Negative Prompts (SD/Flux)
```
ugly, deformed, blurry, low quality, bad anatomy,
extra limbs, missing limbs, disfigured, watermark,
text, signature, cropped, out of frame, duplicate,
poorly drawn, bad proportions, gross proportions
```
## Iterative Workflow
1. Start: Subject + style + quality modifier
2. Add: Lighting + composition + camera
3. Test: Generate 4 variations
4. Refine: Adjust weights, add negatives
5. Upscale: Select winner, increase resolution

View File

@@ -0,0 +1,165 @@
# LLM Prompting Reference
## Prompt Architecture
### System Prompt Structure
```
You are [ROLE] with expertise in [DOMAIN].
## Context
[Background, constraints, tone]
## Instructions
[Step-by-step task breakdown]
## Output Format
[Exact structure with example]
## Constraints
- [Hard limits]
- [Guardrails]
```
### User Prompt Structure
```xml
<context>[Background information]</context>
<task>[Specific action required]</task>
<format>[Output structure]</format>
<constraints>[Additional limits]</constraints>
```
## Reasoning Techniques
### Chain of Thought (CoT)
| Variant | Trigger | Best For |
|---------|---------|----------|
| Zero-shot | "Think step by step" | Quick reasoning tasks |
| Few-shot | 2-3 reasoning examples | Complex multi-step |
| Auto-CoT | "Let's approach systematically" | General reasoning |
### Tree of Thoughts (ToT)
```
Explore 3 approaches to [problem]:
For each: 1) Method 2) Pros/cons 3) Success probability
Evaluate branches, select best path.
```
### Self-Consistency
Run same prompt 3-5x with temp=0.7, take majority answer. Best for: math, logic, factual.
### ReAct Pattern
```
Thought: [Current reasoning]
Action: [Tool/step to take]
Observation: [Result]
...repeat...
Final Answer: [Conclusion]
```
### Least-to-Most
```
Break [complex task] into subproblems.
Solve easiest first, build up.
```
## Instruction Optimization
### Self-Refine Pattern
```
1. Generate initial response
2. Critique: "What's wrong with this?"
3. Refine: "Fix identified issues"
4. Repeat until satisfactory
```
### Role Optimization
- **Expert persona**: "As a senior [role] with 20 years..."
- **Constraint persona**: "You only respond with..."
- **Teaching persona**: "Explain as if to a..."
### Task Decomposition
```
<subtasks>
1. [First step - output X]
2. [Second step - using X, output Y]
3. [Final step - using Y, output Z]
</subtasks>
```
## Output Control
### JSON Enforcement
```
Respond in valid JSON only:
{"field": "type", "required": true}
No markdown, no explanation, just JSON.
```
### Length Control
| Goal | Phrase |
|------|--------|
| Brief | "In 2-3 sentences" |
| Detailed | "Comprehensive analysis in 500 words" |
| Structured | "5 bullet points, max 20 words each" |
### Hallucination Reduction
- "Only use information from provided context"
- "If unsure, say 'I don't know'"
- "Cite sources for each claim"
- "Confidence: high/medium/low for each point"
## Model-Specific Tips
### Claude
- XML tags: `<thinking>`, `<answer>`, `<context>`
- Extended thinking: "Think deeply before responding"
- Prefill: Start assistant response to guide format
### GPT-4
- JSON mode: `response_format: {"type": "json_object"}`
- Function calling for structured output
- System message for persistent instructions
### Gemini
- Multimodal: Image + text in same prompt
- Grounding: Enable Google Search for facts
- Safety settings: Adjust thresholds
## Context Engineering
### RAG Prompt Pattern
```
<retrieved_context>
[Document chunks with sources]
</retrieved_context>
Answer based ONLY on context above.
If not in context, say "Not found in documents."
```
### Window Optimization
- Front-load critical info (primacy effect)
- Repeat key constraints at end (recency effect)
- Chunk long documents with summaries
## Few-Shot Examples
### Structure
```
Example 1:
Input: [representative input]
Output: [ideal output]
Example 2:
Input: [edge case]
Output: [handling]
Now apply to:
Input: [actual task]
```
### Selection Criteria
- Diverse examples > similar examples
- Include edge cases
- Match complexity of target task
- 2-5 examples optimal (diminishing returns beyond)

View File

@@ -0,0 +1,136 @@
# Nano Banana Pro (Gemini Image)
## Models
| Model ID | Type | Best For |
|----------|------|----------|
| `gemini-2.5-flash-image` | Flash | Speed, high-volume |
| `gemini-3-pro-image-preview` | Pro | Text rendering, complex prompts |
## Core Principle
**Narrative paragraphs > keyword lists** (32K context). Write like briefing a photographer.
## Parameters
```python
responseModalities=['TEXT', 'IMAGE']
aspect_ratio="16:9" # 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
image_size="2K" # 1K, 2K, 4K - MUST be uppercase K
```
## Prompt Templates
**Photorealistic**: `A [subject] in [location], [lens] lens. [Lighting] creates [mood]. [Details]. [Camera angle]. Professional photography, natural lighting.`
**Illustration**: `[Art style] illustration of [subject]. [Color palette]. [Line style]. [Background]. [Mood].`
**Text in Image**: `Image with text "[EXACT]" in [font]. Font: [style]. Color: [hex/#FF5733]. Position: [top/center/bottom]. Background: [desc]. Context: [poster/sign].`
**Product**: `[Product] on [surface]. Materials: [finish]. Lighting: [setup]. Camera: [angle]. Background: [type]. Style: [commercial/lifestyle].`
**Infographic**: `Premium liquid glass Bento grid infographic with 8 modules. Product: [item]. Language: [lang]. Hero card: 28-30%. Background: [ethereal/macro/pattern/context].`
## Prompt Collection / Prompt Search
Read `references/awesome-prompts.csv` directly or search for relevant prompts using `python3 ../scripts/search.py "<query>"`.
## JSON Structured Prompts
For complex scenes, use JSON structure:
```json
{
"meta_data": { "prompt_version": "2.0", "use_case": "..." },
"subject_layer": {
"anatomy": { "demographics": {}, "face_detail": {}, "hair": {} },
"attire_layer": { "garment_main": {}, "accessories": {} },
"pose_dynamics": { "posture": "", "limb_placement": {} }
},
"environment_layer": { "setting_type": "", "spatial_layout": {} },
"composition_and_tech": {
"framing": { "type": "", "angle": "" },
"lighting": { "source": "", "direction": "" },
"aesthetic_style": { "visual_core": "", "vibe": "" }
}
}
```
## Techniques
| Technique | Example |
|-----------|---------|
| Emphasis | `ALL CAPS` for critical requirements |
| Precision colors | `#9F2B68` instead of "dark magenta" |
| Negative constraints | `NEVER include text/watermarks. DO NOT add labels.` |
| Realism trigger | `Natural lighting, DOF. Captured with Canon EOS 90D DSLR.` |
| Structured edits | `Make ALL edits: - [1] - [2] - [3]` |
| Complex logic | `Kittens MUST have heterochromatic eyes matching fur colors` |
| Identity lock | `Use reference as EXACT facial reference. STRICT identity lock.` |
## Advanced Features
**Multi-Image Input** (up to 14): 6 object + 5 human refs. Tip: collage refs into single image.
**Search Grounding**: `tools=[{"google_search": {}}]` — real-time data (weather, charts, events).
**Thinking Mode** (Pro only): `part.thought` in response for complex reasoning.
## Popular Use Case Templates
### Quote Card
```
A wide quote card with {background} background, {font_style} font.
Quote: "{quote_text}" — {author}
Large subtle quotation mark before text. Portrait on left, text right.
Text: 2/3 width, portrait: 1/3 width. Gradient transition on portrait.
```
### Infographic (Bento Grid)
```
Premium liquid glass Bento grid product infographic with 8 modules.
Product: [name]. Language: [lang].
1) Hero card (28-30%): Product photo/3D glass
2) Core Benefits: 4 benefits + icons
3) How to Use: 4 methods + icons
4) Key Metrics: 5 data points
5) Who It's For: 4 recommended + 3 caution groups
6) Important Notes: 4 precautions
7) Quick Reference: Specs/certifications
8) Did You Know: 3 facts
Background: Apple liquid glass cards (85-90% transparent).
```
### Mirror Selfie
```
Scene: Mirror selfie in [room type], [color] tone.
Subject: [demographics], [body type], [hairstyle].
Pose: [stance], holding smartphone.
Clothing: [detailed outfit description].
Environment: [room details, furnishings, lighting].
Camera: Smartphone rear camera via mirror, [focal length]mm.
Negative: [artifacts to avoid].
```
### Style Transformation
```
A Japanese Edo-period Ukiyo-e woodblock print reimagining [modern scene].
Characters: Edo-era kimono but modern actions.
Tech transformation: Smartphones → glowing scrolls, trains → wooden carriages.
Composition: Flattened perspective, bold ink outlines.
Texture: Wood grain, paper fibers, pigment bleeding.
Colors: Prussian blue, vermilion red, muted ochre.
Include vertical Japanese calligraphy and red artist seal.
```
## Workflow
1. Narrative description → 2. Photography terms → 3. ALL CAPS emphasis → 4. Multi-turn refine → 5. Negative constraints → 6. Set ratio/resolution
## Avoid
- Keyword spam ("4k, trending, masterpiece")
- Vague text ("add some text" → specify exact text, font, position)
- Lowercase resolution ("4k" rejected, use "4K")
- Over-smoothed skin requests (leads to plastic look)
- Generic prompts without specific details

View File

@@ -0,0 +1,201 @@
# Reasoning Techniques Deep Dive
## Chain of Thought (CoT) Variants
### Zero-Shot CoT
```
[Task description]
Think step by step before answering.
```
**Use when**: Quick reasoning, no examples available
**Effectiveness**: +40-60% on reasoning tasks
### Few-Shot CoT
```
Example 1:
Q: [Question]
A: Let me think through this...
Step 1: [Reasoning]
Step 2: [Reasoning]
Therefore: [Answer]
Example 2:
Q: [Question]
A: Breaking this down...
First: [Reasoning]
Next: [Reasoning]
So: [Answer]
Now solve:
Q: [Your question]
```
**Use when**: Complex reasoning, pattern demonstration needed
**Effectiveness**: +50-80% on complex tasks
### Auto-CoT
```
Let me approach this systematically:
1. Identify the key elements
2. Analyze relationships
3. Apply relevant principles
4. Draw conclusions
5. Verify my reasoning
```
**Use when**: General problem-solving, exploratory reasoning
## Tree of Thoughts (ToT)
### Implementation Pattern
```
Problem: [Complex problem]
Generate 3 different approaches:
Approach A:
- Method: [Description]
- Reasoning: [Why this might work]
- Potential issues: [Risks]
- Confidence: [1-10]
Approach B:
- Method: [Description]
- Reasoning: [Why this might work]
- Potential issues: [Risks]
- Confidence: [1-10]
Approach C:
- Method: [Description]
- Reasoning: [Why this might work]
- Potential issues: [Risks]
- Confidence: [1-10]
Evaluate branches:
- Which has highest success probability?
- Which has fewest risks?
- Which is most feasible?
Selected approach: [Best option with justification]
Execution: [Step-by-step implementation]
```
**Use when**: Strategic decisions, multiple valid paths, high-stakes problems
## Self-Consistency
### Process
1. Generate 5 responses at temp=0.7
2. Extract final answers from each
3. Take majority vote
4. Report confidence = agreement %
### Implementation
```
Run this prompt 5 times (or use n=5 parameter):
[Your reasoning task]
Think step by step and provide final answer.
Aggregate: If 4/5 agree = high confidence
If 3/5 agree = medium confidence
If split = low confidence, needs review
```
**Use when**: Math, logic, factual questions with verifiable answers
## ReAct (Reasoning + Acting)
### Full Pattern
```
Task: [Goal to achieve]
Thought 1: I need to understand the current situation.
Action 1: [Observation or tool use]
Observation 1: [Result from action]
Thought 2: Based on this, I should [next logical step].
Action 2: [Next action]
Observation 2: [Result]
Thought 3: Now I can see that [insight].
Action 3: [Verification or next step]
Observation 3: [Result]
Thought 4: I have enough information to conclude.
Final Answer: [Conclusion with reasoning]
```
**Use when**: Tool-augmented reasoning, research tasks, multi-step analysis
## Least-to-Most Prompting
### Structure
```
Complex problem: [Full problem statement]
Step 1: Decomposition
Break this into simpler subproblems, ordered from easiest to hardest:
1. [Simplest subproblem]
2. [Next subproblem, may depend on 1]
3. [Harder subproblem, may depend on 1,2]
4. [Final subproblem requiring all above]
Step 2: Sequential Solution
Subproblem 1: [Solution]
Using result from 1, Subproblem 2: [Solution]
Using results from 1,2, Subproblem 3: [Solution]
Using all results, Subproblem 4: [Solution]
Final integrated answer: [Complete solution]
```
**Use when**: Mathematical word problems, multi-step procedures, compositional tasks
## Decomposed Prompting (DECOMP)
### Pattern
```
Task: [Complex task]
Required capabilities:
- [Capability 1]: Use [specialized prompt/tool]
- [Capability 2]: Use [specialized prompt/tool]
- [Capability 3]: Use [specialized prompt/tool]
Orchestration:
1. Call [Capability 1] with [input] → get [output1]
2. Call [Capability 2] with [output1] → get [output2]
3. Call [Capability 3] with [output2] → get [final output]
Integrate results: [Final response]
```
**Use when**: Tasks requiring diverse expertise, specialized sub-tasks
## Constitutional AI Reasoning
### Self-Critique Pattern
```
Initial response: [Generated content]
Critique against principles:
- Is it helpful? [Yes/No + reasoning]
- Is it harmless? [Yes/No + reasoning]
- Is it honest? [Yes/No + reasoning]
If any No:
Revised response that addresses [specific issues]:
[Improved content]
```
## Choosing the Right Technique
| Task Type | Best Technique |
|-----------|---------------|
| Simple reasoning | Zero-shot CoT |
| Complex multi-step | Few-shot CoT |
| Strategic decisions | Tree of Thoughts |
| Factual verification | Self-Consistency |
| Tool-using tasks | ReAct |
| Word problems | Least-to-Most |
| Specialized sub-tasks | DECOMP |
| Safety-critical | Constitutional AI |

View File

@@ -0,0 +1,117 @@
# AI Artist Validation Workflow
Agent instructions for mandatory validation interview before image generation.
## Step 1: Parse Arguments
Extract from user input:
- **concept**: The subject/description (required)
- **--mode**: search (default), creative, or wild
- **--skip**: If present, use defaults and skip to Step 4
**Defaults for --skip mode:** Style=Photorealistic, Mood=Professional, Colors=Auto, Aspect=16:9
## Step 2: Interview User
Use `AskUserQuestion` with these 4 questions in a single call:
```json
{"questions": [
{"question": "Visual style?", "header": "Style", "multiSelect": false, "options": [
{"label": "Photorealistic (Recommended)", "description": "Professional photography, 8K"},
{"label": "Cinematic", "description": "Film-like, dramatic lighting"},
{"label": "Illustration", "description": "Digital art, stylized"},
{"label": "Minimalist", "description": "Clean, white space"}
]},
{"question": "Mood?", "header": "Mood", "multiSelect": false, "options": [
{"label": "Professional", "description": "Corporate, trustworthy"},
{"label": "Energetic", "description": "Dynamic, bold"},
{"label": "Calm", "description": "Peaceful, serene"},
{"label": "Dramatic", "description": "High contrast, intense"}
]},
{"question": "Colors?", "header": "Colors", "multiSelect": false, "options": [
{"label": "Auto-select (Recommended)", "description": "AI chooses"},
{"label": "Warm tones", "description": "Oranges, reds"},
{"label": "Cool tones", "description": "Blues, greens"},
{"label": "High contrast", "description": "Blacks, neons"}
]},
{"question": "Aspect ratio?", "header": "Ratio", "multiSelect": false, "options": [
{"label": "16:9 (Recommended)", "description": "Widescreen"},
{"label": "1:1", "description": "Square"},
{"label": "9:16", "description": "Vertical"},
{"label": "4:3", "description": "Standard"}
]}
]}
```
**Dynamic questions** (ask separately if concept matches):
- "banner/poster/thumbnail" → Ask about text space
- "product/showcase" → Ask about background preference
## Step 3: Build Prompt
Map answers to keywords:
| Style | Keywords |
|-------|----------|
| Photorealistic | photorealistic, professional photography, 8K, RAW |
| Cinematic | cinematic, film still, anamorphic, dramatic lighting |
| Illustration | digital illustration, artistic, stylized |
| Minimalist | minimalist, clean design, white space |
| Mood | Keywords |
|------|----------|
| Professional | professional, clean, corporate, polished |
| Energetic | dynamic, bold, vibrant, high energy |
| Calm | serene, peaceful, soft, tranquil |
| Dramatic | dramatic, high contrast, intense, moody |
| Colors | Keywords |
|--------|----------|
| Auto-select | (none) |
| Warm tones | warm palette, golden tones, amber |
| Cool tones | cool palette, blue tones, teal |
| High contrast | high contrast, bold blacks, neon |
**Template:** `[concept], [style], [mood], [colors]. Professional quality. NEVER add watermarks.`
## Step 4: Confirm & Generate
Show preview, then ask confirmation:
```json
{"questions": [{"question": "Generate?", "header": "Confirm", "multiSelect": false, "options": [
{"label": "Yes, generate (Recommended)", "description": "Proceed"},
{"label": "Edit prompt", "description": "Modify first"},
{"label": "Start over", "description": "Re-answer"}
]}]}
```
**If "Edit prompt":** Ask user for edited text, use that instead.
**If "Start over":** Return to Step 2.
Run generation:
```bash
cd .opencode/skills/ai-artist && .venv/bin/python3 scripts/generate.py "[concept]" \
-o ./generated-$(date +%Y%m%d-%H%M%S).png \
--mode [mode] \
-ar [ratio] \
-v
```
## Error Handling
| Error | Action |
|-------|--------|
| API key missing | Tell user to set GEMINI_API_KEY |
| Model error | Suggest `--model flash` |
| No concept | Ask user for concept |
## Output
```
[OK] Image generated: [path]
Style: [style] | Mood: [mood] | Aspect: [ratio]
Tip: Use --skip to bypass interview next time.
```