文章目录
一、关于 fabric
fabric是一个使用人工智能增强人类的开源框架。它提供了一个模块化框架,使用一组可以在任何地方使用的众包人工智能提示来解决特定问题。
注:2024年5月23日——我们将在几周内将Fabric 切换到 Go,以避免Python的所有安装问题。
Go版本安装起来非常简单,甚至更快。而且更容易更新。
由于@xssdr的英勇努力,我们已经让它工作了,我们现在只是在测试!敬请关注有关发布日期的更多信息!
Network Chuck 的介绍视频
这是查克网络的一段精彩视频,讲述了他为什么开始在人工智能的所有东西上使用fabric 。他谈到了这个项目的精神,如何安装它,以及他如何使用它,他只是很好地阐明了我们在这里所做的事情的精神。感谢Chuck!
什么以及为什么
自2023年初和GenAI以来,我们已经看到了大量用于完成任务的AI应用程序。
它很强大,但将此功能集成到我们的生活中并不容易。
换句话说,人工智能没有能力问题 —— 它有接入问题。
Fabric的创建旨在通过使每个人都能够将AI精细地应用于日常挑战来解决这个问题。
哲学
AI isn’t a thing; it’s a magnifier of a thing. And that thing is human creativity.
人工智能不是一个东西;它是一个事物的放大镜。那就是人类的创造力。
我们相信技术的目的是帮助人类蓬勃发展,所以当我们谈论人工智能时,我们从我们想要解决的人类问题开始。
将问题分解为组件
我们的方法是将问题分解为各个部分(见下文),然后一次将AI应用于它们。有关一些示例,请参阅下文。
prompts 太多
提示对这一点有好处,但我在2023年面临的最大挑战——今天仍然存在——是大量的人工智能提示。我们都有有用的提示,但很难发现新的,知道它们是否好,也很难管理我们喜欢的不同版本的提示。
fabric
其中一个的主要特点是帮助人们收集和整合提示,我们称之为模式(Patterns),到他们生活的各个部分。
fabric 具有各种生活和工作活动的Patterns,包括:
- 提取YouTube视频和播客中最有趣的部分。
- 用你自己的声音写一篇文章,只把一个想法作为输入。
- 总结不透明的学术论文。
- 为一篇文章创建完美匹配的AI艺术提示。
- 对内容质量进行评级,看看你是否想阅读/观看整个内容。
- 获取冗长无聊内容的摘要。
- 向您解释代码。
- 把坏的留档变成可用的留档。
- 从任何内容输入创建社交媒体帖子。
- 还有一百万…
我们对提示的方法
Fabric Patterns 与您将看到的大多数提示不同。
- 首先,我们使用
Markdown
来帮助确保最大的易读性和可编辑性。这不仅有助于创作者制作一个好的,也有助于任何想深入了解它的作用的人。重要的是,这也包括你发送它的人工智能!
这是一个fabric Pattern 的例子
https://github.com/danielmiessler/fabric/blob/main/patterns/extract_wisdom/system.md
- 接下来,我们的说明非常清楚,我们使用Markdown结构来强调我们希望人工智能做什么,以及以什么顺序。
- 最后,我们倾向于几乎完全使用提示的系统部分。在一年多的时间里,我们看到了这样做的更多功效。如果情况发生变化,或者我们看到的数据表明情况并非如此,我们将进行调整。
二、快速入门
使用Fabric最具特征的方法是使用fabric
客户端,该客户端可以在此存储库 /client
目录下找到。
Python 版本
确保您的操作系统上至少安装了 python3.10。否则,当您尝试运行pip install命令时,由于某些依赖关系,项目将无法构建。
设置结构命令
按照以下步骤安装和配置所有与结构相关的应用程序。
- 导航到您希望Fabric项目在您的系统上的计算机上的半永久位置。
# Find a home for Fabric
cd /where/you/keep/code
- 将项目克隆到您的计算机。
# Clone Fabric to your computer
git clone https://github.com/danielmiessler/fabric.git
- 进入Fabric的主目录。
# Enter the project folder (where you cloned it)
cd fabric
- 安装Pipx:
苹果操作系统:
brew install pipx
Linux:
sudo apt install pipx
Windows:
使用WSL并遵循Linux说明。
- 安装 fabric:
pipx install .
- 运行设置:
fabric --setup
- 重新启动shell以重新加载所有内容。
- 现在您已经启动并运行了!您可以通过运行帮助进行测试。
# Making sure the paths are set up correctly
fabric --help
注:如果您使用的是server
函数,fabric-api
和 fabric-webui
需要在不同的终端窗口中运行。
三、更新
要更新Fabric,请运行以下命令。
# From the fabric directory
pipx install . --force
fabric --update
然后重新启动您的shell。
使用 fabric
客户端
如果您想将它与OpenAI API兼容的推理服务器一起使用,例如FastChat、Helmholtz Blablador、LM Studio等,只需导出以下环境变量:
export OPENAI_BASE_URL=https://YOUR-SERVER:8000/v1/
export DEFAULT_MODEL="YOUR_MODEL"
如果您的服务器需要鉴权 tokens,像Blablador一样,您可以像使用OpenAI一样导出 token:
export OPENAI_API_KEY="YOUR TOKEN"
一旦你把它都设置好,下面是如何使用它:
- 查看选项
fabric -h
usage: fabric -h
usage: fabric [-h] [--text TEXT] [--copy] [--agents] [--output [OUTPUT]] [--session [SESSION]] [--gui] [--stream] [--list] [--temp TEMP] [--top_p TOP_P] [--frequency_penalty FREQUENCY_PENALTY]
[--presence_penalty PRESENCE_PENALTY] [--update] [--pattern PATTERN] [--setup] [--changeDefaultModel CHANGEDEFAULTMODEL] [--model MODEL] [--listmodels]
[--remoteOllamaServer REMOTEOLLAMASERVER] [--context]
An open-source framework for augmenting humans using AI.
options:
-h, --help show this help message and exit
--text TEXT, -t TEXT Text to extract summary from
--copy, -C Copy the response to the clipboard
--agents, -a Use praisonAI to create an AI agent and then use it. ex: 'write me a movie script'
--output [OUTPUT], -o [OUTPUT]
Save the response to a file
--session [SESSION], -S [SESSION]
Continue your previous conversation. Default is your previous conversation
--gui Use the GUI (Node and npm need to be installed)
--stream, -s Use this option if you want to see the results in realtime. NOTE: You will not be able to pipe the output into another command.
--list, -l List available patterns
--temp TEMP sets the temperature for the model. Default is 0
--top_p TOP_P set the top_p for the model. Default is 1
--frequency_penalty FREQUENCY_PENALTY
sets the frequency penalty for the model. Default is 0.1
--presence_penalty PRESENCE_PENALTY
sets the presence penalty for the model. Default is 0.1
--update, -u Update patterns.
--pattern PATTERN, -p PATTERN
The pattern (prompt) to use
--setup Set up your fabric instance
--changeDefaultModel CHANGEDEFAULTMODEL
Change the default model. For a list of available models, use the --listmodels flag.
--model MODEL, -m MODEL
Select the model to use
--listmodels List all available models
--remoteOllamaServer REMOTEOLLAMASERVER
The URL of the remote ollamaserver to use. ONLY USE THIS if you are using a local ollama server in a non-default location or port
--context, -c Use Context file (context.md) to add context to your pattern
示例命令
默认情况下,客户端无需服务器即可运行Fabric模式(模式是在安装过程中下载的)。这意味着客户端使用给定的输入和使用的Fabric模式直接连接到OpenAI。
- 根据来自
stdin
的输入运行summarize
模式。
pbpaste | fabric --pattern summarize
- 使用
--stream
选项运行analyze_claims
模式以获得即时和流式结果。
pbpaste | fabric --stream --pattern analyze_claims
- 使用
--stream
选项运行extract_wisdom
模式,从任何YouTube视频中获得即时和流式结果(很像原始介绍视频)。
yt --transcript https://youtube.com/watch?v=uXs-zPc63kM | fabric --stream --pattern extract_wisdom
- 新的所有模式都已作为别名添加到您的bash(或zsh)配置文件中
pbpaste | analyze_claims --stream
注:更多示例将在接下来的几天内发布,包括演示视频!
只需使用模式
如果你不想做任何花哨的事情,你只是想要很多很棒的提示,你可以导航到/patterns
目录并开始探索!
我们希望,如果您没有使用Fabric中的任何其他内容,Patterns本身将使该项目有用。
你可以在你拥有的任何人工智能应用程序中使用你在那里看到的任何模式,无论是ChatGPT还是其他应用程序或网站。我们的计划和预测是,人们很快就会分享比我们发布的更多的东西,他们会比我们的好得多。
群众的智慧为胜利。
创建您自己的 Fabric Mill
但我们不仅仅提供模式。我们为您提供代码 来构建您自己的Fabric服务器 和 个人AI基础设施!
四、结构
fabric 的主题是……fabric ——就像……编织材料。所以,想想毯子、被子、图案等。这是概念和结构:
1、组件
Fabric生态系统有三个主要组成部分,都在这个纺织主题中命名。
- Mill 是使Patterns可用的(可选)服务器。
- Patterns是实际的粒度AI用例(提示)。
- Stitches 是被链接在一起创建高级功能的图案(见下文)。
- Looms 是调用由Mill托管的特定模式的客户端应用程序。
2、CLI 原生
该项目最酷的部分之一是它是命令行原生的!
您在/patterns
目录中看到的每个模式都可以在您使用的任何AI应用程序中使用,但您也可以使用/server
代码设置自己的服务器,然后直接调用API!
设置好后,您可以执行以下操作:
# Take any idea from `stdin` and send it to the `/write_essay` API!
echo "An idea that coding is like speaking with rules." | write_essay
3、直接调用模式
基于Markdown的fabric
及其格式的一个关键特征是能够直接引用(和编辑)单个图案,而无需任何周围的代码。
例如,下面介绍如何调用extract_wisdom
模式的直接位置。
https://github.com/danielmiessler/fabric/blob/main/patterns/extract_wisdom/system.md
这意味着您可以干净地直接引用任何模式以用于基于Web的AI应用程序、您自己的代码或任何地方!
更好的是,您还可以让您的Mill功能直接调用系统 和fabric
中的用户提示,这意味着您可以让您的个人AI生态系统自动跟上您最喜欢的模式的最新版本。
这是代码中的样子:
https://github.com/danielmiessler/fabric/blob/main/server/fabric_api_server.py
# /extwis
@app.route("/extwis", methods=["POST"])
@auth_required # Require authentication
def extwis():
data = request.get_json()
# Warn if there's no input
if "input" not in data:
return jsonify({"error": "Missing input parameter"}), 400
# Get data from client
input_data = data["input"]
# Set the system and user URLs
system_url = "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/extract_wisdom/system.md"
user_url = "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/extract_wisdom/user.md"
# Fetch the prompt content
system_content = fetch_content_from_url(system_url)
user_file_content = fetch_content_from_url(user_url)
# Build the API call
system_message = {"role": "system", "content": system_content}
user_message = {"role": "user", "content": user_file_content + "\n" + input_data}
messages = [system_message, user_message]
try:
response = openai.chat.completions.create(
model="gpt-4-1106-preview",
messages=messages,
temperature=0.0,
top_p=1,
frequency_penalty=0.1,
presence_penalty=0.1,
)
assistant_message = response.choices[0].message.content
return jsonify({"response": assistant_message})
except Exception as e:
return jsonify({"error": str(e)}), 500
五、示例
下面是extract_wisdom
模式的一个简略输出示例(每个部分仅限于10个项目)。
# Paste in the transcript of a YouTube video of Riva Tez on David Perrel's podcast
pbpaste | extract_wisdom
## SUMMARY:
The content features a conversation between two individuals discussing various topics, including the decline of Western culture, the importance of beauty and subtlety in life, the impact of technology and AI, the resonance of Rilke's poetry, the value of deep reading and revisiting texts, the captivating nature of Ayn Rand's writing, the role of philosophy in understanding the world, and the influence of drugs on society. They also touch upon creativity, attention spans, and the importance of introspection.
***
## IDEAS:
1. Western culture is perceived to be declining due to a loss of values and an embrace of mediocrity.
2. Mass media and technology have contributed to shorter attention spans and a need for constant stimulation.
3. Rilke's poetry resonates due to its focus on beauty and ecstasy in everyday objects.
4. Subtlety is often overlooked in modern society due to sensory overload.
5. The role of technology in shaping music and performance art is significant.
6. Reading habits have shifted from deep, repetitive reading to consuming large quantities of new material.
7. Revisiting influential books as one ages can lead to new insights based on accumulated wisdom and experiences.
8. Fiction can vividly illustrate philosophical concepts through characters and narratives.
9. Many influential thinkers have backgrounds in philosophy, highlighting its importance in shaping reasoning skills.
10. Philosophy is seen as a bridge between theology and science, asking questions that both fields seek to answer.
***
## QUOTES:
1. "You can't necessarily think yourself into the answers. You have to create space for the answers to come to you."
2. "The West is dying and we are killing her."
3. "The American Dream has been replaced by mass-packaged mediocrity porn, encouraging us to revel like happy pigs in our own meekness."
4. "There's just not that many people who have the courage to reach beyond consensus and go explore new ideas."
5. "I'll start watching Netflix when I've read the whole of human history."
6. "Rilke saw beauty in everything... He sees it's in one little thing, a representation of all things that are beautiful."
7. "Vanilla is a very subtle flavor... it speaks to sort of the sensory overload of the modern age."
8. "When you memorize chapters [of the Bible], it takes a few months, but you really understand how things are structured."
9. "As you get older, if there's books that moved you when you were younger, it's worth going back and rereading them."
10. "She [Ayn Rand] took complicated philosophy and embodied it in a way that anybody could resonate with."
***
## HABITS:
1. Avoiding mainstream media consumption for deeper engagement with historical texts and personal research.
2. Regularly revisiting influential books from youth to gain new insights with age.
3. Engaging in deep reading practices rather than skimming or speed-reading material.
4. Memorizing entire chapters or passages from significant texts for better understanding.
5. Disengaging from social media and fast-paced news cycles for more focused thought processes.
6. Walking long distances as a form of meditation and reflection.
7. Creating space for thoughts to solidify through introspection and stillness.
8. Embracing emotions such as grief or anger fully rather than suppressing them.
9. Seeking out varied experiences across different careers and lifestyles.
10. Prioritizing curiosity-driven research without specific goals or constraints.
***
## FACTS:
1. The West is perceived as declining due to cultural shifts away from traditional values.
2. Attention spans have shortened due to technological advancements and media consumption habits.
3. Rilke's poetry emphasizes finding beauty in everyday objects through detailed observation.
4. Modern society often overlooks subtlety due to sensory overload from various stimuli.
5. Reading habits have evolved from deep engagement with texts to consuming large quantities quickly.
6. Revisiting influential books can lead to new insights based on accumulated life experiences.
7. Fiction can effectively illustrate philosophical concepts through character development and narrative arcs.
8. Philosophy plays a significant role in shaping reasoning skills and understanding complex ideas.
9. Creativity may be stifled by cultural nihilism and protectionist attitudes within society.
10. Short-term thinking undermines efforts to create lasting works of beauty or significance.
***
## REFERENCES:
1. Rainer Maria Rilke's poetry
2. Netflix
3. Underworld concert
4. Katy Perry's theatrical performances
5. Taylor Swift's performances
6. Bible study
7. Atlas Shrugged by Ayn Rand
8. Robert Pirsig's writings
9. Bertrand Russell's definition of philosophy
10. Nietzsche's walks
六、自定义模式
您还可以将自定义模式与Fabric一起使用,这意味着您在本地保留而不上传到Fabric的模式。
存储它们的一个可能位置是~/.config/custom-fabric-patterns
。
然后当你想要使用它们时,只需将它们复制到~/.config/fabric/patterns
中。
cp -a ~/.config/custom-fabric-patterns/* ~/.config/fabric/patterns/
然后你可以运行
pbpaste | fabric -p your_custom_pattern
七、Agents
新功能!我们已将 PraisonAI整合到Fabric中。此特征创建AI代理,然后使用它们执行任务。
echo "Search for recent articles about the future of AI and write me a 500-word essay on the findings" | fabric --agents
此特征适用于所有OpenAI和Ollama模型,但不适用于Claude。您可以使用-m
标志指定模型。
有关这个惊人项目的更多信息,请访问https://github.com/MervinPraison/PraisonAI。
八、助手应用
这些是使用Fabric的辅助工具。示例包括从媒体文件中获取转录本、获取有关媒体的元信息等。
1、YouTube
yt
是一个命令,它使用YouTubeAPI来提取抄本、提取用户评论、获取视频时长和其他功能。它的主要函数是从视频中获取抄本,然后可以将其拼接(管道)到其他Fabric Patterns中。
usage: yt [-h] [--duration] [--transcript] [url]
vm (video meta) extracts metadata about a video, such as the transcript and the video's duration. By Daniel Miessler.
positional arguments:
url YouTube video URL
options:
-h, --help Show this help message and exit
--duration Output only the duration
--transcript Output only the transcript
--comments Output only the user comments
2、TS(音频转录)
'ts’是使用OpenAI Whisper API转录音频文件的命令。由于上下文窗口的原因,此工具使用pydub将文件拆分为10分钟的片段。有关pydub的更多信息,请参考https://github.com/jiaaro/pydub
安装
mac:
brew install ffmpeg
linux:
apt install ffmpeg
windows:
download instructions https://www.ffmpeg.org/download.html
ts -h
usage: ts [-h] audio_file
Transcribe an audio file.
positional arguments:
audio_file The path to the audio file to be transcribed.
options:
-h, --help show this help message and exit
3、保存
save
是一个“tee-like” 的实用程序,用于流水线保存内容,同时保持输出流不变。可以选择通过 "FABRIC_FRONTMATTER"环境变量
如果您想默认变量,请将它们设置在~/.config/fabric/.env
中。
FABRIC_OUTPUT_PATH
需要设置,以便save
写入的位置。
FABRIC_FRONTMATTER_TAGS
是可选的,但对于跟踪标签如何进入您的PKM很有用,如果这对您很重要的话。
用法
usage: save [-h] [-t, TAG] [-n] [-s] [stub]
save: a "tee-like" utility to pipeline saving of content, while keeping the output stream intact. Can optionally generate "frontmatter" for PKM utilities like Obsidian via the
"FABRIC_FRONTMATTER" environment variable
positional arguments:
stub stub to describe your content. Use quotes if you have spaces. Resulting format is YYYY-MM-DD-stub.md by default
options:
-h, --help show this help message and exit
-t, TAG, --tag TAG add an additional frontmatter tag. Use this argument multiple timesfor multiple tags
-n, --nofabric don't use the fabric tags, only use tags from --tag
-s, --silent don't use STDOUT for output, only save to the file
示例
echo test | save --tag extra-tag stub-for-name
test
$ cat ~/obsidian/Fabric/2024-03-02-stub-for-name.md
---
generation_date: 2024-03-02 10:43
tags: fabric-extraction stub-for-name extra-tag
---
test
2024-07-25(四)