Dify中的插件生态系统

Dify v1.0.0-beta.1开始,推出全新的Dify市场。Dify中的插件包括几种分类,分别是Models(模型)、Tools(工具)、Agent 策略、Extensions(扩展)、Bundle(插件包)。插件系统还具备更加友好的传播属性,可通过 Dify Marketplace [1]或 GitHub [2]以及本地文件 [3]的形式分享插件,其它开发者能够便捷地安装插件。

一.Dify插件类型

类型解释
Models(模型)各类 AI 模型的接入插件,包含主流模型服务商和自定义模型,支持配置和调用。专注于请求 LLM API 服务。关于模型插件的开发详情,请参考快速开始: Model 类型插件。[4]
Tools(工具)能够被 Chatflow / Workflow / Agent 应用类型所使用的外部工具,提供完整的工具集和 API 实现能力。不仅可以调用各类工具,还能构建自定义端点。例如在开发 Discord Bot 时,既可以使用现有工具,又能实现收发消息的专用端点。关于工具插件的开发详情,请参考快速开始:Tool 类型插件。[5]
Agent 策略Agent 策略插件能够定义 Agent 节点内部的推理和决策逻辑,包括工具选择、调用和结果处理。详细说明请参考快速开始: Agent 策略插件。[6]
Extensions(扩展)仅提供 endpoint 能力,为简单场景设计的轻量级方案,通过 HTTP 服务快速实现功能扩展。适用于只需要基础 API 调用的简单集成场景。关于扩展插件的开发详情,请参考快速开始:Extension 类型插件。[7]
Bundle(插件包)插件包是一系列插件的组合。通过安装插件集可以批量安装预选插件,告别手动逐个安装插件的繁琐过程。关于插件包的开发详情,请参考插件开发:Bundle 类型插件。[8]

二.Dify插件开发

1.快速开发

快速开发解释链接
Tool 插件以 GoogleSearch 工具为例,介绍如何开发工具类插件。https://docs.dify.ai/zh-hans/plugins/quick-start/developing-plugins/tool-type-plugin
Model 插件以 Anthropic 和 Xinference 模型为例,分别介绍如何开发预定义模型和自定义模型插件。https://docs.dify.ai/zh-hans/plugins/quick-start/developing-plugins/model
Agent 策略插件Agent 策略插件能够帮助 LLM 执行推理或决策逻辑,包括工具选择、调用和结果处理,以更加自动化的方式处理问题。https://docs.dify.ai/zh-hans/plugins/quick-start/developing-plugins/agent-strategy
Extension 插件Extension 插件允许开发者将业务代码封装为插件,并自动提供 Endpoint 请求入口,可以被理解为托管在 Dify 平台内的 API 服务。https://docs.dify.ai/zh-hans/plugins/quick-start/developing-plugins/extension
Bundle 插件包Bundle 插件包是多个插件的集合。它可以将多个插件打包在一个插件内,以达到批量安装插件的效果,同时提供更强大的服务。https://docs.dify.ai/zh-hans/plugins/quick-start/developing-plugins/bundle
最佳实践开发SlackBot插件。https://docs.dify.ai/zh-hans/plugins/quick-start/developing-plugins/best-practice/develop-slack-bot

2.接口文档

接口文档链接
通用结构标准定义https://docs.dify.ai/zh-hans/plugins/api-documentation/tong-yong-gui-fan-ding-yi
Manifest 标准定义https://docs.dify.ai/zh-hans/plugins/api-documentation/manifest
工具接入标准定义https://docs.dify.ai/zh-hans/plugins/api-documentation/tool
模型接入简介https://docs.dify.ai/zh-hans/plugins/api-documentation/model
Endpoint 标准定义https://docs.dify.ai/zh-hans/plugins/api-documentation/endpoint
扩展 Agent 策略https://docs.dify.ai/zh-hans/plugins/api-documentation/agent
反向调用 Dify 平台能力-反向调用 Apphttps://docs.dify.ai/zh-hans/plugins/api-documentation/fan-xiang-diao-yong-dify-fu-wu/app
反向调用 Dify 平台能力-反向调用 Modelhttps://docs.dify.ai/zh-hans/plugins/api-documentation/fan-xiang-diao-yong-dify-fu-wu/model
反向调用 Dify 平台能力-反向调用节点 Nodehttps://docs.dify.ai/zh-hans/plugins/api-documentation/fan-xiang-diao-yong-dify-fu-wu/node
反向调用 Dify 平台能力-反向调用工具 Toolhttps://docs.dify.ai/zh-hans/plugins/api-documentation/fan-xiang-diao-yong-dify-fu-wu/tool
插件持久化存储能力https://docs.dify.ai/zh-hans/plugins/api-documentation/chi-jiu-hua-cun-chu

三.Dify插件管理

主要是Dify插件安装、管理和调试的权限设置;升级插件;删除插件[10]。

Dify插件管理解释链接
安装、管理和调试的权限设置安装和管理插件权限,插件调试权限https://docs.dify.ai/zh-hans/plugins/plugins-management#tiao-zheng-cha-jian-quan-xian
升级插件对插件进行升级https://docs.dify.ai/zh-hans/plugins/plugins-management#sheng-ji-cha-jian
删除插件对插件进行删除https://docs.dify.ai/zh-hans/plugins/plugins-management#shan-chu-cha-jian

四.Dify插件接口定义

Dify插件接口定义解释链接
ManifestManifest 是一个符合 yaml 规范的文件,它定义了插件最基础的信息,包括但不限于插件名称、作者、包含的工具、模型等信息。https://docs.dify.ai/zh-hans/plugins/api-documentation/manifest
Endpoint一个 Endpoint 组是多个 Endpoint 的集合,在 Dify 插件内新建 Endpoint 时可能需要填写Endpoint 名字、API Key等信息。https://docs.dify.ai/zh-hans/plugins/api-documentation/endpoint
ToolDify 支持文本 链接 图片 文件BLOB JSON 等多种消息类型,可通过以下不同的接口返回不同类型的消息。https://docs.dify.ai/zh-hans/plugins/api-documentation/tool
AgentAgent 策略是一个定义了标准输入内容与输出格式的可扩展模板。通过开发具体 Agent 策略接口的功能代码,可实现众多不同的 Agent 策略如 CoT(思维链)/ ToT(思维树)/ GoT(思维图)/ BoT(思维骨架),实现一些诸如 Sementic Kernel 的复杂策略。https://docs.dify.ai/zh-hans/plugins/api-documentation/agent
Model模型供应商规则基于 Provider 实体。模型规则基于 AIModelEntity 实体。https://docs.dify.ai/zh-hans/plugins/api-documentation/modelhttps://docs.dify.ai/zh-hans/plugins/api-documentation/model/model-designing-specificationhttps://docs.dify.ai/zh-hans/plugins/api-documentation/model/mo-xing-jie-kou
通用规范定义包括路径规范和通用结构。https://docs.dify.ai/zh-hans/plugins/api-documentation/tong-yong-gui-fan-ding-yi
持久化存储持久化储机制能够让插件具备在相同 Workspace 持久存储数据的能力,目前通过提供 KV 数据库满足存储需求,未来可能会根据实际的使用情况推出更灵活更强大的储存接口。https://docs.dify.ai/zh-hans/plugins/api-documentation/chi-jiu-hua-cun-chu
反向调用 Dify 服务-App插件能够访问 Dify 平台内 App 的数据。https://docs.dify.ai/zh-hans/plugins/api-documentation/fan-xiang-diao-yong-dify-fu-wu/app
反向调用 Dify 服务-Model插件能够反向调用 Dify 平台内的 LLM 能力,包括平台内的所有模型类型与功能,例如 TTS、Rerank 等。https://docs.dify.ai/zh-hans/plugins/api-documentation/fan-xiang-diao-yong-dify-fu-wu/model
反向调用 Dify 服务-Tool插件能够调用 Dify 平台内的其它工具类型插件。https://docs.dify.ai/zh-hans/plugins/api-documentation/fan-xiang-diao-yong-dify-fu-wu/tool
反向调用 Dify 服务-Node插件能够调用 Dify 平台内某个 Chatflow/Workflow 应用内的节点。https://docs.dify.ai/zh-hans/plugins/api-documentation/fan-xiang-diao-yong-dify-fu-wu/node

五.Dify插件发布

Dify提供了3种插件发布方式,分别是Dify市场、GitHub和本地打包发布。如下所示:

发布方式解释链接
Dify MarketplaceDify 官方提供的插件市场,用户可以在此浏览、搜索并一键安装各类插件。https://docs.dify.ai/zh-hans/plugins/publish-plugins/publish-plugin-to-dify-marketplace
个人 GitHub 仓库将插件开源或托管在 GitHub 上,方便他人查看、下载和安装。https://docs.dify.ai/zh-hans/plugins/publish-plugins/publish-plugin-on-personal-github-repo
本地发布与分享将插件打包成本地文件(如 .difypkg 格式),通过文件分享的方式供他人安装。https://docs.dify.ai/zh-hans/plugins/publish-plugins/package-and-publish-plugin-file

参考文献

[1] Dify Marketplace:https://marketplace.dify.ai/

[2] 发布至个人 GitHub 仓库:https://docs.dify.ai/zh-hans/plugins/publish-plugins/publish-plugin-on-personal-github-repo

[3] 打包插件文件并发布:https://docs.dify.ai/zh-hans/plugins/publish-plugins/package-and-publish-plugin-file

[4] Model 插件:https://docs.dify.ai/zh-hans/plugins/developing-plugins/model

[5] Tool 插件:https://docs.dify.ai/zh-hans/plugins/developing-plugins/tool-type-plugin

[6] Agent 策略插件:https://docs.dify.ai/zh-hans/plugins/developing-plugins/agent

[7] Extension 插件:https://docs.dify.ai/zh-hans/plugins/developing-plugins/extension

[8] Bundle 插件包:https://docs.dify.ai/zh-hans/plugins/developing-plugins/bundle

[9] Dify v1.0.0-beta:插件开启公测:https://mp.weixin.qq.com/s/PNjuWj8nIFuyZKwr5W30Rg

[10] 插件管理:https://docs.dify.ai/zh-hans/plugins/plugins-management

[11] Dify中的插件生态系统:https://z0yrmerhgi8.feishu.cn/wiki/ZXIkwEQ3kicfLxkADbfcrl7CnEb

### 如何在 Dify 中进行数据库查询或实现数据库集成 Dify 是一种用于编排复杂工作流的应用框架,尤其适合于构建 Retrieval-Augmented Generation (RAG) 系统。在这种系统中,向量数据库扮演着至关重要的角色[^1]。为了实现在 Dify 中的数据库查询功能以及完成数据库集成,可以考虑以下几个方面: #### 1. **理解 Dify 的数据处理架构** Dify 支持多种外部系统的集成,其中包括向量数据库和其他传统关系型数据库。对于 RAG 应用而言,通常会涉及两种类型的数据库: - 向量数据库:如 Zilliz Cloud,其基于 Milvus 构建,能够高效管理大规模高维向量数据,并提供快速相似度搜索能力[^2]。 - 关系型数据库或其他结构化存储解决方案。 通过配置适配器或者插件机制,可以在 Dify 流程中调用这些数据库的服务接口来执行查询操作。 #### 2. **利用 SDK 或 API 实现数据库连接** 要让 Dify 访问特定的数据库资源,可以通过以下方式之一建立联系: - 如果目标是一个像 Zilliz Cloud 这样的云端托管服务,则可以直接借助官方提供的 RESTful APIs 或者 Python 客户端库发起请求; ```python from pymilvus import connections, Collection # 建立到远程实例的链接 connections.connect("default", uri="https://your-zilliz-cloud-endpoint", token="YOUR_ACCESS_TOKEN") collection_name = "example_collection" col = Collection(name=collection_name) results = col.query(expr="field_name == 'value'") ``` - 对于本地部署的关系型数据库(MySQL/PostgreSQL),则需引入相应的驱动程序并编写 SQL 查询语句; 上述代码片段展示了如何使用 PyMilvus 来访问一个已存在的集合 `example_collection` 并检索满足条件的数据项。 #### 3. **定义自定义节点逻辑** 当需要更复杂的业务场景时,在 Dify 中创建新的节点类型可能是必要的。这允许开发者封装任意计算过程——包括但不限于跨多个表联结、聚合统计分析等高级SQL命令或是针对嵌入式特征空间内的近邻探测算法应用案例研究等等。 例如,假设我们希望开发一个新的动作节点用来定期同步来自第三方 CRM 系统的新客户记录至内部 Elasticsearch 文档索引里去的话,那么就需要明确指定源端点URL地址参数列表及其认证凭证信息等内容之后再提交给调度引擎安排定时任务计划运行即可达成目的。 --- ### 总结说明 综上所述,要在 Dify 中实施有效的数据库交互行为主要依赖两步走策略:一方面确保选用恰当的技术组件作为底层支撑平台以保障整体方案可行性;另一方面则是灵活运用编程技巧定制专属的功能模块从而最大程度发挥整个生态体系的优势价值所在。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NLP工程化

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值