Initial commit: Portfolio Website
Vollständige Next.js 15 Portfolio-Website mit: - Blog-System mit 100+ Artikeln - Supabase-Integration - Responsive Design mit Tailwind CSS - TypeScript-Konfiguration - Testing-Setup mit Vitest und Playwright Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,293 @@
|
||||
# Prompt Engineering 2026: Jenseits von Zero-Shot und Few-Shot
|
||||
|
||||
**Meta-Description:** Fortgeschrittene Prompting-Techniken für komplexe Reasoning-Aufgaben. Chain-of-Thought, Tree-of-Thoughts, Self-Consistency und Context Engineering.
|
||||
|
||||
**Keywords:** Prompt Engineering, Chain of Thought, Tree of Thoughts, Self-Consistency, CoT Prompting, Advanced Prompting, LLM Prompting
|
||||
|
||||
---
|
||||
|
||||
## Einführung
|
||||
|
||||
Mit GPT-5, Claude Opus 4.5 und Gemini 3 hat sich Prompt Engineering 2026 zu einer **sophistizierten Disziplin** entwickelt. Die Basics (Zero-Shot, Few-Shot) reichen nicht mehr – fortgeschrittene Techniken können die Qualität um 50%+ verbessern.
|
||||
|
||||
---
|
||||
|
||||
## Die Prompting-Hierarchie
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ PROMPTING TECHNIQUES PYRAMID │
|
||||
├─────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌───────────┐ │
|
||||
│ │ ToT │ ← Strategische Planung │
|
||||
│ └───────────┘ │
|
||||
│ ┌─────────────────────┐ │
|
||||
│ │ Self-Consistency │ ← Mehrfach-Sampling │
|
||||
│ └─────────────────────┘ │
|
||||
│ ┌───────────────────────────────┐ │
|
||||
│ │ Chain-of-Thought (CoT) │ ← Step-by-Step │
|
||||
│ └───────────────────────────────┘ │
|
||||
│ ┌─────────────────────────────────────────┐ │
|
||||
│ │ Few-Shot Prompting │ │
|
||||
│ └─────────────────────────────────────────┘ │
|
||||
│ ┌─────────────────────────────────────────────────┐ │
|
||||
│ │ Zero-Shot Prompting │ │
|
||||
│ └─────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 1. Chain-of-Thought (CoT) Prompting
|
||||
|
||||
### Die wichtigste Technik für Reasoning
|
||||
|
||||
```typescript
|
||||
// ❌ Zero-Shot (schwächer)
|
||||
const zeroShotPrompt = `
|
||||
Was ist 847 * 293?
|
||||
`;
|
||||
|
||||
// ✅ Chain-of-Thought (stärker)
|
||||
const cotPrompt = `
|
||||
Was ist 847 * 293?
|
||||
|
||||
Denke Schritt für Schritt:
|
||||
`;
|
||||
```
|
||||
|
||||
### Few-Shot CoT
|
||||
|
||||
```typescript
|
||||
const fewShotCotPrompt = `
|
||||
Löse die Aufgabe Schritt für Schritt.
|
||||
|
||||
Beispiel:
|
||||
Frage: Wenn ein Zug um 9:15 abfährt und 2h 45min braucht,
|
||||
wann kommt er an?
|
||||
Denken: 9:15 + 2 Stunden = 11:15. 11:15 + 45 Minuten = 12:00.
|
||||
Antwort: 12:00
|
||||
|
||||
Frage: ${userQuestion}
|
||||
Denken:
|
||||
`;
|
||||
```
|
||||
|
||||
### Wann CoT verwenden?
|
||||
|
||||
| Use Case | CoT nötig? | Grund |
|
||||
|----------|------------|-------|
|
||||
| Mathematik | Ja | Multi-Step Berechnung |
|
||||
| Logik-Rätsel | Ja | Reasoning-Kette |
|
||||
| Code-Debugging | Ja | Systematische Analyse |
|
||||
| Faktenabruf | Nein | Direktes Wissen |
|
||||
| Klassifikation | Nein | Keine Reasoning-Kette |
|
||||
|
||||
---
|
||||
|
||||
## 2. Self-Consistency
|
||||
|
||||
### Mehrere Antworten, beste auswählen
|
||||
|
||||
```typescript
|
||||
async function selfConsistencyPrompt(
|
||||
question: string,
|
||||
n: number = 5
|
||||
): Promise<string> {
|
||||
// Generiere n verschiedene CoT-Antworten
|
||||
const responses = await Promise.all(
|
||||
Array(n).fill(null).map(() =>
|
||||
llm.generate({
|
||||
prompt: `${question}\n\nDenke Schritt für Schritt:`,
|
||||
temperature: 0.7 // Varianz für unterschiedliche Pfade
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// Extrahiere finale Antworten
|
||||
const answers = responses.map(r => extractFinalAnswer(r));
|
||||
|
||||
// Majority Vote
|
||||
const mostCommon = mode(answers);
|
||||
|
||||
return mostCommon;
|
||||
}
|
||||
```
|
||||
|
||||
### Wann Self-Consistency?
|
||||
|
||||
- Bei **komplexen Problemen** mit mehreren validen Lösungswegen
|
||||
- Wenn **hohe Konfidenz** wichtig ist
|
||||
- Bei **mathematischen** oder **logischen** Aufgaben
|
||||
|
||||
**Trade-off:** 5x mehr API-Calls, aber ~10-15% bessere Accuracy
|
||||
|
||||
---
|
||||
|
||||
## 3. Tree of Thoughts (ToT)
|
||||
|
||||
### Für strategische Planung
|
||||
|
||||
```typescript
|
||||
interface ThoughtNode {
|
||||
thought: string;
|
||||
score: number;
|
||||
children: ThoughtNode[];
|
||||
}
|
||||
|
||||
async function treeOfThoughts(problem: string): Promise<string> {
|
||||
// Initial: Generiere erste Gedanken
|
||||
const initialThoughts = await generateThoughts(problem, 3);
|
||||
|
||||
// Bewerte jeden Gedanken
|
||||
const scoredThoughts = await Promise.all(
|
||||
initialThoughts.map(async (thought) => ({
|
||||
thought,
|
||||
score: await evaluateThought(thought, problem)
|
||||
}))
|
||||
);
|
||||
|
||||
// Behalte die besten 2
|
||||
const topThoughts = scoredThoughts
|
||||
.sort((a, b) => b.score - a.score)
|
||||
.slice(0, 2);
|
||||
|
||||
// Expandiere rekursiv
|
||||
for (const node of topThoughts) {
|
||||
node.children = await expandThought(node.thought, problem);
|
||||
}
|
||||
|
||||
// Finde besten Pfad
|
||||
return findBestPath(topThoughts);
|
||||
}
|
||||
```
|
||||
|
||||
### ToT vs. CoT
|
||||
|
||||
| Aspekt | CoT | ToT |
|
||||
|--------|-----|-----|
|
||||
| Pfade | Linear, einzeln | Verzweigt, mehrfach |
|
||||
| Backtracking | Nein | Ja |
|
||||
| Use Case | Schritt-für-Schritt | Strategisch/Planung |
|
||||
| Kosten | 1x | 5-20x |
|
||||
|
||||
---
|
||||
|
||||
## 4. Context Engineering
|
||||
|
||||
### Strukturierter Kontext für bessere Ergebnisse
|
||||
|
||||
```typescript
|
||||
const structuredPrompt = `
|
||||
<context>
|
||||
Du bist ein Produktexperte für Elektronik mit 10+ Jahren Erfahrung.
|
||||
Dein Ziel: Präzise Marktanalysen für Reselling-Entscheidungen.
|
||||
</context>
|
||||
|
||||
<constraints>
|
||||
- Antworte nur auf Basis der gegebenen Informationen
|
||||
- Wenn unsicher, sage "Daten unzureichend"
|
||||
- Preise immer in EUR
|
||||
</constraints>
|
||||
|
||||
<format>
|
||||
Antworte in diesem JSON-Schema:
|
||||
{
|
||||
"marktwert": <number>,
|
||||
"empfehlung": "kaufen" | "verhandeln" | "skip",
|
||||
"begründung": "<string max 100 Zeichen>"
|
||||
}
|
||||
</format>
|
||||
|
||||
<input>
|
||||
${productDescription}
|
||||
</input>
|
||||
`;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Reverse Prompting
|
||||
|
||||
### Das Modell den Prompt verbessern lassen
|
||||
|
||||
```typescript
|
||||
const reversePrompt = `
|
||||
Ich möchte dass du ${task} ausführst.
|
||||
|
||||
Bevor du antwortest:
|
||||
1. Identifiziere fehlende Informationen die du brauchst
|
||||
2. Schlage einen verbesserten Prompt vor
|
||||
3. Führe dann die Aufgabe mit diesem verbesserten Prompt aus
|
||||
`;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Prompt Chaining
|
||||
|
||||
### Komplexe Aufgaben in Schritte zerlegen
|
||||
|
||||
```typescript
|
||||
async function analyzeProduct(description: string) {
|
||||
// Step 1: Fakten extrahieren
|
||||
const facts = await llm.generate({
|
||||
prompt: `Extrahiere Fakten aus: ${description}
|
||||
Format: JSON mit Feldern: marke, modell, speicher, zustand, preis`
|
||||
});
|
||||
|
||||
// Step 2: Marktdaten abrufen
|
||||
const marketData = await searchMarketPrices(facts);
|
||||
|
||||
// Step 3: Analyse generieren
|
||||
const analysis = await llm.generate({
|
||||
prompt: `
|
||||
Produkt-Fakten: ${JSON.stringify(facts)}
|
||||
Marktdaten: ${JSON.stringify(marketData)}
|
||||
|
||||
Erstelle eine Kaufempfehlung.
|
||||
`
|
||||
});
|
||||
|
||||
return analysis;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Prompting Cheat Sheet 2026
|
||||
|
||||
| Technik | Wann verwenden | Kosten-Multiplikator |
|
||||
|---------|----------------|---------------------|
|
||||
| **Zero-Shot** | Einfache Tasks | 1x |
|
||||
| **Few-Shot** | Spezifisches Format | 1.2x |
|
||||
| **CoT** | Reasoning-Aufgaben | 1.5x |
|
||||
| **Self-Consistency** | Hohe Konfidenz nötig | 5x |
|
||||
| **ToT** | Strategische Planung | 10-20x |
|
||||
|
||||
---
|
||||
|
||||
## Die Goldene Regel
|
||||
|
||||
> "Chain-of-thought reasoning ist die wirkungsvollste fortgeschrittene Technik. Sie ist universell anwendbar, einfach zu implementieren und produziert sofortige, merkliche Verbesserungen bei fast allen Aufgaben."
|
||||
|
||||
**Starten Sie hier:** Fügen Sie "Denke Schritt für Schritt" zu Ihren Prompts hinzu.
|
||||
|
||||
---
|
||||
|
||||
## Bildprompts
|
||||
|
||||
1. "Craftsman carefully sculpting text into AI brain, artistic interpretation of prompt engineering"
|
||||
2. "Layers of prompt refinement, funnel visualization showing increasing quality, infographic style"
|
||||
3. "Wizard with code staff casting prompt spells, fantasy meets tech, dramatic magical effects"
|
||||
|
||||
---
|
||||
|
||||
## Quellen
|
||||
|
||||
- [Prompting Guide: Chain-of-Thought](https://www.promptingguide.ai/techniques/cot)
|
||||
- [Prompting Guide: Tree of Thoughts](https://www.promptingguide.ai/techniques/tot)
|
||||
- [K2View: Prompt Engineering Techniques 2026](https://www.k2view.com/blog/prompt-engineering-techniques/)
|
||||
- [Analytics Vidhya: Prompt Engineering Guide 2026](https://www.analyticsvidhya.com/blog/2026/01/master-prompt-engineering/)
|
||||
Reference in New Issue
Block a user