一、开发要点
所谓插件就是提供了一组功能(REST API)的一个后端服务。将服务注册到GPT中后,用户在 GPT 问答界面中的交互时,如果GPT认为是在操作你的插件,GPT会调用你相应的接口。
比如,用户说“帮我记个事,明天早上起床后要刷牙!”,此时GPT发现你提供的插件里有一个接口是这么描述的:“帮用户添加一个待办事项”,那GPT就会调用你的这个接口,并把“明天早上起床后要刷牙!”当参数传给你。
(一)插件清单
Plugin manifest(清单文件)名为“ai-plugin.json”,这相当于是一个注册文件,告诉GPT我们可以提供什么能力、Logo、插件名 等等。
需要放在我们服务器上固定位置,比如:https://gptplugin.guiji.ai/.well-known/ai-plugin.json
文件内容大致如下:
{
"schema_version": "v1",
"name_for_human": "TODO List",
"name_for_model": "todo",
"description_for_human": "Manage your TODO list. You can add, remove and view your TODOs.",
"description_for_model": "Help the user with managing a TODO list. You can add, remove and view your TODOs.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://example.com/openapi.yaml"
},
"logo_url": "https://example.com/logo.png",
"contact_email": "support@example.com",
"legal_info_url": "http://www.example.com/legal"
}
上面文件中比较重要的几字段说明如下:
-
description_for_model: 写给模型看的描述,当用户在问题中提到的内容经GPT判断是在操作插件,GPT将会请求我们的插件服务器。
-
auth.type: GPT服务器与我们服务器的授权方式,以让我们的服务器确认请求是不是来自GPT。官方推荐
service_http
方式,具体不展开。 -
api.url: 插件所能提供的所有接口的描述,包括请求方式、参数描述、响应结构等。
(二)接口描述文件
如上所述,这个文件对所提供的接口一一描述,让GPT知道我们插件的每个接口的功能,包括请求方式、功能描述、参数描述、响应结构等。
openapi: 3.0.1
info:
title: TODO Plugin
description: A plugin that allows the user to create and manage a TODO list using ChatGPT. If you do not know the user's username, ask them first before making queries to the plugin. Otherwise, use the username "global".
version: "v1"
servers:
- url: https://example.com
paths:
/todos/{username}:
get:
operationId: getTodos
summary: Get the list of todos
parameters:
- in: path
name: username
schema:
type: string
required: true
description: The name of the user.
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/getTodosResponse"
components:
schemas:
getTodosResponse:
type: object
properties:
todos:
type: array
items:
type: string
description: The list of todos.
(三)功能开发
- 通过REST API对接,开发语言不限。
- 只有 ChatGPT Plus 用户可以开发和使用插件。
- 所有接口必须同步返回,没有异步反向推送机制,而我们的数字人合成需要时间,这里在业务设计时需要注意。
二、插件发布
- 目前(2023/12/7) OpenAI 已停止新插件的提交,只接受现有插件的更新审核。官方说明
- 停止新插件的提交,只是插件不能上他们的“市场”了,用户依然可以通过手动填服务端地址的方式使用新出的插件。