Dify 支持 解析 doc

Dify 是一款开源的大语言模型(LLM) 应用开发平台。它融合了后端即服务(Backend as Service)和 LLMOps 的理念,使开发者可以快速搭建生产级的生成式 AI 应用。即使你是非技术人员,也能参与到 AI 应用的定义和数据运营过程中。

  • 约 4 分钟
  • 1,186 字
你可以通过 self-host 方式部署 unstructured API 服务,然后将 Dify 的 UNSTRUCTURED_API_URL 指向该服务,以摆脱依赖外部 API。下面是可行的方案:

📦 1. 拉取官方 Docker 镜像

Unstructured 官方提供了一个名为 unstructured-api 的 repo,支持 Docker 部署 (github.com, github.com)。你可以这样启动:
Bash
git clone https://github.com/Unstructured-IO/unstructured-api.git
cd unstructured-api
docker run -d \
  -p 8000:8000 \
  --name unstructured-api \
  unstructured-io/unstructured-api:latest
这样会启动一个服务监听 0.0.0.0:8000,包含 /general/v0/general 这样的 API 路径。

🔗 2. 在 Dify 中配置

在 docker/.env 中启用和设置 unstructured 服务:
纯文本
COMPOSE_PROFILES=unstructured
ETL_TYPE=Unstructured
UNSTRUCTURED_API_URL=http://unstructured-api:8000/general/v0/general
确保你的 Docker Compose 文件中已经包含了:
YAML
profiles:
  unstructured:
    image: unstructured-io/unstructured-api:latest
    ports:
      - "8000:8000"
    ...
Dify 会在启动时自动注入这个 container,并将 URL 用于 ETL 流程中 (github.com, github.com)。

✅ 3. 验证部署是否生效

  1. 上传一个 .docx 或 .pdf 到 Dify UI;
  2. 检查 unstructured-api 容器日志,看有没有处理调用;
  3. 查看 Dify indexed 文档的结果是否包含抽取内容;
参考 Dify issue 【#9000】中提到的步骤进行确保(github.com)。

🧰 可选:从源码部署

如果需要调试或自定义,可以 Clone 源码仓库:
Bash
git clone https://github.com/Unstructured-IO/unstructured-api.git
cd unstructured-api
docker build -t local-unstructured-api .
docker run -d -p 8000:8000 local-unstructured-api
这对快速迭代或打补丁是很有效的方式。

⚙️ 总结

步骤
内容
1
使用 docker run 拉取并启动 unstructured-api 镜像
2
设置 Dify 的环境变量 UNSTRUCTURED_API_URL 指向服务
3
启动 Dify,并验证文档 ETL 流是否成功

如果你在日志中没看到调用,可能是网络配置(如 Docker 网络不通)或 env 变量未正确加载。可通过访问 http://localhost:8000/health(或其他 health API)进行测试。
如需进一步优化(比如部署到 K8s,或添加 OCR 支持策略、缓存策略),也可以详细展开实现方案。需要帮助随时说!

评论栏

分享你的想法,或参与下面的讨论。

参与讨论

支持 Markdown、代码和图片

撰写评论
正在加载编辑器…

友善交流,让讨论更有价值。

更多留言

加载中…