当前位置: 首页 > news >正文

Dify 插件开发笔记

Dify 插件开发

开发流程

选择插件类型
编写清单文件
manifest.yaml
安装依赖
实现插件功能
测试调试
打包发布

开发准备

安装 Dify 插件开发脚手架工具参考

[初始化开发工具 | Dify](https://docs.dify.ai/zh-hans/plugins/quick-start/develop-plugins/initialize-development-tools)

创建项目,选择插件类型

dify-plugin-windows-amd64.exe plugin init

在这里插入图片描述
以Tool工具为例,假如名称为table2json

创建完成后,修改tools目录下table2json.py,实现具体的业务逻辑

在table2json.yaml定义输入参数

parameters:
  - name: tables
    type: files
    required: true
    label:
      en_US: input files
      zh_Hans: 输入文件
      pt_BR: input files
    human_description:
      en_US: convert table to json format
      zh_Hans: convert table to json format
      pt_BR: convert table to json format
    llm_description: convert table to json format
    form: llm

修改代码

import json
from collections.abc import Generator
from typing import Any
from dify_plugin import Tool
from dify_plugin.entities.tool import ToolInvokeMessage
from dify_plugin.file.file import File
import xxx # 与业务相关的包

class Table2jsonTool(Tool):
    def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]:
       # 获取输入参数
        if 'tables' not in tool_parameters or not tool_parameters['tables']:
            yield self.create_text_message("No files provided")
            return

        file_obj: File = tool_parameters['tables'][0]
        print("---1---类型")
        print(file_obj)
       # 具体的业务逻辑
       # 输出格式定义
        yield self.create_json_message({"result": json_str})

安装依赖

自己导入的包,需写入requirements.txt
执行下面的命令

pip install -r requirements.txt

调试

在这里插入图片描述

请添加图片描述

发布

请添加图片描述

相关文章:

  • 古镇网站建设公司网络推广项目计划书
  • 可以做很多个网站然后哭推广2022年网络流行语
  • 域名网站可以做多个品牌产品吗免费推广神器
  • 网站建设程序开发自己在家做电商
  • 做软件销售网站班级优化大师头像
  • 企业自己如何做网站推广比较好的搜索引擎
  • MyBatis深度解析与实战指南:细节完整,从入门到精通
  • Windows下进行Redis for Windows安装
  • Linux服务器——搭建Zabbix
  • 02-redis-数据结构实现原理
  • 移动端六大语言速记:第12部分 - 测试与优化
  • vue-ganttastic在vue3中使用示例
  • CISA关键措施要求解析:提升组织网络安全的实用指南
  • 近两年年化是177.6%,wxpython+backtrader+quantstats的智能投研平台(系统源码+策略下载)
  • LangChain4j(1):初步认识Java 集成 LLM 的技术架构
  • Dart逆向之函数调用
  • AI | 字节跳动 AI 中文IDE编辑器 Trae 初体验
  • java线程安全-单例模式-线程通信
  • Python刷题笔记
  • Laravel 实现 队列 发送邮件功能
  • IP证书的作用与应用:保障数字身份与通信安全
  • Docker MySQL的主从同步 数据备份 数据同步 配置文件
  • C++学习之ORACLE①
  • 基于flask+vue框架的助贫公益募捐管理系统1i6pi(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
  • BUUCTF-web刷题篇(18)
  • Python设计模式-单例模式