关于 Fabric
Fabric 提供可重用的 AI 提示词模式,用于总结、提取和研究等常见文本任务。通过管道方式集成到命令行工作流中,支持快速应用预制的提示词。
主要功能
- 01应用预制的 AI 提示词模式到文本输入
- 02列表和搜索可用的内置模式
- 03通过管道将模式链接到其他命令
- 04处理文本总结、信息提取、研究和分析任务
适用场景
- 01快速总结长篇文章、文档或笔记
- 02从文本中提取关键信息和数据点
- 03在文本处理管道中标准化 AI 提示词应用
安装
选择你的系统或包管理器,复制命令到终端运行。
安装完成后运行fabric --version确认安装成功。
命令示例
常用命令按使用顺序排列。
详细介绍
更新 • 是什么以及为什么 • 理念 • 安装 • 用法 • REST API • 示例 • 直接使用模式 • 自定义模式 • 辅助应用 • 元信息
是什么以及为什么
自 2022 年底现代 AI 兴起以来,我们见证了**数量惊人的** AI 应用,它们可用于完成各种任务。如今有数以千计的网站、聊天机器人、移动应用和其他界面,可供人们使用各种 AI。
这一切都令人兴奋且功能强大,但_要将这些功能融入我们的生活并不容易。_
换句话说,AI 的问题不在于能力不足,而在于集成。
Fabric 旨在解决这一问题:创建并整理 AI 的基本单元——提示词!
Fabric 按照现实世界中的任务对提示词进行整理,让人们能够在一个地方创建、收集并整理最重要的 AI 解决方案,以便在自己喜欢的工具中使用。如果你主要使用命令行,也可以直接将 Fabric 用作界面!
更新
如需深入了解 Fabric 及其内部机制,请阅读 docs 文件夹中的文档。此外,Fabric 还有一份非常实用且定期更新的 DeepWiki。
点击查看近期更新
各位用户:
Fabric 最近推出了许多令人振奋的内容,我想在这里快速总结一下,让大家了解我们的开发进展!
以下是我们新增的功能与能力(从新到旧排列):
近期重大功能
- v1.4.447(2026 年 4 月 16 日)— Claude Opus 4.7:将 Anthropic SDK 更新至 v1.37.0,并将新版 Claude Opus 4.7 加入可用模型,包括支持 1M-token 上下文窗口。
- v1.4.437(2026 年 3 月 16 日)— OpenAI Codex PLugin:Fabric 现在支持使用 OpenAI Codex(通过你的 OpenAI 订阅)作为后端!
- v1.4.417(2026 年 2 月 21 日)— Azure AI Gateway 插件:新增 Azure AI Gateway 插件,可通过统一的 Azure APIM Gateway 和共享订阅密钥身份验证支持多个后端(AWS Bedrock、Azure OpenAI、Google Vertex AI)。
- v1.4.416(2026 年 2 月 21 日)— Azure Entra ID 身份验证:新增 Azure Entra ID 身份验证插件,提供共享 Azure 实用工具和 Entra ID/MSAL 支持,并将通用 Azure 逻辑提取到可复用的
azurecommon包中。 - v1.4.380(2026 年 1 月 15 日)— Microsoft 365 Copilot 集成:新增对企业版 Microsoft 365 Copilot 的支持,使企业用户能够利用基于其组织 Microsoft 365 数据(电子邮件、文档、会议)的 AI。
- v1.4.378(2026 年 1 月 14 日)— Digital Ocean GenAI 支持:新增对 Digital Ocean GenAI 的支持,并附带使用指南。
- v1.4.356(2025 年 12 月 22 日)— 完整国际化:为全部 10 种语言的设置提示提供完整的 i18n 支持,并智能处理环境变量,让 Fabric 真正服务全球用户,同时保持配置一致性。
- v1.4.350(2025 年 12 月 18 日)— 交互式 API 文档:在
/swagger/index.html添加 Swagger/OpenAPI UI,提供全面的 REST API 文档、增强的开发者指南,并改进端点的可发现性,让集成更轻松。 - v1.4.338(2025 年 12 月 4 日)— 为 Chat-LLM 模型添加 Abacus 供应商支持(参见 RouteLLM APIs)。
- v1.4.337(2025 年 12 月 4 日)— 添加「Z AI」供应商支持。更多详情请参阅 Z AI 概览页面。
- v1.4.334(2025 年 11 月 26 日)— Claude Opus 4.5:将 Anthropic SDK 更新至最新版本,并将新版 Claude Opus 4.5 加入可用模型。
- v1.4.331(2025 年 11 月 23 日)— 支持 GitHub Models:新增对使用 GitHub Models 的支持。
- v1.4.322(2025 年 11 月 5 日)— 交互式 HTML 概念图和 Claude Sonnet 4.5:新增
create_conceptmap模式,使用 Vis.js 进行可视化知识表示;新增 WELLNESS 类别及心理分析模式;并升级至 Claude Sonnet 4.5 - v1.4.317(2025 年 9 月 21 日)— 葡萄牙语变体:新增 BCP 47 区域设置规范化,支持巴西葡萄牙语(pt-BR)和欧洲葡萄牙语(pt-PT),并提供智能回退链
- v1.4.314(2025 年 9 月 17 日)— Azure OpenAI 迁移:迁移至官方
openai-go/azureSDK,改进身份验证并支持默认 API 版本 - v1.4.311(2025 年 9 月 13 日)— 更多国际化支持:新增 de(德语)、fa(波斯语)、fr(法语)、it(意大利语)、 ja(日语)、pt(葡萄牙语)、zh(中文)
- v1.4.309(2025 年 9 月 9 日)— 全面国际化支持:包含英语和西班牙语区域设置文件。
- v1.4.303(2025 年 8 月 29 日)— 新增二进制版本:支持 Linux ARM 和 Windows ARM 目标平台。你可以在 Raspberry PI 和 Windows Surface 上运行 Fabric!
- v1.4.294(2025 年 8 月 20 日)— Venice AI 支持:新增 Venice AI 提供商。Venice 是一家以隐私为先的开源 AI 提供商。详情请参阅其「关于 Venice」页面。
- v1.4.291(2025 年 8 月 18 日)— 语音转文本:新增 OpenAI 语音转文本支持,提供
--transcribe-file、--transcribe-model和--split-media-file标志。 这些功能体现了我们致力于让 Fabric 成为最强大、最灵活的 AI 增强框架!
入门视频
请注意,其中许多视频是在 Fabric 基于 Python 时录制的,因此请记得使用下方最新的安装说明。
导航
fabric
更新日志
Fabric 正在快速发展。
请查看更新日志,了解所有近期更改,掌握最新功能。
理念
AI 不是一种事物;它是某种事物的_放大镜_。而那种事物就是人类创造力。
我们相信技术的目的是帮助人类蓬勃发展,因此谈到 AI 时,我们会从想要解决的人类问题出发。
将问题拆分为组件
我们的方法是将问题拆分成各个独立部分(见下文),然后逐一应用 AI。以下是一些示例。
提示词很适合用来完成这些任务,但我在 2023 年面临的最大挑战——直到今天依然如此——是 AI 提示词数量实在太多。我们都有一些实用的提示词,但很难发现新的提示词、判断它们好不好,并管理我们喜欢的提示词的不同版本。
fabric 的主要功能之一,就是帮助人们收集提示词并将其集成到生活的各个方面,我们称之为 Patterns。
Fabric 为生活和工作中的各种活动提供 Patterns,包括:
- 提取 YouTube 视频和播客中最有趣的内容
- 只需输入一个想法,就能用你自己的风格写一篇文章
- 总结晦涩难懂的学术论文
- 为一篇文章生成完美匹配的 AI 艺术提示词
- 评估内容质量,帮助你决定是否要阅读或观看全文
- 总结冗长乏味的内容
- 为你解释代码
- 将糟糕的文档变成实用的文档
- 根据任意输入内容创建社交媒体帖子
- 还有无数其他用途……
安装
一行安装(推荐)
Unix/Linux/macOS:
curl -fsSL https://raw.githubusercontent.com/danielmiessler/fabric/main/scripts/installer/install.sh | bash
Windows PowerShell:
iwr -useb https://raw.githubusercontent.com/danielmiessler/fabric/main/scripts/installer/install.ps1 | iex
如需了解自定义安装选项和故障排除方法,请参阅 scripts/installer/README.md。
手动下载二进制文件
最新版本的二进制文件归档及其预期的 SHA256 哈希值,请访问 https://github.com/danielmiessler/fabric/releases/latest
使用包管理器
注意: 使用 Homebrew 或 Arch Linux 包管理器时,fabric 会以 fabric-ai 的名称提供,因此请在 shell 启动文件中添加以下别名:
alias fabric='fabric-ai'
macOS(Homebrew)
brew install fabric-ai
Arch Linux(AUR)
yay -S fabric-ai
Windows
使用 Microsoft 官方支持的 Winget 工具:
winget install danielmiessler.Fabric
Windows(Scoop)
scoop install fabric-ai
从源代码安装
要安装 Fabric,请确保已安装 Go,然后运行以下命令。
# Install Fabric directly from the repo
go install github.com/danielmiessler/fabric/cmd/fabric@latest
Docker
使用预构建的 Docker 镜像运行 Fabric:
# Use latest image from Docker Hub
docker run --rm -it kayvan/fabric:latest --version
# Use specific version from GHCR
docker run --rm -it ghcr.io/ksylvan/fabric:v1.4.305 --version
# Run setup (first time)
mkdir -p $HOME/.fabric-config
docker run --rm -it -v $HOME/.fabric-config:/home/appuser/.config/fabric kayvan/fabric:latest --setup
# Use Fabric with your patterns
docker run --rm -it -v $HOME/.fabric-config:/home/appuser/.config/fabric kayvan/fabric:latest -p summarize
# Run the REST API server (see REST API Server section)
docker run --rm -it -p 8080:8080 -v $HOME/.fabric-config:/home/appuser/.config/fabric kayvan/fabric:latest --serve
可用镜像:
- Docker Hub:kayvan/fabric
- GHCR:ksylvan/fabric
如需了解如何构建自定义镜像和高级配置,请参阅 scripts/docker/README.md。
环境变量
在 Linux 上,可能需要在 ~/.bashrc 中设置一些环境变量;在 Mac 上,则需要在 ~/.zshrc 文件中设置,才能运行 fabric 命令。以下是可添加的示例:
适用于基于 Intel 的 Mac 或 Linux
# Golang environment variables
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
# Update PATH to include GOPATH and GOROOT binaries
export PATH=$GOPATH/bin:$GOROOT/bin:$HOME/.local/bin:$PATH
适用于基于 Apple Silicon 的 Mac
# Golang environment variables
export GOROOT=$(brew --prefix go)/libexec
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$HOME/.local/bin:$PATH
设置
现在运行以下命令
# Run the setup to set up your directories and keys
fabric --setup
如果一切正常,就可以开始使用了。
支持的 AI 提供商
Fabric 支持多种 AI 提供商:
原生集成:
- OpenAI
- OpenAI Codex(通过私有后端使用 ChatGPT/Codex 订阅 OAuth)
- Anthropic(Claude)
- Claude Code(通过本地
claudeCLI 使用 Claude 订阅) - Google Gemini
- Ollama(本地模型)
- Azure OpenAI
- Amazon Bedrock
- Vertex AI
- LM Studio
- Perplexity
兼容 OpenAI 的提供商:
- Abacus
- AIML
- AIStupidLevel
- API Route
- Apple Foundation Models(本地,macOS 27 或更高版本:运行一次
sudo fm license,然后运行fm serve --port 1976;无需 API 密钥;在fabric -S中选择一次即可启用) - Cerebras
- Cheaper Inference
- DeepSeek
- DemonRoute
- DigitalOcean
- Eden AI
- GrokAI
- Groq
- Hostinger Router
- Langdock
- LiteLLM
- MiniMax
- Mistral
- Novita AI
- OpenCode Go
- OpenCode Zen
- OpenRouter
- Opper
- OrcaRouter
- OVHcloud
- Pzero
- Requesty
- SiliconCloud
- Synthorai
- Together
- Venice AI
- Y-API
- Z AI
运行 fabric --setup 配置你偏好的提供商,或使用 fabric --listvendors 查看所有可用提供商。
按模式映射模型
你可以使用环境变量为各个模式配置专用模型,
例如 FABRIC_MODEL_PATTERN_NAME=vendor|model
这样就能轻松地在 Shell 启动文件中维护这些按模式配置的模型映射。
为所有模式添加别名
若要为所有模式添加别名并将其直接用作命令,例如使用 summarize 代替 fabric --pattern summarize,
可以将以下内容添加到 .zshrc 或 .bashrc 文件中。你也可以选择先设置 FABRIC_ALIAS_PREFIX 环境变量,
这样所有 fabric 别名都会以相同前缀开头。
# Loop through all files in the ~/.config/fabric/patterns directory
for pattern_file in $HOME/.config/fabric/patterns/*; do
# Get the base name of the file (i.e., remove the directory path)
pattern_name="$(basename "$pattern_file")"
alias_name="${FABRIC_ALIAS_PREFIX:-}${pattern_name}"
# Create an alias in the form: alias pattern_name="fabric --pattern pattern_name"
alias_command="alias $alias_name='fabric --pattern $pattern_name'"
# Evaluate the alias command to add it to the current shell
eval "$alias_command"
done
yt() {
if [ "$#" -eq 0 ] || [ "$#" -gt 2 ]; then
echo "Usage: yt [-t | --timestamps] youtube-link"
echo "Use the '-t' flag to get the transcript with timestamps."
echo "Pipe to a pattern: yt URL | fabric -p extract_wisdom"
return 1
fi
transcript_flag="--transcript"
if [ "$1" = "-t" ] || [ "$1" = "--timestamps" ]; then
transcript_flag="--transcript-with-timestamps"
shift
fi
local video_link="$1"
# Outputs the raw transcript to stdout so it can be piped to a pattern:
# yt URL | fabric -p extract_wisdom
fabric -y "$video_link" $transcript_flag
}
若要在 PowerShell 中创建等效别名,可以在 PowerShell 窗口中运行 notepad $PROFILE,然后添加以下代码:
# Path to the patterns directory
$patternsPath = Join-Path $HOME ".config/fabric/patterns"
foreach ($patternDir in Get-ChildItem -Path $patternsPath -Directory) {
# Prepend FABRIC_ALIAS_PREFIX if set; otherwise use empty string
$prefix = $env:FABRIC_ALIAS_PREFIX ?? ''
$patternName = "$($patternDir.Name)"
$aliasName = "$prefix$patternName"
# Dynamically define a function for each pattern
$functionDefinition = @"
function $aliasName {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = `$true)]
[string] `$InputObject,
[Parameter(ValueFromRemainingArguments = `$true)]
[String[]] `$patternArgs
)
begin {
# Initialize an array to collect pipeline input
`$collector = @()
}
process {
# Collect pipeline input objects
if (`$InputObject) {
`$collector += `$InputObject
}
}
end {
# Join all pipeline input into a single string, separated by newlines
`$pipelineContent = `$collector -join "`n"
# If there's pipeline input, include it in the call to fabric
if (`$pipelineContent) {
`$pipelineContent | fabric --pattern $patternName `$patternArgs
} else {
# No pipeline input; just call fabric with the additional args
fabric --pattern $patternName `$patternArgs
}
}
}
"@
# Add the function to the current session
Invoke-Expression $functionDefinition
}
# Define the 'yt' function as well
function yt {
[CmdletBinding()]
param(
[Parameter()]
[Alias("timestamps")]
[switch]$t,
[Parameter(Position = 0, ValueFromPipeline = $true)]
[string]$videoLink
)
begin {
$transcriptFlag = "--transcript"
if ($t) {
$transcriptFlag = "--transcript-with-timestamps"
}
}
process {
if (-not $videoLink) {
Write-Error "Usage: yt [-t | --timestamps] youtube-link"
Write-Host "Pipe to a pattern: yt URL | fabric -p extract_wisdom"
return
}
}
end {
if ($videoLink) {
# Outputs the raw transcript to stdout so it can be piped to a pattern:
# yt URL | fabric -p extract_wisdom
fabric -y $videoLink $transcriptFlag
}
}
}
这还会创建一个 yt 辅助工具,将 YouTube 转录内容输出到标准输出。将其通过管道传递给某个模式,即可使用 fabric 处理:
yt https://www.youtube.com/watch?v=4b0iet22VIk | fabric -p extract_wisdom
不使用管道运行 yt,即可先查看原始转录内容。
使用别名将文件保存为 markdown
如果除了上述别名之外,你还想将输出保存到喜欢的 markdown 笔记库(例如 Obsidian),那么请将以下内容添加到 .zshrc 或 .bashrc 文件中,而不是添加上面的内容:
# Define the base directory for Obsidian notes
obsidian_base="/path/to/obsidian"
# Loop through all files in the ~/.config/fabric/patterns directory
for pattern_file in ~/.config/fabric/patterns/*; do
# Get the base name of the file (i.e., remove the directory path)
pattern_name=$(basename "$pattern_file")
# Remove any existing alias with the same name
unalias "$pattern_name" 2>/dev/null
# Define a function dynamically for each pattern
eval "
$pattern_name() {
local title=\$1
local date_stamp=\$(date +'%Y-%m-%d')
local output_path=\"\$obsidian_base/\${date_stamp}-\${title}.md\"
# Check if a title was provided
if [ -n \"\$title\" ]; then
# If a title is provided, use the output path
fabric --pattern \"$pattern_name\" -o \"\$output_path\"
else
# If no title is provided, use --stream
fabric --pattern \"$pattern_name\" --stream
fi
}
"
done
这样一来,你就可以像上面那样将模式用作别名,例如使用 summarize 代替 fabric --pattern summarize --stream。不过,如果你传入额外参数,例如 summarize "my_article_title",输出就会保存到你在 obsidian_base="/path/to/obsidian" 中设置的目标位置,文件名格式为 YYYY-MM-DD-my_article_title.md,日期会自动生成。
你可以调整 date_stamp 格式来更改日期格式。
迁移
如果你安装的是旧版(Python)版本,并想迁移到 Go 版本,操作方法如下。基本分为两步:1)卸载 Python 版本;2)安装 Go 版本。
# Uninstall Legacy Fabric
pipx uninstall fabric
# Clear any old Fabric aliases
(check your .bashrc, .zshrc, etc.)
# Install the Go version
go install github.com/danielmiessler/fabric/cmd/fabric@latest
# Run setup for the new version. Important because things have changed
fabric --setup
然后按照上文所示设置环境变量。
升级/替换
Go 的一大优点是升级或替换现有安装非常简单。只需运行最初用于安装的同一条命令,即可自动获取最新版本并替换旧版本。
go install github.com/danielmiessler/fabric/cmd/fabric@latest
如果要替换现有安装,只需运行上述命令,Go 就会自动用新版本替换旧版本。
重要提示:升级后运行 fabric --setup,如果版本之间存在配置更改,你可能需要重新配置某些设置或密钥。
Shell 补全
Fabric 为 Zsh、Bash 和 Fish Shell 提供补全脚本,通过为命令和选项提供 Tab 补全, 让 CLI 更易于使用。
快速安装(无需克隆)
你可以直接通过一行命令安装补全:
curl -fsSL https://raw.githubusercontent.com/danielmiessler/Fabric/refs/heads/main/completions/setup-completions.sh | sh
可选变体:
# Dry-run (see actions without changing your system)
curl -fsSL https://raw.githubusercontent.com/danielmiessler/Fabric/refs/heads/main/completions/setup-completions.sh | sh -s -- --dry-run
# Override the download source (advanced)
FABRIC_COMPLETIONS_BASE_URL="https://raw.githubusercontent.com/danielmiessler/Fabric/refs/heads/main/completions" \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/danielmiessler/Fabric/refs/heads/main/completions/setup-completions.sh)"
Zsh 补全
启用 Zsh 补全:
# Copy the completion file to a directory in your $fpath
mkdir -p ~/.zsh/completions
cp completions/_fabric ~/.zsh/completions/
# Add the directory to fpath in your .zshrc before compinit
echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc
echo 'autoload -Uz compinit && compinit' >> ~/.zshrc
Bash 补全
启用 Bash 补全:
# Source the completion script in your .bashrc
echo 'source /path/to/fabric/completions/fabric.bash' >> ~/.bashrc
# Or copy to the system-wide bash completion directory
sudo cp completions/fabric.bash /etc/bash_completion.d/
Fish 补全
启用 Fish 补全:
# Copy the completion file to the fish completions directory
mkdir -p ~/.config/fish/completions
cp completions/fabric.fish ~/.config/fish/completions/
用法
完成所有设置后,下面介绍如何使用。
fabric -h
Usage:
fabric [OPTIONS]
Application Options:
-p, --pattern= Choose a pattern from the available patterns
-v, --variable= Values for pattern variables, e.g. -v=#role:expert -v=#points:30
-C, --context= Choose a context from the available contexts
--session= Choose a session from the available sessions
-a, --attachment= Attachment path or URL (e.g. for OpenAI image recognition messages)
-S, --setup Run setup for all reconfigurable parts of fabric
-t, --temperature= Set temperature (default: 0.7)
-T, --topp= Set top P (default: 0.9)
-s, --stream Stream
-P, --presencepenalty= Set presence penalty (default: 0.0)
-r, --raw Use the defaults of the model without sending chat options (temperature,
top_p, etc.). Only affects OpenAI-compatible providers. Anthropic models
always use smart parameter selection to comply with model-specific
requirements.
-F, --frequencypenalty= Set frequency penalty (default: 0.0)
-l, --listpatterns List all patterns
--readpattern= Print the contents of the named pattern to the terminal
-L, --listmodels List all available models
-x, --listcontexts List all contexts
-X, --listsessions List all sessions
-U, --updatepatterns Update patterns
-c, --copy Copy to clipboard
-m, --model= Choose model
-V, --vendor= Specify vendor for the selected model (e.g., -V "LM Studio" -m
openai/gpt-oss-20b)
--modelContextLength= Model context length (only affects ollama)
-o, --output= Output to file
--output-session Output the entire session (also a temporary one) to the output file
--extract Output only the first fenced code block from the response (full response if
none is found)
--extract-last Output only the last fenced code block from the response (full response if
none is found)
-n, --latest= Number of latest patterns to list
-d, --changeDefaultModel Change default model
-y, --youtube= YouTube video or play list "URL" to grab transcript, comments from it and
send to chat or print it put to the console and store it in the output file
--playlist Prefer playlist over video if both ids are present in the URL
--transcript Grab transcript from YouTube video and send to chat (it is used per
default).
--transcript-with-timestamps Grab transcript from YouTube video with timestamps and send to chat
--visual Extract visual data from video using OCR and FFmpeg
--visual-sensitivity= Tolerance for FFmpeg scene detection (0.0 - 1.0) (default: 0.4)
--visual-fps= Extract a specific number of frames per second instead of using scene
detection
--comments Grab comments from YouTube video and send to chat
--metadata Output video metadata
--yt-dlp-args= Additional arguments to pass to yt-dlp (e.g. '--cookies-from-browser brave')
--spotify= Spotify podcast or episode URL to grab metadata from and send to chat
-g, --language= Specify the Language Code for the chat, e.g. -g=en -g=zh -g=pt-BR -g=pt-PT
-u, --scrape_url= Scrape website URL to markdown using Jina AI
-q, --scrape_question= Search question using Jina AI
--serply_search= Search Google using Serply and send the results to chat
--firecrawl_search= Search the web using Firecrawl and send the top pages to chat as Markdown
-e, --seed= Seed to be used for LMM generation
-w, --wipecontext= Wipe context
-W, --wipesession= Wipe session
--printcontext= Print context
--printsession= Print session
--print-prompt Print the rendered prompt without sending it to a model
--readability Convert HTML input into a clean, readable view
--input-has-vars Apply variables to user input
--no-variable-replacement Disable pattern variable replacement
--dry-run Show what would be sent to the model without actually sending it
--serve Serve the Fabric Rest API
--serveOllama Serve the Fabric Rest API with ollama endpoints
--address= The address to bind the REST API (default: :8080)
--api-key= API key used to secure server routes
--cors-origins= Browser origins that can call the server (repeatable; * for all)
--config= Path to YAML config file
--version Print current version
--listextensions List all registered extensions
--addextension= Register a new extension from config file path
--rmextension= Remove a registered extension by name
--strategy= Choose a strategy from the available strategies
--liststrategies List all strategies
--listvendors List all vendors
--shell-complete-list Output raw list without headers/formatting (for shell completion)
--search Enable web search tool for supported models (Anthropic, OpenAI, Gemini, Grok)
--search-location= Set location for web search results (e.g., 'America/Los_Angeles')
--image-file= Save generated image to specified file path (e.g., 'output.png')
--image-size= Image dimensions: 1024x1024, 1536x1024, 1024x1536, auto (default: auto)
--image-quality= Image quality: low, medium, high, auto (default: auto)
--image-compression= Compression level 0-100 for JPEG/WebP formats (default: not set)
--image-background= Background type: opaque, transparent (default: opaque, only for PNG/WebP)
--suppress-think Suppress text enclosed in thinking tags
--think-start-tag= Start tag for thinking sections (default: <think>)
--think-end-tag= End tag for thinking sections (default: </think>)
--disable-responses-api Disable OpenAI Responses API (default: false)
--transcribe-file= Audio or video file to transcribe
--transcribe-model= Model to use for transcription (separate from chat model)
--split-media-file Split audio/video files larger than 25MB using ffmpeg
--voice= TTS voice name for supported models (e.g., Kore, Charon, Puck) (default:
Kore)
--list-gemini-voices List all available Gemini TTS voices
--list-transcription-models List all available transcription models
--notification Send desktop notification when command completes
--notification-command= Custom command to run for notifications (overrides built-in notifications)
--thinking= Set reasoning/thinking level (e.g., off, low, medium, high, or numeric
tokens for Anthropic or Google Gemini)
--show-metadata Print metadata (input/output tokens) to stderr
--debug= Set debug level (0=off, 1=basic, 2=detailed, 3=trace, 4=wire)
Help Options:
-h, --help Show this help message
调试级别
使用 --debug 标志控制运行时日志记录:
0:关闭(默认)1:基本调试信息2:详细调试信息3:跟踪级别4:Wire 级别(完整的请求和响应正文)
空运行模式
使用 --dry-run 预览将发送给 AI 模型的内容,而不发起 API 调用:
echo "test input" | fabric --dry-run -p summarize
这有助于调试模式、检查提示词构建,并在使用 API 额度前验证输入格式。
提示词导出
使用 --print-prompt 可呈现 Fabric 组合后的提示词,并在调用任何模型前退出:
echo "test input" | fabric --print-prompt -p summarize
如果你想将 Fabric 的提示词库用于其他 CLI 大模型工具,或检查 Fabric 组合的系统消息和用户消息的确切结构,这会很有用。
有些模型需要原始模式,该模式会将系统消息合并到用户消息中。要显示此类模型的结构,请通过 -m(或 FABRIC_MODEL_<PATTERN>)指定模型。随后,Fabric 会查找供应商,这可能会发送模型列表请求。如果未指定模型,导出内容会分别显示系统消息和用户消息,除非你设置了 --raw。
扩展
Fabric 支持在模式中调用扩展。完整文档请参阅扩展指南。
重要: 扩展只能在模式文件中使用,不能通过直接输入 stdin 调用。详情和示例请参阅指南。
REST API 服务
Fabric 内置了 REST API 服务,可通过 HTTP 暴露所有核心功能。使用以下命令启动服务:
fabric --serve
该服务提供以下端点:
- 聊天补全,支持流式响应
- 模式管理(创建、读取、更新、删除)
- 上下文和会话管理
- 模型和供应商列表
- YouTube 字幕提取
- 配置管理
有关完整的端点文档、身份验证设置和使用示例,请参阅 REST API 文档。
Ollama 兼容模式
Fabric 可以通过提供兼容 Ollama 的 API 端点,作为 Ollama 的直接替代品。使用以下命令启动服务:
fabric --serve --serveOllama
此模式会启用以下兼容 Ollama 的端点:
GET /api/tags- 列出可用模式,作为模型显示POST /api/chat- 聊天补全GET /api/version- 服务版本
配置为使用 Ollama API 的应用可以改为指向你的 Fabric 服务,从而通过 Ollama 接口使用 Fabric 支持的任意 AI 提供商。模式会显示为模型(例如,summarize:latest)。
我们的提示词编写方法
Fabric 模式 与你常见的大多数提示词不同。
- 首先,我们使用
Markdown来确保内容尽可能易读、易编辑。这不仅能帮助创建者写出优质内容,也有助于任何想要深入了解其作用的人。重要的是,这也包括你将提示词发送给的 AI!
以下是一个 Fabric 模式示例。
https://github.com/danielmiessler/Fabric/blob/main/data/patterns/extract_wisdom/system.md
-
接下来,我们会让指令极其清晰,并使用 Markdown 结构强调我们希望 AI 执行什么操作,以及执行顺序。
-
最后,我们几乎只使用提示词中的系统部分。一年多来,我们一直专注于这项工作,而实践表明这样做效果更好。如果情况有所变化,或者有数据表明并非如此,我们会进行调整。
示例
以下示例使用 macOS 的
pbpaste从剪贴板粘贴内容。Windows 和 Linux 的替代方案请参阅下方的 pbpaste 部分。
现在来看看你可以用 Fabric 做些什么。
-
根据
stdin中的输入运行summarizePattern。本例中,输入是一篇文章的正文。pbpaste | fabric --pattern summarize -
使用
--stream选项运行analyze_claimsPattern,以即时获取流式结果。pbpaste | fabric --stream --pattern analyze_claims -
使用
--stream选项运行extract_wisdomPattern,即时获取任意 Youtube 视频的流式结果(与最初的介绍视频非常相似)。fabric -y "https://youtube.com/watch?v=uXs-zPc63kM" --stream --pattern extract_wisdom -
创建 Pattern:你必须创建一个包含该 Pattern 的 .md 文件,并将其保存到
~/.config/fabric/patterns/[yourpatternname]。 -
在网站上运行
analyze_claimsPattern。Fabric 使用 Jina AI 将 URL 抓取为 markdown 格式,然后再发送给模型。fabric -u https://github.com/danielmiessler/fabric/ -p analyze_claims
只使用 Patterns
如果你不打算做什么复杂的事情,只是想要许多优质提示词,可以前往 /patterns 目录开始探索!
我们希望,即使你不使用 Fabric 的其他功能,单独使用 Patterns 也能让这个项目派上用场。
你可以在任何 AI 应用中使用那里看到的任何 Pattern,无论是 ChatGPT,还是其他应用或网站。我们计划并预测,人们很快就会分享比我们发布的多得多的 Patterns,而且它们会比我们的好得多。
集思广益,效果更佳。
提示词策略
Fabric 还实现了诸如“思维链”(Chain of Thought)和“草稿链”(Chain of Draft)等提示词策略,可以与基本 Patterns 配合使用。
有关提示词策略示例,请参阅论文 Thinking Faster by Writing Less 和 Learn Prompting 的思维生成部分。
每种策略都是 /strategies 目录中的一个小型 json 文件。
策略对提示词的修改会应用于系统提示词,并在聊天会话中传递给 LLM。
使用 fabric -S,并选择在 ~/.config/fabric 目录中安装策略的选项。
可用策略
Fabric 包含多种提示词策略:
cot- 思维链:逐步推理cod- 草稿链:迭代起草,每步只写简短笔记(最多 5 个词)tot- 思维树:生成多条推理路径并选出最佳路径aot- 思维原子:将问题拆分为最小的独立原子子问题ltm- 由易到难:从最简单的子问题开始解决,逐步攻克更难的问题self-consistent- 自洽性:生成多条推理路径并达成共识self-refine- 自我改进:回答、批评并改进reflexion- 反思:回答、简要批评并提供改进后的答案standard- 标准:直接回答,不作解释
使用 --strategy 标志应用策略:
echo "Analyze this code" | fabric --strategy cot -p analyze_code
使用以下命令列出所有可用策略:
fabric --liststrategies
策略以 JSON 文件的形式存储在 ~/.config/fabric/strategies/ 中。格式规范请参阅默认策略。
自定义模式
你可能想使用 Fabric 创建自己的自定义模式,但不与他人分享。没问题!
Fabric 现在支持专用的自定义模式目录,可将你的个人模式与内置模式分开。这样,你的自定义模式就不会在更新 Fabric 内置模式时被覆盖。
设置自定义模式
-
运行 Fabric 设置:
fabric --setup -
从 Tools 菜单中选择“Custom Patterns”选项,并输入所需的目录路径(例如,
~/my-custom-patterns) -
如果目录不存在,Fabric 会自动创建。
使用自定义模式
-
创建自定义模式目录结构:
mkdir -p ~/my-custom-patterns/my-analyzer -
创建模式文件
echo "You are an expert analyzer of ..." > ~/my-custom-patterns/my-analyzer/system.md -
使用自定义模式:
fabric --pattern my-analyzer "analyze this text"
工作原理
- 优先级系统:同名时,自定义模式的优先级高于内置模式
- 无缝集成:自定义模式会与内置模式一起显示在
fabric --listpatterns中 - 更新安全:运行
fabric --updatepatterns不会影响你的自定义模式 - 默认私有:除非你明确分享,否则自定义模式会保持私有
你的自定义模式完全私有,不会受到 Fabric 更新的影响!
辅助应用
Fabric 还会使用一些核心辅助应用(工具),以便更轻松地集成到各种工作流中。以下是一些示例:
to_pdf
to_pdf 是一个辅助命令,可将 LaTeX 文件转换为 PDF 格式。用法如下:
to_pdf input.tex
这会在同一目录中,根据输入的 LaTeX 文件创建一个 PDF 文件。
你也可以通过 stdin 使用它,这与 write_latex 模式配合得非常好:
echo "ai security primer" | fabric --pattern write_latex | to_pdf
这会在当前目录中创建一个名为 output.pdf 的 PDF 文件。
to_pdf 安装
要安装 to_pdf,按照安装 Fabric 的方式安装即可,只需使用不同的仓库名称。
go install github.com/danielmiessler/fabric/cmd/to_pdf@latest
请确保系统已安装 LaTeX 发行版(如 TeX Live 或 MiKTeX),因为 to_pdf 需要系统 PATH 中包含 pdflatex。
code2context
code2context 与 create_coding_feature 模式配合使用。
它会生成目录中代码的 json 表示,可将其提供给 AI 模型,
并附上指令,以创建新功能或按指定方式编辑代码。
详情请参阅创建编码功能模式 README。
先使用以下命令安装:
go install github.com/danielmiessler/fabric/cmd/code2context@latest
generate_changelog
generate_changelog 根据 git 提交历史和 GitHub 拉取请求生成变更日志。它会遍历仓库的 git 历史记录,提取 PR 信息,并生成格式规范的 Markdown 变更日志。
generate_changelog --help
其功能包括用于快速增量更新的 SQLite 缓存、用于高效获取 PR 的 GitHub GraphQL API 集成,以及使用 Fabric 生成 AI 增强摘要的可选功能。
使用以下命令安装:
go install github.com/danielmiessler/fabric/cmd/generate_changelog@latest
详细用法和选项请参阅 generate_changelog README。
pbpaste
示例使用 macOS 程序 pbpaste 将剪贴板内容粘贴并通过管道传入 fabric 作为输入。Windows 和 Linux 上没有 pbpaste,但可以使用其他替代方案。
在 Windows 上,可以在 PowerShell 命令提示符中使用 PowerShell 命令 Get-Clipboard。你也可以根据需要为其设置别名 pbpaste。如果使用经典 PowerShell,请编辑文件 ~\Documents\WindowsPowerShell\.profile.ps1;如果使用 PowerShell Core,请编辑 ~\Documents\PowerShell\.profile.ps1,并添加以下别名:
Set-Alias pbpaste Get-Clipboard
在 Linux 上,可以使用 xclip -selection clipboard -o 从剪贴板粘贴内容。你可能需要通过包管理器安装 xclip。对于包括 Ubuntu 在内的 Debian 系统:
sudo apt update
sudo apt install xclip -y
你也可以编辑 ~/.bashrc 或 ~/.zshrc 并添加以下别名:
alias pbpaste='xclip -selection clipboard -o'
Web 界面(Fabric Web App)
Fabric 现在内置了一个 Web 界面,可作为命令行界面的 GUI 替代方案。请参阅 Web App README,了解安装说明和功能概览。
致谢
说明
特别感谢以下人员提供灵感并作出贡献!
- Jonathan Dunn 是本项目中绝对的 MVP 开发者,主导了新版 Go 版本以及 GUI 的开发!此外,他还是一名全职医生!
- Caleb Sima 让我最终决定是否将这个项目公开。
- Eugen Eisler 和 Frederick Ros 为 Go 版本作出了宝贵贡献。
- David Peters 负责开发 Web 界面。
- Joel Parish 为项目的 Github 目录结构提供了非常实用的建议。
- Joseph Thacker 提出了
-c上下文标志的想法,可将./config/fabric/目录中预先创建的上下文添加到所有 Pattern 查询中。 - Jason Haddix 提出了 stitch(链式 Pattern)的想法:先用本地模型过滤内容,再发送给云端模型,例如先用
llama2清理客户数据,再发送给gpt-4进行分析。 - Andre Guerra 协助开发了多个组件,让项目更简单、更易于维护。
核心贡献者
贡献者
由 contrib.rocks 制作。
fabric 由 Daniel Miessler 于 2024 年 1 月创建。
💜 支持此项目
我每年都会在开源项目上投入数百小时。如果你愿意支持这个项目,可以在此赞助我。🙏🏼
