简单实现一个ChatGPT Plugin( 二 )

result = {}result['title'] = conf['title']result['year'] = conf['year']result['link'] = conf['link']result['place'] = conf['place']result['sub'] = conf['sub']result['deadline'] = conf['deadline']results.append(result)responses = json.dumps(results)return responsesif __name__ == '__main__':app.run(debug=True, host='0.0.0.0', port=5023)
我们在def ()搞来最近的会议数据 。
在@app.get("/all")里确定了Api的 。访问该,也即:5023/all,将返回一个list的信息 。
其他需要注意的是:
我们需要CORS来允许访问我们的 。
@app.get("/logo.png"): 一个logo文件 。
@app.get("/.well-known/ai-.json"): 文件 。
@app.get("/.yaml"): api说明文件 。
这里我们为我们的插件精心挑选一个清心寡欲的logo,像极了写论文时的我:

简单实现一个ChatGPT Plugin

文章插图
.yaml
该文件是标准的格式的文档,目的是告诉GPT我们的提供了哪些,该如何调用这些,和的输出形式是什么 。
分开来讲:首先是插件基本信息的插件的url地址 。
openapi: 3.0.1info:title: AI Conferencesdescription: Plugin to get information about upcoming AI conferences.version: 'v1'servers:- url: http://localhost:5023
:/all,也即访问:5023/all 的方法和结果 。我们这里,我们告诉GPT使用get与服务器交流 。则告诉GPT这个是干啥的用的 。
paths:/all:get:operationId: getAllUpcomingConfsummary: Get information about all the upcoming conferencesresponses:"200":description: OKcontent:application/json:schema:$ref: '#/components/schemas/getAllUpcomingConfResponses'
格式:这里告诉GPT该怎么解读返回的结果 。
components:schemas: getAllUpcomingConfResponses:type: arrayitems:type: objectproperties:link:type: stringdescription: The link to the conference website.place:type: stringdescription: The place where the conference will be held.sub:type: stringdescription: The subfield of AI that the conference is about.deadline:type: stringdescription: The deadline for submitting papers.
放在一起有:
openapi: 3.0.1info:title: AI Conferencesdescription: Plugin to get information about upcoming AI conferences.version: 'v1'servers:- url: http://localhost:5023paths:/all:get:operationId: getAllUpcomingConfsummary: Get information about all the upcoming conferencesresponses:"200":description: OKcontent:application/json:schema:$ref: '#/components/schemas/getAllUpcomingConfResponses'components:schemas: getAllUpcomingConfResponses:type: arrayitems:type: objectproperties:link:type: stringdescription: The link to the conference website.place:type: stringdescription: The place where the conference will be held.sub:type: string