Translator | Cui Hao
Reviewer | Chonglou
OpenAI has just announced the ChatGPT plugin - a way to let ChatGPT perform operations on the web. This not only means that ChatGPT can access the Internet and browse the latest content and news, but it can also perform some operations on our behalf, such as buying groceries, booking flights, and more.
The implementation process is very simple:
Plug-in providers use the OpenAPI standard to write API specifications. This is a standard that has been around for a while and is a proponent of API documentation tools like Swagger.
This specification is then compiled into a prompt that explains to ChatGPT how it uses the API to enhance the answer . Imagine a detailed prompt that includes a description of each available endpoint.
Finally, users ask new questions. If ChatGPT needs to get information from the API, it will make the request and add it to the context before answering.
Although this process is documented in the official OpenAI documentation at the time of writing, Access is restricted. Since I haven't gained access yet, I decided to implement my own mechanism based on the above. So, below is my attempt to implement my own ChatGPT plugin mechanism.
solemnly declare: I We can only learn about ChatGPT plug-in through public information, and there is no other channel to learnAdditional information. The # demonstration in this article is to illustrate the concept of implementation, does not represent implementation What it looks like afterwards. Choose an API Specification
I use DummyJSON, a simple API specifically for testing, specifically "get all delegates" Matter" endpoint. I wrote the following YAML file as a specification.
openapi: 3.0.1
info:
title: TODO Plugin
description: A plugin that allows the user to create and manage a TODO list using ChatGPT.
version: 'v1'
servers:
- url: https://dummyjson.com/todos
paths:
/todos:
get:
operationId: getTodos
summary: Get the list of todos
parameters:
- in: query
name: limit
schema:
type: integer
description: Number of todos to return
- in: query
name: skip
schema:
type: integer
description: Number of todos to skip from the beginning of the list
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/getTodosResponse'
components:
schemas:
getTodosResponse:
type: object
properties:
todos:
type: array
items:
type: object
properties:
id:
type: int
todo:
type: string
completed:
type: bool
userId:
type: string
description: The list of todos.
An endpoint has two parameters: "limit" and "skip". Now, I need to change the above
After repeated discussions, we finally got the following results:
我会告诉ChatGPT以特定的语法回应,并告诉它用户将提供响应。这是因为AI模型不会执行任何API调用——它必须将该操作委托给不同的系统。由于我们无法访问ChatGPT的内部组件,于是要求它将HTTP请求委托给用户。只要隐藏对话转换对最终用户不可见就行了,用户甚至感知不到HTTP请求,就万事大吉了。 ChatGPT是一个通过REST API公开的AI模型。向OpenAI模型发出请求只是端到端聊天机器人体验中的一步。这意味着可以设置模型传递的信息,以及向最终用户显示的信息。 为了使用ChatGPT实现虚拟助手的功能,我使用了Bot Framework Composer,这是一种基于UI的工具,允许我们构建对话体验并将其发布到不同的渠道。以下是高级别的解决方案架构: 我用Bot Framework Composer构建了这个虚拟助手,因为它可以快速部署到多个终端用户渠道,且只需要很少的代码。如果您想要复制这个解决方案,您可能还需要考虑使用Power Virtual Agents,尤其是在生产中使用。 以下是对话流程的构建方式: 1. 用户提问 2.ChatGPT用预格式化的消息进行回复: 3.Azure Bot检测到这种格式,并将请求提交给DummyJSON API,而不会牵扯到最终用户。 4.Azure Bot代表用户向ChatGPT发出新请求,以获取响应正文。 5.ChatGPT格式化响应:"这是你的前5个待办事项:..." 6.Azure Bot回复给用户。 One thing caught my attention immediatelyProductCan Stop ItCall other websites or applications by generating code. For this reason, I applied a simple domain name allow list, This ensures that all requestsRequests can only be sent to the DummyJSON API, and only one message can be sent at a time – To ensure the security of message sending. The above is the design plan The overall idea of points. above Skip Some implementation details until the experience is perfect. This is a statistical tool, so expect some trial and error until you find the right hints. But ultimately, this is the conversation I had with the final version of the robot. ChatGPT plugin The implementation of the function is more # than the above quick demonstration ##complex. The purpose of this Demo# is to show how to complete ChatGPT Integration - Trust me, I'm as curious as you are about the process of implementing . This Demo provides ChatGPT with the ability to integrate HTTP Possibilities, I can’t wait to see what the community can #fresh 花. At the same time, we, as users of this ## technology , there is also a sense of responsibility: What would happen if a malicious prompt caused Azure Bot to make a request to an unknown server? What new attack vectors are there now? In the #bot I wrote, a simple whitelist of domain names was applied - as new use cases continue to emerge, is this enough? I also managed to rewrite the API specification in a follow-up tip - are there any risks associated with this? There are many related to AI # Security issues need to be considered, and OpenAI is certainly aware of this. In general, This time The Demo impressed me . ChatGPT’s The possibilities are truly endless and I will definitely be keeping an eye on this feature to see where it comes in in the coming weeks and months development within. I hope to see it in Azure OpenAI soon too! Translator IntroductionCui Hao, 51CTO community editor, senior architect Teacher, has 18 years of experience in software development and architecture, and 10 years of experience in distributed architecture. ##Original title: How ChatGPT Plugins (could) work, Author: MarcoCardosoYou are a virtual assistant that helps users with their questions by relying on
information from HTTP APIs. When the user asks a question, you should determine whether
you need to fetch information from the API to properly answer it. If so, you will
request the user to provide all the parameters you need, and then ask them to run the
request for you. When you are ready to ask for a request, you should specify it using
the following syntax:
<http_request>{
"url": "<request URL>",
"method": "<method>",
"body": {<json request body>},
"headers": {<json request headers>}
}</http_request>
Replace in all the necessary values the user provides during the interaction, and do not
use placeholders. The user will then provide the response body, which you may use to
formulate your answer. You should not respond with code, but rather provide an answer
directly.
The following APIs are available to you:
---
<OpenAPI Specification goes here>
编排
2.<http_request>{
"url": "https://dummyjson.com/todos?limit=5",
"method": "GET",
"body": "",
"headers": {}
}</http_request>
The above is the detailed content of How the ChatGPT plugin works. For more information, please follow other related articles on the PHP Chinese website!