Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ scripts/stress-test/reports/

# 二开新增
docker/volumes/admin-server/*
docker/.env.bak*
docker/backups/
docker/**/*.bak
docker/nginx/conf.d/*.before_*

# Next.js build output
.next/
128 changes: 128 additions & 0 deletions README_DIFY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,131 @@
# T1000 Dify / Dify Plus 工作记录

更新时间:2026-06-17

本文档用于沉淀 T1000 服务器上 Dify、Dify Plus、MinerU 文档解析流水线、模型服务和权限验证相关工作。原始 Dify README 保留在本文档后半部分。

## 1. 部署现状

- 旧版官方 Dify 保留在 `/home/yu/projects/dify-rag/docker`,当前不直接改动,作为稳定环境继续保留。
- Dify Plus 采用旁路部署方式,目录为 `/home/yu/projects/dify-plus/docker`,Compose 文件为 `docker-compose.dify-plus.yaml`,容器名前缀为 `difyplus_sidecar-*`。
- Dify Plus 对外访问地址:`http://118.196.65.83:18090`。
- Dify Plus 管理中心地址:`http://118.196.65.83:18091/admin/login`。
- 管理中心曾出现无法进入的问题,原因是 admin-web 前端请求 `/admin/api/...`,但 nginx 只代理了 `/api/...`。已通过 `docker/admin-web/my.conf` 增加 `/admin/api` 代理,并在 Compose 中为 `admin-web` 挂载该配置。

## 2. Dify Plus 迁移和基础验证

已在 Dify Plus 中复刻旧 Dify 的主要应用和知识库,便于对比 Plus 版本能力。

已迁移或复刻的应用:

- 超级大脑
- 专属智能客服
- 每日新闻摘要-国内
- 知识库2 + 聊天机器人
- 知识库 + 聊天机器人3

已迁移或复刻的知识库:

- 企业演示知识库
- 部门测试知识库2
- Convert to Markdown 1
- Untitled 1
- MinerU 中文文档知识库

迁移过程中已处理文件、向量数据、模型供应商凭据、租户密钥和 Plus `SECRET_KEY` 相关问题,并验证本地 Embedding 与 Rerank 服务可被 Plus 容器访问,包括 Ollama `bge-m3` 和 Xinference `bge-reranker-v2-m3`。

## 3. MinerU 文档解析流水线

目标是在 Dify 中通过流水线创建知识库:先调用自部署 MinerU 服务完成文档解析,再进入常规知识库流程,包括分段、Embedding、Rerank 和检索。

已经完成或处理的问题:

- 确认可以走自部署 MinerU 服务,而不是只依赖外部插件形态。
- 按中文文档优先场景配置 Embedding 与 Rerank 模型。
- 将流水线参数从纯英文调整为中文 + 英文的表达方式,并补充默认值。
- 修复默认值只显示但不提交的问题,避免用户必须手动重新输入数字才能进入下一步。
- 分析默认一次最多上传 5 个文件的限制,判断该限制主要是为了控制解析、队列、存储、Embedding 和 Rerank 阶段的资源压力。
- 处理 DOC 等非标准输入格式的体验问题,方向是由流水线前置兼容或转换,而不是要求上传者手动预处理。
- 排查 DOC 文件长时间排队问题,并结合队列、Worker 并发和资源消耗分析处理能力上限。
- 解释 MinerU 是否使用多核:取决于服务自身 Worker、进程数和并发配置,不等于默认无限制占满所有 CPU。

## 4. 资源与运行观察

已围绕 Dify、MinerU、Embedding 和 Rerank 做过资源消耗观察,重点关注:

- 上传文件数量增加时,MinerU 解析阶段对 CPU、内存和队列的影响。
- 文档解析后进入知识库流程时,Embedding 与 Rerank 对本地小模型服务的调用压力。
- Dify Plus 旁路部署不应影响旧 Dify 的稳定运行。

后续如果要提高一次上传数量,建议先做小步压测,再调整上传上限、Worker 并发、队列超时、容器资源限制和模型服务并发,避免解析阶段和向量化阶段互相拖垮。

## 5. 账号、角色和权限验证

Dify / Dify Plus 当前不是完整的任意 RBAC 系统。已确认:

- 工作区角色主要是固定角色,例如 `owner`、`admin`、`editor`、`normal`、`dataset_operator`。
- 知识库可以通过 `dataset_permissions` 做部分成员授权。
- 应用级“只看某几个应用”的能力不是官方默认完整能力,本次为了测试做了账号级白名单补丁。
- 模型权限没有完整的逐用户模型白名单,本次主要通过额度方式做近似验证。

已创建的测试账号,密码以本机部署环境记录为准,不写入仓库:

- `t1000-admin@test.local`:管理员角色,可访问全部 5 个知识库,额度 100000。
- `t1000-editor@test.local`:编辑角色,知识库范围为企业演示知识库、Convert to Markdown 1、MinerU 中文文档知识库,额度 20000。
- `t1000-kb@test.local`:知识库操作角色,知识库范围为部门测试知识库2、MinerU 中文文档知识库,额度 10000。
- `t1000-normal@test.local`:普通角色,仅企业演示知识库,额度 1000。
- `t1000-limited@test.local`:普通角色,额度设置为已耗尽,用于额度限制测试。
- `t1000-twoapps@test.local`:普通角色,用于“只能使用两个应用”的测试。

5 个知识库已调整为 `partial_members`,并保留 owner 的完整访问能力。

## 6. 应用可见性和应用中心问题

用户希望验证“一个账号只能看到两个应用”的效果。Dify 默认工作室应用列表和探索 / 应用中心不是同一套逻辑,因此分别做了处理。

当前给 `t1000-editor@test.local` 和 `t1000-twoapps@test.local` 配置的两个可见应用:

- 超级大脑
- 专属智能客服

已修改和验证的逻辑:

- 工作室应用列表过滤:`api/services/app_service.py`
- 应用详情访问拦截:`api/controllers/console/app/wraps.py`
- 应用中心推荐 / 已安装应用空指针修复和账号过滤:`api/services/recommended_app_service_extend.py`
- 探索页已安装应用过滤:`api/controllers/console/explore/installed_app.py`

曾遇到的问题:

- “探索 / 应用中心”显示没有 Web Apps。原因是它不是工作室应用列表,而是使用已安装应用 / 推荐应用数据。
- `/console/api/installed/apps` 曾出现 500,原因是扩展代码假设 `installed_app` 一定存在,实际可能为空。已增加空值跳过逻辑。
- 为 `t1000-twoapps@test.local` 补充了两个应用的 installed / recommended 记录,并将相关应用设为可公开和启用站点。

注意:当前应用白名单是测试级硬编码补丁,适合验证效果;如果后续要长期使用,应改造成数据库配置或管理后台可配置能力。

## 7. 当前代码改动摘要

与本次 Dify Plus 验证相关的主要改动:

- `docker/admin-web/my.conf`:修复管理中心 `/admin/api` 代理。
- `docker/docker-compose.dify-plus.yaml`:为 `admin-web` 增加 nginx 配置挂载。
- `api/services/app_service.py`:增加指定账号的工作室应用列表白名单过滤。
- `api/controllers/console/app/wraps.py`:增加指定账号访问非白名单应用详情时的拦截。
- `api/services/recommended_app_service_extend.py`:修复已安装应用空指针问题,并增加指定账号应用中心过滤。
- `api/controllers/console/explore/installed_app.py`:增加探索页已安装应用的账号级过滤。

## 8. 后续建议

- 将账号级应用白名单从代码常量迁移到数据库配置,避免以后每次调整账号和应用都要改代码。
- 为应用中心、工作室应用列表和 API 访问统一一套权限判断逻辑,避免前端显示与后端访问不一致。
- 对 MinerU 流水线做一次包含 PDF、DOC、DOCX、图片 PDF 和扫描件的批量压测,记录不同文件类型下的耗时、CPU、内存、队列等待和失败率。
- 如果要突破默认 5 文件上传限制,应同步调整队列、Worker 并发、模型服务并发和超时配置,并保留回退方案。
- 对 Dify Plus 的二开增强能力继续做对比测试,重点看管理中心、权限体系、应用中心、知识库权限和计费 / 额度模块是否稳定。

---

# Upstream Dify README

![cover-v5-optimized](https://github.com/langgenius/dify/assets/13230914/f9e19af5-61ba-4119-b926-d10c4c06ebab)

<p align="center">
Expand Down
20 changes: 19 additions & 1 deletion api/controllers/console/app/wraps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,26 @@
R1 = TypeVar("R1")


ACCOUNT_VISIBLE_APP_IDS = {
# T1000 test account: t1000-editor@test.local
"8f6f424f-5435-4786-870b-2dc31674f05d": {
"60629616-8821-48c6-aedc-18f6b3e8d24e",
"cda60867-051d-4e19-ac36-3167a3ea6403",
},
# T1000 test account: t1000-twoapps@test.local
"d7eda734-576a-4354-a08a-776dfac2b50d": {
"60629616-8821-48c6-aedc-18f6b3e8d24e",
"cda60867-051d-4e19-ac36-3167a3ea6403",
},
}


def _load_app_model(app_id: str) -> App | None:
_, current_tenant_id = current_account_with_tenant()
account, current_tenant_id = current_account_with_tenant()
allowed_app_ids = ACCOUNT_VISIBLE_APP_IDS.get(account.id)
if allowed_app_ids is not None and app_id not in allowed_app_ids:
return None

app_model = (
db.session.query(App)
.where(App.id == app_id, App.tenant_id == current_tenant_id, App.status == "normal")
Expand Down
17 changes: 16 additions & 1 deletion api/controllers/console/explore/installed_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ class InstalledAppsListQuery(BaseModel):
installed_app_list_model = get_or_create_model("InstalledAppList", installed_app_list_fields_copy)


ACCOUNT_VISIBLE_APP_IDS = {
# T1000 test account: t1000-twoapps@test.local
"d7eda734-576a-4354-a08a-776dfac2b50d": {
"60629616-8821-48c6-aedc-18f6b3e8d24e",
"cda60867-051d-4e19-ac36-3167a3ea6403",
},
}


@console_ns.route("/installed-apps")
class InstalledAppsListApi(Resource):
@login_required
Expand All @@ -53,16 +62,22 @@ class InstalledAppsListApi(Resource):
def get(self):
query = InstalledAppsListQuery.model_validate(request.args.to_dict())
current_user, current_tenant_id = current_account_with_tenant()
allowed_app_ids = ACCOUNT_VISIBLE_APP_IDS.get(current_user.id)

if query.app_id:
if allowed_app_ids is not None and query.app_id not in allowed_app_ids:
return {"installed_apps": []}
installed_apps = db.session.scalars(
select(InstalledApp).where(
and_(InstalledApp.tenant_id == current_tenant_id, InstalledApp.app_id == query.app_id)
)
).all()
else:
filters = [InstalledApp.tenant_id == current_tenant_id]
if allowed_app_ids is not None:
filters.append(InstalledApp.app_id.in_(allowed_app_ids))
installed_apps = db.session.scalars(
select(InstalledApp).where(InstalledApp.tenant_id == current_tenant_id)
select(InstalledApp).where(*filters)
).all()

if current_user.current_tenant is None:
Expand Down
17 changes: 17 additions & 0 deletions api/services/app_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@
logger = logging.getLogger(__name__)


ACCOUNT_VISIBLE_APP_IDS = {
# T1000 test account: t1000-editor@test.local
"8f6f424f-5435-4786-870b-2dc31674f05d": {
"60629616-8821-48c6-aedc-18f6b3e8d24e",
"cda60867-051d-4e19-ac36-3167a3ea6403",
},
# T1000 test account: t1000-twoapps@test.local
"d7eda734-576a-4354-a08a-776dfac2b50d": {
"60629616-8821-48c6-aedc-18f6b3e8d24e",
"cda60867-051d-4e19-ac36-3167a3ea6403",
},
}


class AppService:
def get_paginate_apps(self, user_id: str, tenant_id: str, args: dict) -> Pagination | None:
"""
Expand All @@ -42,6 +56,9 @@ def get_paginate_apps(self, user_id: str, tenant_id: str, args: dict) -> Paginat
:return:
"""
filters = [App.tenant_id == tenant_id, App.is_universal == False]
allowed_app_ids = ACCOUNT_VISIBLE_APP_IDS.get(user_id)
if allowed_app_ids is not None:
filters.append(App.id.in_(allowed_app_ids))

# start Extend: App Center - Recommended list sorted by usage frequency
rows = db.session.execute(
Expand Down
17 changes: 16 additions & 1 deletion api/services/recommended_app_service_extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
from services.account_service_extend import TenantExtendService


ACCOUNT_VISIBLE_APP_IDS = {
# T1000 test account: t1000-twoapps@test.local
"d7eda734-576a-4354-a08a-776dfac2b50d": {
"60629616-8821-48c6-aedc-18f6b3e8d24e",
"cda60867-051d-4e19-ac36-3167a3ea6403",
},
}


class RecommendedAppService:
@classmethod
def installed_app_list(cls, tenant_id: str) -> dict:
Expand All @@ -29,6 +38,10 @@ def installed_app_list(cls, tenant_id: str) -> dict:
recommended_apps_result = []

for app in apps:
allowed_app_ids = ACCOUNT_VISIBLE_APP_IDS.get(current_user.id)
if allowed_app_ids is not None and str(app.id) not in allowed_app_ids:
continue

classList = app.tags
description = app.description
config = app.app_model_config
Expand All @@ -38,7 +51,7 @@ def installed_app_list(cls, tenant_id: str) -> dict:
classList.append(type('Tag', (), {'name': '未分类'})())
# Extend: stop Handle apps without tags
if (
len(description) == 0
not description
and config is not None
and config.pre_prompt is not None
and len(config.pre_prompt) > 0
Expand All @@ -51,6 +64,8 @@ def installed_app_list(cls, tenant_id: str) -> dict:
installed_app: InstalledApp = (
db.session.query(InstalledApp).filter(InstalledApp.app_id == app.id).first()
)
if installed_app is None:
continue
recommended_apps_result.append(
{
"id": installed_app.id,
Expand Down
Loading