Salta ai contenuti

Fabric

Installation

# Install via pip (Python 3.10+)
pip install fabric-ai

# Or install from source
git clone https://github.com/danielmiessler/fabric
cd fabric
pip install .

# First-time setup (configures API keys and default model)
fabric --setup

# Verify installation
fabric --version
fabric --list        # List all available patterns

# Update to latest
pip install --upgrade fabric-ai

Configuration

# Run interactive setup wizard
fabric --setup
# Prompts for: OpenAI key, Anthropic key, Google key, Ollama, default model

# Configuration file location
# Linux/Mac: ~/.config/fabric/.env
# Shows/edits current config:
cat ~/.config/fabric/.env

# Set individual env vars (override .env)
export OPENAI_API_KEY=sk-your-key
export ANTHROPIC_API_KEY=sk-ant-your-key
export DEFAULT_MODEL=claude-3-5-sonnet-20241022

# YouTube transcript support (for yt pattern)
# Requires yt-dlp installed:
pip install yt-dlp
# Or: brew install yt-dlp
# Key config options in ~/.config/fabric/.env
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=...
OLLAMA_API_KEY=ollama
DEFAULT_MODEL=gpt-4o
PATTERNS_LOADER_GIT_REPO_URL=https://github.com/danielmiessler/fabric
PATTERNS_LOADER_GIT_REPO_PATTERNS_FOLDER=patterns

Core Commands / API

CommandDescription
fabric --setupInteractive configuration wizard
fabric --listList all available patterns
fabric --pattern PATTERNRun a specific pattern
fabric -p PATTERNShorthand for --pattern
fabric --model MODELUse specific model for this run
fabric -m MODELShorthand for --model
fabric --listmodelsList all configured models
fabric --updateUpdate patterns from GitHub
fabric --copyCopy output to clipboard
fabric -cShorthand for --copy
fabric --output FILESave output to file
fabric -o FILEShorthand for --output
fabric --streamStream output as it generates
fabric -sShorthand for --stream
fabric --guiOpen web UI
fabric --temp 0.7Set temperature (0.0–1.0)
fabric --topp 0.9Set top-p sampling
fabric --ctx 4096Set context window
fabric --session NAMENamed conversation session
fabric --new-session NAMEStart new named session
fabric --wipe-session NAMEDelete a session

Advanced Usage

Core Pattern Usage

# Pipe any text to a pattern
echo "Your text here" | fabric -p summarize

# From clipboard (pbpaste = Mac, xclip = Linux)
pbpaste | fabric -p extract_wisdom

# From a file
cat article.txt | fabric -p summarize

# From a URL (via curl)
curl -s https://example.com/article | fabric -p summarize

# Combine patterns (chain them)
cat long_paper.txt | fabric -p extract_wisdom | fabric -p create_keynote

# Save output to file
cat notes.txt | fabric -p create_summary | fabric -o summary.md

Most Useful Patterns

# SUMMARIZE — Compress any content
cat article.txt | fabric -p summarize

# EXTRACT_WISDOM — Pull insights, quotes, facts, references
cat podcast_transcript.txt | fabric -p extract_wisdom

# WRITE_ESSAY — Transform ideas into structured prose
echo "Topic: The future of remote work" | fabric -p write_essay

# ANALYZE_PAPER — Academic paper analysis
cat paper.pdf | pdftotext - - | fabric -p analyze_paper

# EXPLAIN_CODE — Understand code
cat complex_script.py | fabric -p explain_code

# IMPROVE_WRITING — Rewrite for clarity and polish
cat my_draft.txt | fabric -p improve_writing

# CREATE_SUMMARY — Short structured summary
cat meeting_notes.txt | fabric -p create_summary

# FIND_LOGICAL_FALLACIES — Argument analysis
cat opinion_piece.txt | fabric -p find_logical_fallacies

# RATE_CONTENT — Score quality of content
cat blog_post.txt | fabric -p rate_content

# EXTRACT_IDEAS — Pull out key ideas and concepts
cat book_chapter.txt | fabric -p extract_ideas

# CREATE_QUIZ — Generate quiz questions
cat study_material.txt | fabric -p create_quiz

# ANALYZE_CLAIMS — Fact-check assertions
cat news_article.txt | fabric -p analyze_claims

# WRITE_MICRO_ESSAY — Short-form writing
echo "Topic: Why habits beat motivation" | fabric -p write_micro_essay

# SUGGEST_PATTERN — Meta: suggest which pattern to use
echo "I want to understand this research paper better" | fabric -p suggest_pattern

YouTube Transcript Processing

# Extract wisdom from a YouTube video
fabric -y "https://www.youtube.com/watch?v=VIDEO_ID" -p extract_wisdom

# Summarize a YouTube video
fabric -y "https://youtu.be/VIDEO_ID" -p summarize

# Get full transcript only (no pattern)
fabric -y "https://www.youtube.com/watch?v=VIDEO_ID" --transcript

# Chain: get transcript and analyze
fabric -y "https://youtu.be/VIDEO_ID" --transcript | fabric -p analyze_paper

# Shorthand -y works with most YouTube URL formats
fabric -y "youtu.be/VIDEO_ID" -p create_summary

Model Selection

# Use a specific OpenAI model
echo "Explain quantum computing" | fabric -p explain_docs -m gpt-4o

# Use Claude
echo "Explain quantum computing" | fabric -p explain_docs -m claude-3-5-sonnet-20241022

# Use a local Ollama model
echo "Summarize this" | fabric -p summarize -m ollama/llama3

# List all available models
fabric --listmodels

# Set default model permanently
fabric --changeDefaultModel gpt-4o

Creating Custom Patterns

# Patterns live in ~/.config/fabric/patterns/
mkdir -p ~/.config/fabric/patterns/my_pattern

# Create system.md — defines the pattern behavior
cat > ~/.config/fabric/patterns/my_pattern/system.md << 'EOF'
# IDENTITY AND PURPOSE

You are an expert code reviewer who provides actionable, specific feedback. You focus on:
- Security vulnerabilities
- Performance bottlenecks
- Code readability and maintainability
- Best practices for the language in use

# OUTPUT FORMAT

Provide your review in the following sections:

## Critical Issues
List any security or correctness bugs that must be fixed.

## Performance
Identify any performance concerns with suggested improvements.

## Style and Readability
Note readability issues with specific line references.

## Overall Assessment
A 1–2 sentence summary with a score out of 10.

# INSTRUCTIONS

Be specific. Reference line numbers when possible. Be constructive, not dismissive.
EOF

# Use your new pattern immediately
cat my_code.py | fabric -p my_pattern
# Create a pattern for your workflow
mkdir -p ~/.config/fabric/patterns/daily_standup
cat > ~/.config/fabric/patterns/daily_standup/system.md << 'EOF'
# IDENTITY AND PURPOSE
You convert raw notes from yesterday into a professional daily standup update.

# OUTPUT FORMAT
Format:
**Yesterday:** [what was accomplished]
**Today:** [what will be worked on]  
**Blockers:** [anything blocking progress, or "None"]

Keep each section to 1-2 sentences. Be concise and specific.
EOF

# Use it
echo "Fixed the login bug, merged PR #234, attended design review" | fabric -p daily_standup

Conversation Sessions

# Start a named session (maintains context across messages)
fabric --new-session research_project

# Continue in same session
echo "Tell me about transformer architecture" | fabric -p chat --session research_project
echo "How does attention work specifically?" | fabric -p chat --session research_project

# List sessions
fabric --list-sessions

# Wipe a session
fabric --wipe-session research_project

API Integration

# Fabric can serve as an API
fabric --serve                          # Start REST API server (default port 8080)
fabric --serve --port 9000              # Custom port

# API endpoints:
# POST /api/chat        — send message with optional pattern
# GET  /api/patterns    — list all patterns
# GET  /api/models      — list models

# Example API call
curl -X POST http://localhost:8080/api/chat \
  -H "Content-Type: application/json" \
  -d '{
    "prompts": [{"user": "Summarize this text: The quick brown fox..."}],
    "patterns_url": "summarize",
    "model": "gpt-4o"
  }'

Common Workflows

Research Pipeline

# Full research workflow
# 1. Get article transcript
curl -s https://arxiv.org/abs/2310.06825 | fabric -p analyze_paper

# 2. Extract key insights from multiple sources
for url in url1 url2 url3; do
  curl -s "$url" | fabric -p extract_wisdom >> insights.md
done

# 3. Synthesize findings
cat insights.md | fabric -p create_summary

Content Creation Pipeline

# Generate a blog post from rough notes
cat rough_notes.txt | fabric -p write_essay | fabric -p improve_writing > draft.md

# Create social media posts from article
cat article.md | fabric -p create_summary | fabric -p write_micro_essay

# Generate newsletter from week's bookmarks
cat bookmarks.txt | fabric -p extract_wisdom | fabric -o newsletter_draft.md

Meeting Intelligence

# Process meeting recording transcript
cat meeting_transcript.txt | fabric -p create_summary > meeting_summary.md

# Extract action items
cat meeting_transcript.txt | fabric -p extract_ideas

# Generate follow-up email
cat meeting_summary.md | fabric -p write_email

Code Review Workflow

# Review a PR diff
git diff main | fabric -p explain_code
git diff main | fabric -p review_design

# Document undocumented code
cat legacy_module.py | fabric -p create_coding_project > docs.md

# Explain error messages
echo "TypeError: 'NoneType' object is not subscriptable at line 45" | fabric -p explain_docs

Tips and Best Practices

Effective Piping

# Chain patterns for deeper processing
cat article.txt \
  | fabric -p extract_wisdom \
  | fabric -p create_summary \
  | fabric -p write_micro_essay

# Use tee to save intermediate outputs
cat article.txt \
  | fabric -p extract_wisdom \
  | tee wisdom.md \
  | fabric -p create_summary > summary.md

# Process multiple files
for f in *.txt; do
  cat "$f" | fabric -p summarize > "${f%.txt}_summary.md"
done

Pattern Selection Guide

GoalPattern
Understand any contentextract_wisdom
Quick summarysummarize or create_summary
Generate prosewrite_essay or write_micro_essay
Code helpexplain_code, review_design
Academic papersanalyze_paper
Improve writingimprove_writing
Debate analysisfind_logical_fallacies, analyze_claims
Learningcreate_quiz, explain_docs
YouTube videosUse -y flag + any pattern

Model Cost vs Quality

Use CaseRecommended Model
Quick summariesgpt-4o-mini (cheap, fast)
Deep analysisclaude-3-5-sonnet or gpt-4o
Private/offlineollama/llama3
Long documentsModels with large context windows
Creative writingclaude-3-5-sonnet
# Alias shortcuts for your most-used patterns
alias wisdom="fabric -p extract_wisdom"
alias sum="fabric -p summarize"
alias essay="fabric -p write_essay"
alias explain="fabric -p explain_code"

# Add to ~/.bashrc or ~/.zshrc
echo 'alias wisdom="fabric -p extract_wisdom"' >> ~/.zshrc
echo 'alias sum="fabric -p summarize"' >> ~/.zshrc