插件协议

GPTBots Plugin 是可以连接第三方的api,通过 LLM 调用第三方数据和服务的插件。

GPTBots 的插件协议遵循OpenAPI Specification(OAS)格式定义了一种标准的、与语言无关的 HTTP API 接口,允许人类和计算机理解服务的功能。

示例协议

插件协议字段指南
// Some code
{
  "openapi": "3.0.0",
  "servers": [
    {
      "url": "请求的域名,必须是URL地址格式,如:https://restapi.amap.com"
    }
  ],
  "paths": {
    "/api/custom/path": {
      "get": {
        "operationId": "【必须】接口名称,名称可由英文和下划线组成,禁止使用空格。如:getAdCode、get_Ad_Code"
        "description": "【必须】清晰描述接口功能,由LLM 判断调用该接口时机,描述文案长度限制为 200 个字符长度。"
        "parameters": [
          {
            "name": "【必须】参数字段名称,如:key",
            "in": "【必须】参数位置,支持:path(路径参数)/query(追加在url地址之后的参数)/header(请求中使用的自定义请求头)/cookie(特定的cookie值)",
            "description":"【必须】清晰描述参数含义,描述文案长度限制为 200 个字符长度。"
            "required": true,
            "schema": {
              "type": "字段类型,支持:integer/number/string/boolean",
              "default": "参数的默认值,如:e1a791daabb6b8d2bc8cb22633e37"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "响应的描述",
            "content": {
              "*/*": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Authentication failed"
          }
        }
      }
    },
    "post": {
        "operationId": "【必须】接口名称,名称可由英文和下划线组成,禁止使用空格。如:createUser、create_User"    
        "description":"【必须】清晰描述接口功能,由LLM 判断调用该接口时机,描述文案长度限制为 200 个字符长度。"
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/User"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "引用,例如:#/components/schemas/User"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          }
        }
      }
    ,
  "components": {
    "schemas": {
      "User": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          }
        },
        "required": ["name", "email"]
      }
    }
  }
  }
}

天气插件示例
// Some code
{
  "openapi": "3.0.0",
  "servers": [
    {
      "url": "https://restapi.amap.com"
    }
  ],
  "paths": {
    "/v3/geocode/geo": {
      "get": {
        "description": "When weather or location information is available, call this API to obtain the adCode corresponding to the address.",
        "operationId": "getAdCode",
        "parameters": [
          {
            "name": "key",
            "in": "query",
            "description": "The key used for API authentication (default value: your_key)",
            "required": true,
            "schema": {
              "type": "string",
              "default": "your_key"
            }
          },
          {
            "name": "address",
            "in": "query",
            "description": "Address",
            "required": true,
            "schema": {
              "type": "string",
              "default": "北京"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "*/*": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Authentication failed"
          }
        }
      }
    },
    "/v3/weather/weatherInfo": {
      "get": {
        "description": "When an adCode is obtained, use the adCode to query the weather.",
        "operationId": "queryWeather",
        "parameters": [
          {
            "name": "key",
            "in": "query",
            "description": "The key used for API authentication (default value: your_key)",
            "required": true,
            "schema": {
              "type": "string",
              "default": "your_key"
            }
          },
          {
            "name": "city",
            "in": "query",
            "description": "The adCode obtained from the previous request",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "extensions",
            "in": "query",
            "description": "Default value: all",
            "required": true,
            "schema": {
              "type": "string",
              "default": "all"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "*/*": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Authentication failed"
          }
        }
      }
    }
  }
}

字段规则

字段属性规则说明

operationId

必填

接口名称,名称可由英文和下划线组成,禁止有空格。如:getAdCode、get_Ad_Code

description(接口)

必填

清晰描述接口功能,由LLM 判断调用该接口时机,描述文案长度限制为 200 个字符长度

parameters - name

必填

参数字段名称,如:key",

parameters - in

必填

参数位置,支持:path(路径参数)/query(追加在url地址之后的参数)/header(请求中使用的自定义请求头)/cookie(特定的cookie值)",

parameters -description

必填

清晰描述参数含义,描述文案长度限制为 200 个字符长度

parameters -type

必填

字段类型,支持:integer/number/string/boolean

插件开发规范指南

  • 一个插件允许包含最多 5个 API 接口,GPTBots推荐插件应该配置尽可能少的 API 接口。

  • 开发者不要试图通过 description 控制 LLM 的情绪、个性、或者确切回应。

  • 当用户的问题与插件提供的特地服务无关时,descriptions字段不应鼓励 LLM 使用插件。

  • 不要为插件设定触发特定的触发条件。

  • 除非有必要,否则插件API响应应返回原始数据,而不是自然语言响应。 LLM 将使用返回的数据提供自己的自然语言响应。

Last updated