ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

Fabric 使用指南:基于 Go 的开源 AI 提示词框架——安装、Patterns 与实战

Fabric 使用指南:基于 Go 的开源 AI 提示词框架——安装、Patterns 与实战 Fabric 使用指南基于 Go 的开源 AI 提示词框架——安装、Patterns 与实战【免费下载链接】FabricFabric is an open-source framework for augmenting humans using AI. It provides a modular system for solving specific problems using a crowdsourced set of AI prompts that can be used anywhere.项目地址: https://gitcode.com/GitHub_Trending/fa/FabricFabric 是一个用 Go 实现的开源框架目标是用 AI 增强人类能力它把提示词以可复用的Patterns模式形式组织起来让任何人都能把 AI 精确地接入日常生活与工作流。本文将以 Fabric 的官方 README 为核心结合本仓库源码完整讲解其设计理念、安装配置、CLI 用法、Patterns 机制、辅助工具与 Web 界面读完后你可以独立完成 Fabric 的安装、配置并把现成的 Patterns 直接用于视频摘要、论文解读、写作辅助等真实场景。Fabric 是什么以及它为什么存在自 2023 年初生成式 AI 爆发以来出现了海量 AI 应用与工具。它们功能强大但把这些功能真正整合进日常生活并不容易。Fabric 项目的核心判断是AI 的问题不在于能力而在于整合integration。Fabric 就是为了解决这个问题而创建的——它让每个人都能把 AI 以颗粒度极小的方式应用到日常挑战中。官方将其定位为an open-source framework for augmenting humans using AI一个用 AI 增强人类能力的开源框架。设计哲学把问题拆成组件用 Patterns 解决把问题分解成组件Fabric 的核心理法是把大的问题拆解成一个个独立的组成部分然后对每个部分分别应用 AI。例如从长内容里抽取洞见、把想法写成文章、给视频做摘要——每一件事都是一个独立的问题单元对应一个独立的 Prompt。提示词太多了怎么办Patterns2023 年作者面临的最大挑战是提示词数量爆炸每个人都有自己觉得好用的提示词但很难发现新提示词、判断质量优劣、以及管理自己喜欢的多个版本。Fabric 的主要特性之一就是帮助人们收集、整合这些提示词并把它们称为Patterns。Fabric 内置了覆盖各种生活与工作场景的 Patterns包括提取 YouTube 视频和播客中最有趣的部分仅凭一个想法就写出带有你自己风格的 essay总结晦涩的学术论文为一篇文章生成完美匹配的 AI 绘图提示词评估内容质量决定是否值得通读获取冗长枯燥内容的摘要为你解释代码把糟糕的文档改写成可用文档从任何内容输入生成社交媒体帖子以及更多……这些 Patterns 存放在仓库的 data/patterns 目录中每个 Pattern 是一个独立目录包含system.md系统提示词和可选的user.md用户提示词。安装 FabricFabric 有两种安装方式下载官方 release 二进制或从源码安装Go 环境。方式一下载最新 release 二进制# Windows: curl -L https://github.com/danielmiessler/fabric/releases/latest/download/fabric-windows-amd64.exe fabric.exe fabric.exe --version # MacOS (arm64): curl -L https://github.com/danielmiessler/fabric/releases/latest/download/fabric-darwin-arm64 fabric chmod x fabric ./fabric --version # MacOS (amd64): curl -L https://github.com/danielmiessler/fabric/releases/latest/download/fabric-darwin-amd64 fabric chmod x fabric ./fabric --version # Linux (amd64): curl -L https://github.com/danielmiessler/fabric/releases/latest/download/fabric-linux-amd64 fabric chmod x fabric ./fabric --version # Linux (arm64): curl -L https://github.com/danielmiessler/fabric/releases/latest/download/fabric-linux-arm64 fabric chmod x fabric ./fabric --version方式二从源码安装先确保已安装 Go然后执行go install github.com/danielmiessler/fabriclatest在本仓库中程序的真正入口在 cmd/fabric/main.gomain()直接调用internal/cli包的cli.Cli(version)而版本号定义在 cmd/fabric/version.go当前为v1.4.478。也就是说整个 CLI 的逻辑都集中在 internal/cli 目录下。设置环境变量为了让fabric命令可以直接运行可能需要在 Linux 的~/.bashrc或 Mac 的~/.zshrc中加入 Go 相关环境变量。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:$PATHApple 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初始化配置# 运行 setup 来创建目录并配置 API 密钥 fabric --setup这一步会引导你完成所有可配置项的初始化。从源码看--setup的处理位于 internal/cli/setup_server.go 的handleSetupAndServerCommands中设置标志存在时调用registry.Setup()完成目录、密钥与默认配置的创建。为所有 Patterns 添加别名可选如果你希望直接使用summarize这样的命令而不是每次都敲fabric --pattern summarize可以把下面这段加入.zshrc或.bashrc# 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) # Create an alias in the form: alias pattern_namefabric --pattern pattern_name alias_commandalias $pattern_namefabric --pattern $pattern_name # Evaluate the alias command to add it to the current shell eval $alias_command done yt() { local video_link$1 fabric -y $video_link --transcript }这段脚本同时创建了一个yt别名让你可以用yt https://www.youtube.com/watch?v4b0iet22VIk直接获取 YouTube 视频的字幕。用别名把输出保存为 Markdown 笔记如果你想把输出保存到 Obsidian 之类的 Markdown 笔记库中改用下面的版本# 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) # Unalias 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 yt() { local video_link$1 fabric -y $video_link --transcript }用法直接调用summarize等价于fabric --pattern summarize --stream如果传入额外参数例如summarize my_article_title输出会保存到你设定的obsidian_base目录文件名格式为YYYY-MM-DD-my_article_title.md日期自动生成。可以通过修改date_stamp来调整日期格式。从旧版 Python 迁移如果安装过旧版Python 版Fabric迁移只需两步卸载 Python 版再安装 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/fabriclatest # Run setup for the new version. Important because things have changed fabric --setup随后按上文设置环境变量即可。升级Go 让升级变得非常简单——直接重跑当初的安装命令即可获取最新版本go install github.com/danielmiessler/fabriclatest使用命令行参数全解析安装完成后用fabric -h查看完整帮助fabric -hUsage: 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 -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 chosen model (e.g., -V LM Studio -m openai/gpt-oss-20b) -o, --output Output to file --output-session Output the entire session (also a temporary one) to the output file -n, --latest Number of latest patterns to list (default: 0) -d, --changeDefaultModel Change default model -y, --youtube YouTube video URL to grab transcript, comments from it and send to chat --transcript Grab transcript from YouTube video and send to chat (it used per default). --comments Grab comments from YouTube video and send to chat -g, --language Specify the Language Code for the chat, e.g. -gen -gzh -u, --scrape_url Scrape website URL to markdown using Jina AI -q, --scrape_question Search question using Jina AI -e, --seed Seed to be used for LMM generation -w, --wipecontext Wipe context -W, --wipesession Wipe session --printcontext Print context --printsession Print session --readability Convert HTML input into a clean, readable view --serve Initiate the API server --dry-run Show what would be sent to the model without actually sending it --version Print current version Help Options: -h, --help Show this help message参数背后的源码实现以上所有参数都在 internal/cli/flags.go 的Flags结构体中定义通过go-flags的 struct tag 声明短参、长参与默认值你可以把它当作参数的权威来源。几个值得注意的实现细节输入通道Init()会检测 stdin 是否为管道os.Stdin.Stat()如果检测到管道输入就自动读取作为消息同时位置参数也会被拼接到消息中。这就是pbpaste | fabric --pattern summarize能工作的底层原因。YAML 配置文件Init()默认读取~/.config/fabric/patterns同级的~/.config/fabric/config.yaml见 internal/cli/flags.go 与 internal/cli/example.yaml。加载策略是命令行显式传入的参数优先未指定的参数才用 YAML 中的值覆盖。配置示例 internal/cli/example.yaml 展示了常用可配置项#this is an example yaml config file for fabric # use fabric pattern names pattern: ai # or use a filename # pattern: ~/testpattern.md model: phi3:latest # for models that support context length modelContextLength: 2048 frequencypenalty: 0.5 presencepenalty: 0.5 topp: 0.67 temperature: 0.88 seed: 42 stream: true raw: false # suppress vendor thinking output suppressThink: false thinkStartTag: think thinkEndTag: /think # OpenAI Responses API settings # (use this for llama-server or other OpenAI-compatible local servers) disableResponsesAPI: true上面示例里的model: phi3:latest说明 Fabric 同样支持本地模型如 OllamadisableResponsesAPI: true适用于 llama-server 等 OpenAI 兼容的本地服务器。从 internal/cli/cli.go 可以看到--disable-responses-api会通过configureOpenAIResponsesAPI切换 OpenAI 客户端的 Responses API 开关。命令分发流水线cli.Cli()internal/cli/cli.go按固定顺序处理参数——先--setup/--serveinternal/cli/setup_server.go再配置类命令--updatepatterns、--changeDefaultModel见 internal/cli/configuration.go然后是列表类命令--listpatterns、--listmodels、--listcontexts、--listsessions等见 internal/cli/listing.go再是管理类命令--wipecontext、--printsession等见 internal/cli/management.go最后才进入真正的对话处理。输出与剪贴板-o会把结果写入文件已存在的文件不会被覆盖见 internal/cli/output.go 的CreateOutputFile-c则调用系统剪贴板。进阶参数源码中比文档更丰富除了fabric -h展示的基础参数internal/cli/flags.go 中还定义了一批进阶能力包括--transcript-with-timestamps带时间戳的字幕、--visual用 OCR 和 FFmpeg 提取视频视觉信息--visual-sensitivity默认 0.4、--playlistYouTube 播放列表优先、--yt-dlp-args透传 yt-dlp 参数、--spotify抓取 Spotify 播客元数据、--image-fileAI 生图保存路径、--voiceTTS 音色默认 Kore、--thinking推理等级、--show-metadata打印 token 用量、--debug调试级别 0–4等。这些功能与仓库的 internal/tools 和 internal/plugins 模块一一对应。Fabric 的提示词方法论Patterns 为什么不一样Fabric 的 Patterns 与常见的提示词不同主要体现在三点使用 Markdown 书写保证最大可读性与可编辑性。这不仅帮助作者写出高质量提示词也让任何想深入理解它的人包括接收它的 AI 模型都能看懂结构与意图。指令极其清晰利用 Markdown 结构强调希望 AI 做什么、按什么顺序做。几乎只使用 System 部分经过一年多的高强度实践团队发现把指令放在 System 段效果最好。仓库中 data/patterns/extract_wisdom/system.md 是典型示例它以# IDENTITY and PURPOSE开头定义角色接着是# STEPS明确要求先输出 25 词的 SUMMARY再提取 20–50 条 IDEAS、10–20 条 INSIGHTS、15–30 条 QUOTES 等然后是# OUTPUT INSTRUCTIONS只输出 Markdown、每条要点恰好 16 个词、不得重复等硬性约束最后是# INPUT。这种结构把要什么、按什么顺序、输出格式如何全部显式化是理解 Fabric 提示词风格的最佳范本。实战示例以下示例使用 macOS 的pbpaste从剪贴板取内容。Windows/Linux 的替代方案见下文pbpaste 跨平台替代一节。基于 stdin 输入运行summarizePattern例如一篇文章的正文pbpaste | fabric --pattern summarize用--stream流式运行analyze_claimsPattern即时获取流式结果pbpaste | fabric --stream --pattern analyze_claims用--stream从任意 YouTube 视频提取智慧extract_wisdomfabric -y https://youtube.com/watch?vuXs-zPc63kM --stream --pattern extract_wisdom-y触发的是 internal/cli/cli.go 中processYoutubeVideo的完整流程默认抓取字幕GrabTranscriptWithArgs也可通过--comments抓评论、--metadata输出视频元数据。创建你自己的 Pattern创建一个.md文件保存到~/.config/fabric/patterns/[你的pattern名]即可。只使用 Patterns 也可以即使不折腾任何高级功能只想获得一大批高质量提示词你也可以直接浏览仓库的 data/patterns 目录——里面有从summarize、analyze_claims、extract_wisdom到create_slides、explain_code、write_essay等大量开箱即用的模式。这些 Patterns 可以用于你拥有的任何 AI 应用ChatGPT 或其他网页应用均可。这正是 Fabric 的社区化愿景众人拾柴火焰高The wisdom of crowds for the win——人们会分享比官方更多的 Patterns而且质量会更高。自定义 Patterns私有使用如果你只想创建自己的 Pattern 而不对外分享方法很简单在~/.config/custompatterns/或任意目录中创建目录放入你的.md文件需要使用时把它们复制到~/.config/fabric/patterns/之后就能像使用内置 Patterns 一样使用它们——它们默认是私有的除非你主动向 Fabric 项目提交 Pull Request否则不会公开。该功能支持所有 OpenAI 与 Ollama 模型但不支持 Claude可以通过-m参数指定模型。辅助工具to_pdfFabric 还附带一些核心辅助工具helper apps方便你把它接入自己的工作流。其中to_pdf是一个把 LaTeX 文件转换为 PDF 的命令行工具to_pdf input.tex这会在同一目录生成 PDF 文件。它还支持从 stdin 读取与write_latexPattern 配合使用效果极佳echo ai security primer | fabric --pattern write_latex | to_pdf这会在当前目录生成名为output.pdf的文件。安装to_pdf安装方式与 Fabric 相同只是仓库名不同go install github.com/danielmiessler/fabric/plugins/tools/to_pdflatest注意系统需要安装 LaTeX 发行版如 TeX Live 或 MiKTeX因为to_pdf依赖 PATH 中的pdflatex。本仓库中对应实现位于 cmd/to_pdf/main.go。pbpaste 跨平台替代上面的示例使用 macOS 的pbpaste把剪贴板内容管道给fabric。Windows 和 Linux 没有这个命令但有替代方案。Windows在 PowerShell 中使用Get-Clipboard。如果想保持习惯可以添加别名——经典 PowerShell 编辑~\Documents\WindowsPowerShell\.profile.ps1PowerShell Core 编辑~\Documents\PowerShell\.profile.ps1Set-Alias pbpaste Get-ClipboardLinux使用xclip -selection clipboard -o。Debian 系含 Ubuntu先安装sudo apt update sudo apt install xclip -y然后在~/.bashrc或~/.zshrc中加别名alias pbpastexclip -selection clipboard -oWeb 界面与 Streamlit UI内置 Web 界面Fabric 自带一个 Web 界面为 CLI 提供了 GUI 替代方案同时也是一个开箱即用的网站适合想开始做 Web 开发或写博客的人。你可以把它当作 Fabric 的图形界面、现成的博客站点或者自己项目的网站模板。仓库的web/src/lib/content目录包含 starter 的.obsidian/与templates/目录可以把web/src/lib/content/作为 Obsidian vault 打开准备好发布时把文章放进 posts 目录即可。安装进入web目录用npm install、pnpm install或你喜欢的包管理器安装依赖然后启动开发服务器。注意需要在另一个终端先运行fabric --serve启动后端 API。npm run dev ## or ## pnpm run dev ## or your equivalent--serve的处理同样在 internal/cli/setup_server.go调用restapi.Serve(registry, address, apiKey)启动 REST API 服务默认监听127.0.0.1:8080可通过--address和--api-key/FABRIC_API_KEY环境变量调整。服务端实现位于 internal/server支持--serveOllama模式提供 Ollama 兼容端点。Streamlit UI另一种选择是 Streamlit 界面。在仓库的scripts/python_ui目录包含 streamlit.py 与依赖清单 requirements.txt下运行# Install required dependencies pip install streamlit pandas matplotlib seaborn numpy python-dotenv # Run the Streamlit app streamlit run streamlit.pyStreamlit UI 提供友好的图形界面支持运行与串联 Patterns管理 Pattern 输出创建与编辑 Patterns分析 Pattern 结果结语Fabric 用一套简洁而扎实的设计——Markdown 化的 Patterns、stdin 驱动的管道式输入、丰富的 CLI 参数、以及 Web/Streamlit 双界面——把用 AI 增强人类从口号变成了可落地的工具箱。无论你是想批量处理视频与论文、把提示词沉淀成个人知识库还是基于它构建自己的 AI 应用本文覆盖的安装、配置、参数与 Patterns 用法都足以让你立即上手。更深层的实现细节如多供应商插件体系 internal/plugins/ai、数据库层 internal/plugins/db可以继续在仓库源码中探索。【免费下载链接】FabricFabric is an open-source framework for augmenting humans using AI. It provides a modular system for solving specific problems using a crowdsourced set of AI prompts that can be used anywhere.项目地址: https://gitcode.com/GitHub_Trending/fa/Fabric创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表