Dify自定义工具例子

1.天气(JSON)

{
      "openapi": "3.1.0",
      "info": {
        "title": "Get weather data",
        "description": "Retrieves current weather data for a location.",
        "version": "v1.0.0"
      },
      "servers": [
        {
          "url": "https://weather.example.com"
        }
      ],
      "paths": {
        "/location": {
          "get": {
            "description": "Get temperature for a specific location",
            "operationId": "GetCurrentWeather",
            "parameters": [
              {
                "name": "location",
                "in": "query",
                "description": "The city and state to retrieve the weather for",
                "required": true,
                "schema": {
                  "type": "string"
                }
              }
            ],
            "deprecated": false
          }
        }
      },
      "components": {
        "schemas": {}
      }
    }

这段代码是一个OpenAPI规范的JSON文件,用于描述一个获取天气数据的API。总的来说,这个API允许用户查询特定位置的天气数据。

  • "openapi": "3.1.0":这表示使用的OpenAPI规范的版本是3.1.0。

  • "info":这部分提供了API的基本信息,包括标题、描述和版本。

  • "servers":这部分列出了API的服务器URL。

  • "paths":这部分定义了API的路径和操作。在这个例子中,有一个GET操作,路径是/location,用于获取特定位置的天气。这个操作需要一个名为location的查询参数,这个参数是必需的,类型是字符串。

  • "components":这部分用于定义API中使用的模式,但在这个例子中,它是空的。

在OpenAPI规范中,parameters是一个数组,用于定义API操作的输入参数。parameters定义了一个名为location的查询参数,这个参数是必需的,类型是字符串。每个参数都是一个对象,包含以下属性:

  • "name":参数的名称。

  • "in":参数的位置。可以是"query", "header", "path""cookie"

  • "description":参数的描述。

  • "required":如果为true,则此参数是必需的。

  • "schema":参数的数据类型。

重点介绍下参数的位置,4种情况如下所示:

  • header参数,用于在请求头中传递API密钥。

  • path参数,用于在URL路径中指定要检索的对象的ID。

  • cookie参数,用于在cookie中传递用户的会话ID。

  • query参数,附加在URL后面的参数,通常用于提供信息过滤。

创建自定义工具界面:

测试工具接口界面:

2.宠物商店(YAML)

# Taken from https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore.yaml

    openapi: "3.0.0"
    info:
      version: 1.0.0
      title: Swagger Petstore
      license:
        name: MIT
    servers:
      - url: https://petstore.swagger.io/v1
    paths:
      /pets:
        get:
          summary: List all pets
          operationId: listPets
          tags:
            - pets
          parameters:
            - name: limit
              in: query
              description: How many items to return at one time (max 100)
              required: false
              schema:
                type: integer
                maximum: 100
                format: int32
          responses:
            '200':
              description: A paged array of pets
              headers:
                x-next:
                  description: A link to the next page of responses
                  schema:
                    type: string
              content:
                application/json:    
                  schema:
                    $ref: "#/components/schemas/Pets"
            default:
              description: unexpected error
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Error"
        post:
          summary: Create a pet
          operationId: createPets
          tags:
            - pets
          responses:
            '201':
              description: Null response
            default:
              description: unexpected error
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Error"
      /pets/{petId}:
        get:
          summary: Info for a specific pet
          operationId: showPetById
          tags:
            - pets
          parameters:
            - name: petId
              in: path
              required: true
              description: The id of the pet to retrieve
              schema:
                type: string
          responses:
            '200':
              description: Expected response to a valid request
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Pet"
            default:
              description: unexpected error
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Error"
    components:
      schemas:
        Pet:
          type: object
          required:
            - id
            - name
          properties:
            id:
              type: integer
              format: int64
            name:
              type: string
            tag:
              type: string
        Pets:
          type: array
          maxItems: 100
          items:
            $ref: "#/components/schemas/Pet"
        Error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: integer
              format: int32
            message:
              type: string

pet.yaml 是一个 OpenAPI 规范文件,用于描述和定义一个名为 “Swagger Petstore” 的 API 的接口。这个文件使用了 YAML 格式,它是一种用于编写配置文件的人类可读的数据序列化标准。这个文件为开发者提供了一个清晰的 API 接口定义,使得开发者可以知道如何与 “Swagger Petstore” API 进行交互。文件中的主要部分包括:

  • openapi: 这个字段指定了使用的 OpenAPI 规范的版本,这里是 “3.0.0”。

  • info: 这个部分提供了 API 的基本信息,包括版本、标题和许可证。

  • servers: 这个部分定义了 API 的服务器 URL。

  • paths: 这个部分定义了 API 的所有路径和操作。例如,/pets 路径有两个操作:getpostget 操作用于列出所有宠物,post 操作用于创建一个新的宠物。每个操作都有自己的参数、响应和其他详细信息。

  • components: 这个部分定义了可重用的模式(schemas),这些模式可以在 paths 部分中引用。例如,PetPetsError 模式。

将上述YAML文件转换为JSON格式:

{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Swagger Petstore",
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "https://petstore.swagger.io/v1"
    }
  ],
  "paths": {
    "/pets": {
      "get": {
        "summary": "List all pets",
        "operationId": "listPets",
        "tags": ["pets"],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "How many items to return at one time (max 100)",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 100,
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A paged array of pets",
            "headers": {
              "x-next": {
                "description": "A link to the next page of responses",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pets"
                }
              }
            }
          },
          "default": {
            "description": "unexpected error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a pet",
        "operationId": "createPets",
        "tags": ["pets"],
        "responses": {
          "201": {
            "description": "Null response"
          },
          "default": {
            "description": "unexpected error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/pets/{petId}": {
      "get": {
        "summary": "Info for a specific pet",
        "operationId": "showPetById",
        "tags": ["pets"],
        "parameters": [
          {
            "name": "petId",
            "in": "path",
            "required": true,
            "description": "The id of the pet to retrieve",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Expected response to a valid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pet"
                }
              }
            }
          },
          "default": {
            "description": "unexpected error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Pet": {
        "type": "object",
        "required": ["id", "name"],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "name": {
            "type": "string"
          },
          "tag": {
            "type": "string"
          }
        }
      },
      "Pets": {
        "type": "array",
        "maxItems": 100,
        "items": {
          "$ref": "#/components/schemas/Pet"
        }
      },
      "Error": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "integer",
            "format": "int32"
          },
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}

3.空白模板

{
      "openapi": "3.1.0",
      "info": {
        "title": "Untitled",
        "description": "Your OpenAPI specification",
        "version": "v1.0.0"
      },
      "servers": [
        {
          "url": ""
        }
      ],
      "paths": {},
      "components": {
        "schemas": {}
      }
    }

注解:貌似JSON格式看上去更加直观。

参考文献

[1] OpenAPI Specification:https://swagger.io/specification/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/765585.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

linux和mysql基础指令

Linux中nano和vim读可以打开记事文件。 ifdown ens33 ifup ens33 关闭,开启网络 rm -r lesson1 gcc -o code1 code1.c 编译c语言代码 ./code1 执行c语言代码 rm -r dir 删除文件夹 mysql> show databases-> ^C mysql> show databases; -------…

鸿蒙开发设备管理:【@ohos.multimodalInput.touchEvent (触摸输入事件)】

触摸输入事件 设备上报的触屏事件。 说明: 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 导入模块 import {Action,ToolType,SourceType,Touch,TouchEvent} from ohos.multimodalInput.touchEvent;…

Android高级面试_8_热修补插件化等

Android 高级面试:插件化和热修复相关 1、dex 和 class 文件结构 class 是 JVM 可以执行的文件类型,由 javac 编译生成;dex 是 DVM 执行的文件类型,由 dx 编译生成。 class 文件结构的特点: 是一种 8 位二进制字节…

Linux指定文件权限的两种方式-符号与八进制数方式示例

一、指定文件权限可用的两种方式: 对于八进制数指定的方式,文件权限字符代表的有效位设为‘1’,即“rw-”、“rw-”、“r--”,以二进制表示为“110”、“110”、“100”,再转换为八进制6、6、4,所以777代表…

Log4j日志框架讲解(全面,详细)

Log4j概述 Log4j是Apache下的一款开源的日志框架,通过在项目中使用 Log4J,我们可以控制日志信息输出到控制台、文件、甚至是数据库中。我们可以控制每一条日志的输出格式,通过定义日志的输出级别,可以 更灵活的控制日志的输出过程…

pycharm中新建的临时python文件存放在哪里?

在pycharm中建立的临时python文件,从哪里可以找到呢? 1.我们打开cmd窗口,进入根目录,用dos命令“dir scratch*.py/a/s”进行查找,发现这些临时文件存放在Roaming\JetBrains\PyCharmCE2022.2\scratches 的目录里面 2.…

【SkiaSharp绘图14】SKCanvas方法详解(三)URL注释、按顶点绘制、 是否裁切区域之外、旋转、缩放、倾斜、平移、保存/恢复画布

文章目录 SKCanvas方法DrawUrlAnnotation 绘制URL注释DrawVertices 按顶点绘制Flush 立即绘制QuickReject 判断区域是否在裁切区域之外ResetMatrix重置矩阵Restore、RestoreToCountRotateDegrees按角度旋转画布RotateRadians按弧度旋转画布SaveLayer保存并新建图层Scale 缩放画…

海南云亿商务咨询有限公司抖店开店服务怎么样?

在数字化浪潮汹涌的当下,电商行业正以前所未有的速度发展,而抖音电商作为其中的佼佼者,更是吸引了无数企业和创业者的目光。海南云亿商务咨询有限公司,作为抖音电商服务的佼佼者,凭借专业的团队和丰富的经验&#xff0…

浙江建筑安全员A证2024年最新考试题库练习

46.总承包单位依法将建设工程分包给其他单位的,分包合同中应当明确各自的安全生产方面的权利、义务。总承包单位对分包工程的安全生产承担()责任。 A.全部 B.主要 C.部分 D.连带 答案:D 47.实施总承报的建设工程发生事故&…

百事可乐推出具有视频屏幕和人工智能技术的智能罐头

在最近于法国戛纳举行的国际创意节上,百事公司推出了创新的智能罐头。这些罐头不同于传统产品,它们采用了环绕式3D屏幕,能够展示高清视频内容,为品牌宣传和促销带来了全新的视角。经过两年多的精心研发,这些智能罐成为…

github仓库的基本使用-创建、上传文件、删除

1.第一步 先点击左侧菜单栏的远程仓库 2.点击NEW 3.创建仓库 然后点击右下角的 CREATE 4.点击code 点击SSH,然后我出现了You don’t have any public SSH keys in your GitHub account. You can add a new public key, or try cloning this repository via HTTPS. 1&#xff…

《大海》这歌为何经久不衰?你看歌词写的多美妙!

《大海》这歌为何经久不衰?你看歌词写的多美妙! 《大海》是一首由陈大力作词,陈大力、陈秀男作曲,Ricky Ho编曲,张雨生演唱的国语流行歌曲。该曲收录在张雨生1992年11月30日由飞碟唱片发行的同名专辑《大海》中。 作为…

Python特征工程 — 1.2 特征分箱

目录 1 什么是特征分箱 2 分箱的重要性及其优势 3 有监督分箱 3.1卡方分箱原理 3.2 决策树分箱 4 无监督分箱 4.1 等距分箱 4.2 等频分箱 4.3 分位数分箱 实验数据:链接:https://pan.baidu.com/s/1yT1ct_ZM5uFLgcYsaBxnHg?pwdczum 提取码&…

CM-UNet: Hybrid CNN-Mamba UNet for Remote Sensing Image Semantic Segmentation

论文:CM-UNet: Hybrid :CNN-Mamba UNet for Remote Sensing Image Semantic Segmentation 代码:https://github.com/XiaoBuL/CM-UNet Abstrcat: 由于大规模图像尺寸和对象变化,当前基于 CNN 和 Transformer 的遥感图像语义分割方…

TongRDS2214手动部署版指引(by lqw+sy)

文章目录 前言准备工作单机版集群版哨兵版多个中心节点配置 前言 由于一些特殊原因(例如服务器没有联网,没有办法直接更新和下载unzip指令,从而导致控制台版本安装节点之后,会报file not found的错误,或者使用不了rds…

【Flutter】列表流畅性优化

前言 在日常APP的开发中,列表是使用频率最高的,这里讲述在Flutter中优化列表的滑动速度与流畅度,以来提高用户的体验。 方案 1、使用ListView.builder代替ListView ListView.builder在创建列表的时候要比ListView更高效,因为L…

Pyramid 中混合认证策略

1. 问题背景 在一个使用 Pyramid 框架开发的应用程序中,需要同时处理 HTML 内容的显示和 JSON API 的请求。对于 HTML 内容,使用了 AuthTktAuthenticationPolicy 进行身份验证和 ACLAuthorizationPolicy 进行授权。当用户成功登录后,会在浏览…

sql拉链表

1、定义:维护历史状态以及最新数据的一种表 2、使用场景 1、有一些表的数据量很大,比如一张用户表,大约1亿条记录,50个字段,这种表 2.表中的部分字段会被update更新操作,如用户联系方式,产品的…

【哈尔滨二级等保测评需要测哪些指标】

为了保证系统的安全性、稳定性和遵从性,哈尔滨二级等保评估要求对评估指标进行全面的评估。下面就是对哈尔滨等保二级考核所需要的考核指标的具体说明,并按各个维度分点表达与总结: 一、物理安全要求 物理安全是信息系统的根本,…

kubeadm kubectl kubelet区别

kubeadm kubeadm 是一个方便易用的 Kubernetes 工具,能够部署生产级别的 Kubernetes 集群kubeadm 还具有了和 minikube 一样的易用性,只要很少的几条命令,如 init、join、upgrade、reset 就能够完成 Kubernetes 集群的管理维护工作&#xff…