ChatGPT 101: Introducing Plugins
Photo by cottonbro studio: https://www.pexels.com/photo/a-woman-looking-afar-5473955/

ChatGPT 101: Introducing Plugins

Imagine ChatGPT as a seasoned Ninja-Grandmother who possesses an impressive arsenal of tools and skills, surpassing all expectations. Now imagine what would be if we super-power her up?

This is exactly what the ChatGPT plugins bring to the table. The power of ChatGPT, impressive as it is, becomes exponentially greater, enabling it to access real-time information, perform complex calculations, and interact with a variety of third-party services using Plugins.

It's as if our Ninja-Grandmother can now draw on the power of a constellation of other ninjas, each enhancing her abilities in a unique way.

We will focus on understanding and developing plugins in this article.

OpenAI has released a killer feature just few days back called "function calling" - in my view this is a huge game changer for paving way in building intelligent applications - stay tuned to explore "function calling" in the next set of articles.

Upcoming articles:

  • ChatGPT working with our own organizational data
  • Private GPT with custom data (no ChatGPT)
  • Function calling GPT: We will develop most advanced "function calling" feature (I'd truly think this is a huge game changer)

What are ChatGPT Plugins

ChatGPT plugins are extensions designed to enhance the capabilities of the language model by allowing it to integrate with third party services, access up-to-date information and perform complex calculations and computations. They feed the ChatGPT with fresh data not found in the original training set.

The introduction of these plugins is indeed a smart move on the roadmap! Notable companies like Expedia, FiscalNote, KAYAK, OpenTable, Slack and a few others have developed the first batch of plugins. And all I can say is that the plugins are exploding - and the best part of it is - it is pretty straightforward to develop them.

Currently ChatGPT plugins are only available to Plus subscribers. You can invoke the GPT-4 model and access the Plugins by clicking on the "Plugins" menu item as shown in the image below:

No alt text provided for this image
ChatGPT Plugins

Currently, though we can install as many as we can, only three plugins will be active. We can select these three using the check boxes next to them:

No alt text provided for this image
Enabled plugins and Plugin store

We can install/uninstall as well as develop our own plugins from the plugin store. As you can see in the image below, there are a few plugins available to try out:

No alt text provided for this image
Available plugins

Working with a Plugin

Once you've selected the required plugins, invoking them is a bit "non-intutive". In the sense, you don't need to explicitly ask ChatGPT to use Expedia to find your upcoming holiday. Instead, you can write something like:

We are planning a school trip to get away this Summer for a week to Athens in Greece. We have 20 kids, aged from 16-18 years. We will be travelling from London. Find me some cheap flights and accommodation, please? Provide me the only top two options.

This prompt would initiate the Expedia plugin auto-magically (as your context is real-time-flight-and-accomodation-booking). The Expedia plugin will invoke APIs to get the deals:

No alt text provided for this image
Flight and hotel details

Just as we converse with the agent on the call, we can tweak the query or enhance the input or request for additional information by simply conversing with the ChatGPT.

This is a mind-blowing feature - we now have a Ninja-Granmother who can form alliances, merging her capabilities with the strengths of other powerful entities.

If you haven't had the chance to experience the magic of these plugins, I highly recommend diving in!

Not only will you be in for a delightful surprise, but you'll also encounter a whole new realm of possibilities, bridging the gap between artificial intelligence and the ever-evolving digital landscape.

Developing Plugins

If I have itched your developer hands, good! Fortunately, learning curve for developing plugins isn't that steep. In fact, if you are familiar with any programming language (Python, Java, NodeJS..), you shouldn't take more than half hour to get your plugin developed!

Let's dig in how to get started on developing a simple "Quote" plugin in this article.

Join the Wait List

If you wish to develop plugins, first you need to get access to it - there's a plugin-developer-wait-list that you need to join. Fill up the form and wait for few days. I got mine after two weeks I think. By the way, this "developer access wait list" is different to the one you apply for accessing plugins (that is not development of them but just accessing them in your ChatGPT window).

Components of a plugin

A plugin consists of three components:

  • Main application: The application's entry point class
  • Application's API specification in OpenAPI format: "openapi.yaml"
  • Plugin Manifest: Plugin's metadata in JSON format: "ai-plugin.json"

The main file is the one such as "main.py" or "app.js" that hosts the application logic. The application must be designed as a webapp such that the APIs are exposed on respective endpoints.

The specification of the API endpoints is documented in the "openapi.yaml" file and are carried out in OpenAPI format. This is the document that plugin infrastructure looks at to invoke our APIs.

The final piece is the metadata about the plugin itself - for example: schema version, name and description of the plugin, authentication, api type, logo and other contact information. This declared in "ai-plugin.json" and must be available in ".well-known" folder (note the dot - it's a hidden folder).

As you can see my project has these three components - though the name of the main file is up to us, the other two names are pretty much what Plugin infra expects when we deploy it to a hosting service.

No alt text provided for this image
Components of a plugin


We will go over developing the plugin here in this article. We will look at the deployment and registering as well as productionising the plugin in the next article.

Developing a Quote Plugin in Python

Let's create a simple Quote Plugin - a service that returns a motivational quote by ChatGPT.

The Quote Plugin code is available in my GitHub repo. If you are impatient but wish to look at the code, just clone it and run!

Create a new Python project in any of your favourite IDEs (I'm using Visual Studio for Code) and create a new folder: gpt-quote-plugin and then a main file in the terminal:

mkdir gpt-quote-plugin
cd gpt-quote-plugin
touch main.py        

We use Flask to create a Python Webapp. The "main.py" is the entry point that exposes the required APIs. In our quote plugin, we expect a root "/" endpoint that when invoked returns a quote. It is a GET method:

// We create a Flask App
app = Flask(__name__)

@app.route("/")
def quote():
  // here's where the logic of calling the GPT goes
)        

In addition to the main entry method, we will need to code two mandatory methods that are required by the plugin infra to call our plugin's API spec and meta data:

// we also need to provide mandatory two endpoints

// Return the metadata
@app.route('/.well-known/ai-plugin.json'
def serve_ai_plugin():
  return send_from_directory('./well-known',
                             'ai-plugin.json',
                             mimetype='application/json')

// Return the API spec
@app.route('/openapi.yaml')
def serve_openapi_yaml():
  return send_from_directory('.', 'openapi.yaml', mimetype='text/yaml'))        

We should also provide the webserver's hostname and port:


        


if __name__ == "__main__"
  app.run(host='0.0.0.0', port=81)        

This let's our webapp running on our localhost (127.0.0.1) at port 81.

Our logic of a prompt querying the GPT can be defined in a function and be invoked from our endpoint:

// Invoke our GPT friend
def gpt(prompt):
  response = openai.ChatCompletion.create(
    model = "gpt-3.5-turbo",
    messages=[{"role": "user", "content": prompt}]
  )
  return response.choices[0].message.content:        

The gpt method expects a prompt from the user (in our case, we've hardcoded a prompt) but the main logic is coded in the ChatCompletion's create method. The create method expects the model and the prompt as the content to a message array. That's the heart and soul of our GPT invocation.

We then invoke this method from our root entry point:


@app.route("/")
def quote():
  // invoke the GPT function. We pass in a hard coded prompt
  return gpt("Fetch me an inspirational quote related to comp sciences")
)        

That's it - we developed the main program. We can put it to test by simply running "python3 main.py". The Webserver will be served on your localhost at port 81.

Run the server and hit the URL browser at https://127.0.0.1:81. You should be presented with a quote from ChatGPT:

No alt text provided for this image
Quote Webapp in Action

That's pretty much for this article. We managed to develop a Python based WebApp with plugin scaffolding so far.

In the next article, we will check the next steps in getting this plugin deployed, installed and put to use!

Code is available in?my repo here.

Stay tuned!

OpenAI has released a killer feature called "function calling" - in my view this is a game changer for intelligent applications - stay tuned to explore "function calling" in the next set of articles.

Me @?Medium?||?LinkedIn?||?Twitter?||?GitHub



要查看或添加评论,请登录

社区洞察

其他会员也浏览了