Flowise 是什么
如果你用过 LangChain,你会发现它非常强大,但学习曲线也确实不低。那些 Chain、Agent、Memory、Tool 的概念,需要花费不少时间才能理解清楚。有没有办法让我们更直观地构建 AI 应用呢?
Flowise 就是为了回答这个问题而生的。它是一个开源的可视化 AI 应用构建工具,基于 LangChainJS 开发,提供了拖拽式的界面,让我们可以像画流程图一样构建 RAG 管道和 Agent。截至目前,Flowise 在 GitHub 上获得了超过 50K 颗星,已经成为 LangChain 生态中最受欢迎的可视化工具之一。
Flowise 的核心理念是「所见即所得」。你不需要写大量代码,只需要拖拽节点、连接它们、配置参数,就能构建一个完整的 AI 应用。这种低代码/无代码的方式,大大降低了 AI 应用开发的门槛。
核心功能解析
1. 拖拽式界面
Flowise 提供了直观的拖拽式界面。在主画布上,我们可以从左侧的节点面板中选择需要的组件,然后拖到画布上进行配置和连接。
主界面包含以下几个区域:
- 节点面板 - 包含所有可用的组件,按类别分组
- 画布区域 - 我们拖拽和连接节点的地方
- 属性配置 - 选中节点后,右侧会显示配置选项
- 预览/测试 - 可以直接在界面中测试流程
2. 节点类型
Flowise 提供了丰富的节点类型,涵盖了构建 AI 应用的各种需求:
2.1 LLM 节点
| 节点 | 功能描述 |
|---|---|
| OpenAI | GPT-4、GPT-3.5 Turbo |
| Anthropic | Claude 系列模型 |
| Azure OpenAI | 微软 Azure 版 OpenAI |
| Ollama | 本地开源模型 |
| HuggingFace | HuggingFace Hub 模型 |
# Flowise 中 LLM 节点的配置示例
{
"model": "gpt-4o-mini",
"temperature": 0.7,
"maxTokens": 2000,
"apiKey": "${OPENAI_API_KEY}",
"basePath": "https://api.openai.com/v1"
}
2.2 嵌入和向量化
| 节点 | 功能描述 |
|---|---|
| OpenAI Embeddings | OpenAI 的 text-embedding-3-small |
| Azure OpenAI Embeddings | Azure 版本嵌入 |
| Ollama Embeddings | 本地模型嵌入 |
| HuggingFace Embeddings | HuggingFace 嵌入模型 |
2.3 向量存储
| 节点 | 功能描述 |
|---|---|
| Pinecone | Pinecone 向量数据库 |
| Chroma | 本地向量库 |
| Weaviate | 开源向量数据库 |
| Qdrant | 高性能向量搜索 |
| Redis | 使用 Redis 作为向量存储 |
2.4 文档处理
| 节点 | 功能描述 |
|---|---|
| PDF File | PDF 文档加载 |
| Docx File | Word 文档加载 |
| CSV Loader | CSV 文件加载 |
| Text Loader | 纯文本加载 |
| Web Page | 网页内容抓取 |
| Notion | Notion 页面导入 |
2.5 Agent 相关
| 节点 | 功能描述 |
|---|---|
| Conversational Agent | 对话型 Agent |
| OpenAI Agent | 使用 OpenAI 函数的 Agent |
| ReAct Agent | ReAct 推理 Agent |
| Tool Agent | 工具调用 Agent |
3. RAG 管道构建
RAG 是 Flowise 最受欢迎的应用场景之一。我们可以可视化地构建一个完整的 RAG 管道:
文档加载 → 文本分割 → 向量化 → 存储到向量库
↓
用户查询 → 向量化 → 向量检索 → 上下文组装 → LLM 生成答案
# Flowise RAG 流程配置示例
flow:
nodes:
- id: document_loader_1
type: PDFLoader
position: [100, 100]
data:
filePath: "./docs/manual.pdf"
page: 1
- id: text_splitter_1
type: RecursiveCharacterTextSplitter
position: [250, 100]
data:
chunkSize: 1000
chunkOverlap: 200
- id: embedding_1
type: OpenAIEmbeddings
position: [400, 100]
data:
model: text-embedding-3-small
- id: vectorstore_1
type: Pinecone
position: [550, 100]
data:
indexName: "knowledge-base"
namespace: "docs"
- id: question_embedding
type: OpenAIEmbeddings
position: [400, 300]
data:
model: text-embedding-3-small
- id: retriever_1
type: VectorStoreRetriever
position: [550, 300]
data:
searchType: similarity
k: 5
- id: llm_1
type: ChatOpenAI
position: [700, 300]
data:
model: gpt-4o-mini
temperature: 0.7
- id: answer_node
type: StuffDocumentsChain
position: [850, 300]
data:
prompt: |
基于以下上下文回答用户的问题。如果上下文中没有相关信息,请说明无法回答。
上下文:
{context}
问题:{question}
edges:
- source: document_loader_1
target: text_splitter_1
- source: text_splitter_1
target: embedding_1
- source: embedding_1
target: vectorstore_1
- source: question_embedding
target: retriever_1
- source: vectorstore_1
target: retriever_1
- source: retriever_1
target: llm_1
- source: llm_1
target: answer_node
4. Agent 构建
Flowise 支持构建各种类型的 Agent。我们可以配置 Agent 使用的工具,让它能够执行搜索、计算、访问数据库等操作。
# Flowise Agent 配置示例
{
"agentType": "openai-functions",
"tools": [
{
"name": "search",
"description": "搜索互联网信息",
"tool": "serpapi"
},
{
"name": "calculator",
"description": "执行数学计算",
"tool": "calculator"
},
{
"name": "python",
"description": "运行 Python 代码",
"tool": "python_repl"
}
],
"memory": {
"type": "buffer",
"windowSize": 10
}
}
5. API 导出
Flowise 的一大亮点是可以将我们构建的流程一键导出为 API。我们不需要编写额外的代码,Flowise 会自动生成 API 端点。
# Flowise API 调用示例
curl -X POST 'http://localhost:3000/api/v1/prediction/{flow_id}' \
-H 'Content-Type: application/json' \
-d '{
"question": "什么是 Flowise?"
}'
实际应用场景
1. 快速原型验证
当我们有一个 AI 想法想要快速验证时,Flowise 是非常好的选择。不需要写代码,几个小时就能搭建一个可用的原型。
# 使用 Flowise API 构建一个简单问答系统
import requests
FLOWISE_URL = "http://localhost:3000"
FLOW_ID = "your-flow-id"
def ask_question(question: str):
"""向 Flowise 流程提问"""
url = f"{FLOWISE_URL}/api/v1/prediction/{FLOW_ID}"
headers = {
"Content-Type": "application/json"
}
payload = {
"question": question,
"overrideConfig": {}
}
response = requests.post(url, json=payload, headers=headers)
result = response.json()
return result.get("text", result.get("result", ""))
# 使用示例
answer = ask_question("请介绍一下 RAG 技术")
print(answer)
2. 企业内部知识库
企业可以使用 Flowise 构建内部知识问答系统。上传 PDF、Word 等文档,配置好 RAG 管道,员工就能用自然语言查询企业知识。
3. 多模态应用
Flowise 支持多种文档类型的处理,可以构建处理 PDF 合同、Word 简历、Excel 报表等的多模态应用。
4. 自动化工作流
结合 Agent 能力,Flowise 可以构建自动化的 AI 工作流,比如自动回复邮件、自动处理工单等。
与 Dify 的对比
Flowise 和 Dify 都是可视化 AI 应用构建工具,但它们的定位和特点有所不同:
| 特性 | Flowise | Dify |
|---|---|---|
| 底层框架 | LangChainJS | 自研 |
| 界面风格 | 纯拖拽流程图 | 工作流 + 简易模式 |
| 学习门槛 | 较低 | 中等 |
| 部署复杂度 | 简单 | 中等 |
| 企业功能 | 基础 | 完善 |
| API 封装 | 自动生成 | 开箱即用 |
| 自定义程度 | 高 | 中等 |
选择建议
-
选择 Flowise:
- 你是 LangChain 重度用户
- 需要高度自定义的流程
- 主要在本地或私有环境开发
- 喜欢纯拖拽的构建方式
-
选择 Dify:
- 需要快速部署对外服务
- 需要企业级的安全和权限
- 团队对 LangChain 不熟悉
- 需要完整的监控和分析
-
两者结合:
- 使用 Flowise 快速验证原型
- 验证成功后,使用 Dify 部署生产版本
快速上手指南
本地安装
# 克隆项目
git clone https://github.com/FlowiseAI/Flowise.git
cd Flowise
# 安装依赖
npm install -g yarn
yarn install
# 启动服务
yarn start
# 访问 http://localhost:3000
Docker 部署
# docker-compose.yml
version: '3.8'
services:
flowise:
image: flowiseai/flowise
ports:
- "3000:3000"
environment:
- PORT=3000
- FLOWISE_USERNAME=admin
- FLOWISE_PASSWORD=123456
- DATABASE_TYPE=sqlite
- DATABASE_PATH=/root/.flowise
volumes:
- ./storage:/root/.flowise
基本使用流程
- 创建流程:点击「New Chatflow」,进入可视化编辑界面
- 添加节点:从左侧面板拖拽节点到画布
- 连接节点:从一个节点的输出拖拽到另一个节点的输入
- 配置节点:选中节点,在右侧面板配置参数
- 保存流程:点击「Save」保存流程
- 测试使用:在右侧对话框中测试
进阶技巧
1. 环境变量管理
Flowise 支持使用环境变量来管理敏感信息:
# 在节点配置中使用
${OPENAI_API_KEY}
${PINECONE_API_KEY}
在 .env 文件中定义:
OPENAI_API_KEY=sk-xxx
PINECONE_API_KEY=xxx
2. 流程导入导出
Flowise 支持将流程导出为 JSON 文件,方便分享和备份:
// flow.json
{
"nodes": [...],
"edges": [...]
}
3. 自定义节点开发
如果现有的节点不满足需求,Flowise 支持开发自定义节点:
// 自定义节点示例
import { INode, INodeData, INodeParams } from '../../../src'
class MyCustomNode implements INode {
label: string = 'My Custom Node'
name: string = 'myCustomNode'
type: string = 'action'
icon: string = '/custom/icon.svg'
category: string = 'Custom'
baseClasses: string[] = ['Action']
inputs: INodeParams[] = [...]
outputs: INodeParams[] = [...]
async run(nodeData: INodeData): Promise<string> {
// 自定义逻辑
return result
}
}
4. 批量文档处理
对于大量文档,可以使用批处理模式:
# 批量上传文档到 Flowise
import os
import requests
FLOWISE_URL = "http://localhost:3000"
def upload_documents(directory: str):
"""批量上传文档"""
files = os.listdir(directory)
for file in files:
file_path = os.path.join(directory, file)
with open(file_path, 'rb') as f:
files = {'file': f}
response = requests.post(
f"{FLOWISE_URL}/api/v1/document-loader/file",
files=files
)
print(f"Uploaded: {file}")
# 使用
upload_documents("./documents")
总结
Flowise 是一个优秀的低代码 AI 应用构建工具。它将复杂的 LangChain 功能封装成了直观的可视化界面,让我们可以快速构建 RAG 管道和 Agent。虽然在企业级功能方面不如 Dify 完善,但对于开发者和小型团队来说,Flowise 是一个不可多得的利器。
特别是在快速原型验证和学习 LangChain 概念方面,Flowise 有着独特的优势。通过可视化的方式,我们可以更直观地理解 Chain、Agent、Memory 这些抽象概念,从而更好地掌握 AI 应用开发的技巧。
工具的价值不在于它有多复杂,而在于它能否帮助你解决实际问题。从最简单的流程开始,在实践中逐步深入,这比一开始就追求完美更加重要。
相关文章
评论
加载中...
评论
加载中...