ChatGPT Plugin | The first encounter
I was pleasantly surprised when I checked my email today. I got early developer access to ChatGPT plugin. I could not wait to try out the first use case. It is so simple that it took me less than an hour to install and try it out. Below are the steps that I took to develop the plugin. The purpose of the plugin is to query the wikipedia content to provide answer to a prompt
Step 1: To build plugin, we need access to a platform which can host our plugin as an API. I used https://replit.com/~, it offers a easy way to code and publish your plugin as an API
Step 2: I created a replit python repo and created the below three files in it
a. main.py - This has the code to access wikipedia and then publish it as an API using python flask web framework
from waitress import serve
from flask import Flask, request, send_from_directory
import wikipedia
app = Flask(__name__)
@app.route('/hello', methods=['GET'])
def get_answer():
? subject = request.args.get('subject')
? page_object = wikipedia.page(subject, auto_suggest=False)
? return {"content": page_object.content}
@app.route('/.well-known/ai-plugin.json')
def serve_ai_plugin():
? return send_from_directory('.',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'ai-plugin.json',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?mimetype='application/json')
@app.route('/.well-known/openapi.yaml')
def serve_openapi_yaml():
? return send_from_directory('.', 'openapi.yaml', mimetype='text/yaml')
if __name__ == '__main__':
? serve(app, host="0.0.0.0", port=8080)
b. Creating the openapi.yaml(note it is openapi and not open ai) - This piece has the specification of my APIs. Note the "url: https://wikihow.repl.co" part. This is where repl has published the API
openapi: 3.0.1
info:
? title: Wiki Knowledge Plugin
? description: A plugin that allows the user to get answers from wikipedia.
? version: 'v1'
servers:
? - url: https://wikihow.rajib76.repl.co
paths:
? /hello:
? ? get:
? ? ? operationId: get_answer
? ? ? summary: Get the answer for a subject from wikipedia
? ? ? parameters:
? ? ? ? - name: subject
? ? ? ? ? in: query
? ? ? ? ? description: The name of the subject?
? ? ? ? ? required: true
? ? ? ? ? schema:
? ? ? ? ? ? type: string
? ? ? responses:
? ? ? ? "200":
? ? ? ? ? description: OK
? ? ? ? ? content:
? ? ? ? ? ? application/json:
? ? ? ? ? ? ? schema:
? ? ? ? ? ? ? ? $ref: '#/components/schemas/WikiResponse'
components:
? schemas:
? ? WikiResponse:
? ? ? type: object
? ? ? properties:
? ? ? ? message:
? ? ? ? ? type: string
? ? ? ? ? description: The retrun message
c. ai-plugin.json - This is the component which is used by open ai to understand how to install and later use the plugin upon providing the prompt. Not the use of the sentence "Use keywords 'subject' to prompt the plugin." This is going as the inline arg to my api code. Look at the line "subject = request.args.get('subject')" in main.py
{?
"schema_version": "v1",
? "name_for_human": "Knowledge from Wikipedia",
? "name_for_model": "knowledgefromwiki",
? "description_for_human": "Plugin for information from wikipedia for a particular subject.",
? "description_for_model": "Plugin for information from wikipedia for a particular subject using the latest wiki page content. Answer only if the information can be retrieved from wikipedia.Use keywords 'subject' to prompt the plugin.",
? "auth": {
? ? "type": "none"
? },
? "api": {
? ? "type": "openapi",
? ? "url": "https://wikihow.rajib76.repl.co/.well-known/openapi.yaml",
? ? "is_user_authenticated": false
? },
? "logo_url": "https://wikihow.rajib76.repl.co/logo.png",
? "contact_email": "[email protected]",
? "legal_info_url": "https://www.your-domain.com/legal"
}
After this I am done developing the plugin
领英推荐
Now the deployment is also easy. Go to the ChatGPT console as shown below. Click on Plugin Store
Clicking Plugin store will pop up the below screen
Now click "Develop your own plugin" which will show the below screen. Enter your api location which for me is "https://wikihow.rajib76.repl.co". It will automatically fetch the plugin which you can now install
Now you are ready to test. See below the output of testing
Is not this cool? Stay tuned for more in this space. I plan to go little more deep into this feature and combine future testing with more prompt engineering
Senior Manager - Power Utilities & Renewables
1 年Wow....Congrats Rajib!