概述
Dify 是由 LangGenius 团队开发的开源 LLM 应用开发平台。它提供可视化的应用构建界面,支持工作流编排、Prompt 管理、RAG 引擎、Agent 模式等。Dify 的目标是让 AI 应用开发更简单高效,降低技术门槛。它支持私有部署,适合对数据安全有要求的企业。Dify 在 GitHub 上获得 50k+ star,是最受欢迎的 LLM 应用平台之一。
安装
推荐使用 Docker Compose 部署 Dify,以简化安装过程。需要 Docker 20+ 和 Docker Compose 2+。也支持本地开发和云部署。
# Clone the repository
git clone https://github.com/langgenius/dify.git
cd dify/docker
# Copy environment variables
cp .env.example .env
# Start the service
docker compose up -d
# Access http://localhost:3000
# Default account: admin / Dify123456工作流
Dify 的核心功能是可视化工作流编排。通过拖拽节点,可以构建复杂的 AI 处理流程。节点类型包括:LLM、知识检索、代码执行、条件分支、HTTP 请求等。工作流支持调试、版本管理和 API 调用。
# Workflow example (via API call)
curl -X POST 'http://localhost/v1/workflows/run' \
-H 'Authorization: Bearer {api_key}' \
-H 'Content-Type: application/json' \
-d '{
"inputs": {"query": "Analyze this report"},
"response_mode": "streaming"
}'Prompt IDE
Dify 提供 Prompt IDE,允许用户可视化编辑和测试提示词。支持变量插值、少样本示例、模型比较等。可以管理多个版本的提示词进行 A/B 测试。Prompt IDE 显著提升提示词工程的效率。
RAG 引擎
Dify 内置 RAG 引擎,支持文档上传、自动分块、向量索引、混合检索等。支持多种数据源:PDF、Word、网页、API 等。提供知识库管理界面,便于维护和更新知识。
# Upload documents to the knowledge base via API
curl -X POST 'http://localhost/v1/datasets/{dataset_id}/documents' \
-H 'Authorization: Bearer {api_key}' \
-F '[email protected]' \
-F 'data={"name":"Report","process_rule":{"mode":"automatic"}}'Agent 模式
Dify 支持 Agent 模式,允许 AI 自主调 用工具完成任务。支持 Function Calling 和 ReAct 等 Agent 类型。可配置多种工具:搜索、代码执行、数据库查询、自定义 API 等。Agent 模式适用于复杂任务场景。
# Agent configuration example
{
"agent_mode": {
"enabled": true,
"strategy": "function_call",
"tools": [
{"name": "web_search", "config": {}},
{"name": "code_interpreter", "config": {}}
]
}
}API 访问
Dify 为每个应用提供 RESTful API,支持聊天、工作流、知识库等操作。API 兼容 OpenAI 格式,可轻松集成到现有系统中。支持流式响应、文件上传、会话管理等。
# Chat application API
curl -X POST 'http://localhost/v1/chat-messages' \
-H 'Authorization: Bearer {api_key}' \
-H 'Content-Type: application/json' \
-d '{
"inputs": {},
"query": "Hello",
"user": "user-123",
"response_mode": "streaming"
}'插件
Dify 支持插件系统以扩展功能。插件可以添加新工具、数据源、模型等。社区提供丰富的插件,如搜索引擎、数据库连接器、第三方 API 等。也支持自定义插件开发。
部署
Dify 支持多种部署方式:Docker Compose(单机)、Kubernetes(集群)、云服务(Dify Cloud)。企业版提供高可用、SSO、审计日志等高级功能。部署时需要考虑数据库、向量数据库、对象存储等组件的配置。
# Kubernetes deployment
helm repo add dify https://dify-ai.github.io/dify-helm
helm install dify dify/dify \
--set global.image.tag=latest \
--set ingress.enabled=true定价
Dify 提供免费的开源版本,可自行部署。Dify Cloud 提供托管服务,有免费和付费计划。企业版提供高级功能和支持,价格根据团队规模和需求定制。开源版本已能满足大部分需求,付费版本主要提供托管和企业功能。
Configuration
Dify is configured through its .env file and the web dashboard. The .env file sets the secret key, DB connection, and vector store; docker-compose.yml orchestrates the services. In the dashboard you add LLM providers (OpenAI, Anthropic, local models) and configure workflows, RAG knowledge bases, and agent tools.
# .env (dify/docker/.env)
SECRET_KEY=your-random-secret
DB_USERNAME=postgres
DB_PASSWORD=your-password
VECTOR_STORE=weaviate # or qdrant, milvus, pgvector
# Start the stack
cd dify/docker
cp .env.example .env
# edit .env, then:
docker compose up -d
# Access http://localhost:3000 (admin / Dify123456)
# In the dashboard:
# Settings -> Model Provider -> add OpenAI/Anthropic/local keys
# Knowledge -> create dataset -> upload docs -> pick chunking + embedding
# Workflow -> drag nodes (LLM, retrieval, code, HTTP) -> publish -> API keyFor production, change the default admin password and use an external Postgres + vector store.
FAQ
Common questions cover self-hosting, model providers, cost, Dify vs LangChain, and API access. Dify is a visual platform you self-host with Docker; LangChain is a code framework. Each Dify app gets an OpenAI-compatible REST API.
Q: Can I self-host Dify?
A: Yes—docker compose up for single-machine, or Helm/Kubernetes for
clusters. The open-source edition is free.
Q: Which LLM providers are supported?
A: OpenAI, Anthropic, Google, local Ollama, and many more via the
Model Provider settings.
Q: Dify vs LangChain?
A: Dify is a visual low-code platform (drag-and-drop workflows); LangChain
is a Python code framework. Dify suits non-developers and fast prototyping.
Q: Does each app get an API?
A: Yes—every chat/workflow app exposes a REST API compatible with the
OpenAI format, plus streaming and file uploads.
Q: Is there a free tier?
A: The open-source self-hosted edition is free; Dify Cloud has free and
paid plans; the enterprise edition adds SSO and audit logs.Change the default admin password (Dify123456) immediately after first launch.