How to create a ChatGPT plugin?

Updated 2 years ago on July 18, 2023

ChatGPT is a highly intelligent autocomplete tool. It accepts instructions or questions in natural language and produces a reasonably high quality textual result.

But there is a catch - ChatGPT's knowledge only extends through September 2021. Thus, as of this writing (June 2023), the model is not aware of any events or data after September 2021.

This is where ChatGPT plugins come to the rescue. These plugins allow ChatGPT to interact with external APIs to access up-to-date information. They can also help ChatGPT perform certain actions, such as running a Zapier task or sending an email.

From the perspective of an API provider (such as Listen Notes, which provides PodcastAPI.com), creating a ChatGPT plugin is similar to creating a user-friendly interface for your AI-enabled API. For ChatGPT enthusiasts, creating their own plugins can greatly expand its usability.

In this tutorial, we will look at a real example of the Listen Notes ChatGPT plugin (already available in the plugin store) to highlight the process of creating a ChatGPT plugin.

This process is easier than you might think. By the end of this article, you should have enough knowledge to use any APIs and create your own ChatGPT plugin.

Try the Listen Notes ChatGPT Plugin and explore its source code on GitHub.

How do ChatGPT plugins work?

For the end user, the process of using the ChatGPT plug-in is quite simple. It is enough to activate the plug-in in the ChatGPT user interface and then enter the prompts.

For developers, this process requires additional effort. You need to provide a hosted ai-plugin.json file using your own domain name. This file contains metadata about the plugin and an OpenAPI specification specifying the available API endpoints that ChatGPT can communicate with.

In essence, the ChatGPT plugin is an intelligent API calling program. The user uses natural language to call these external APIs instead of writing code. All API endpoints, as well as the ai-plugin.json and openapi.json files, must be hosted on the same domain name.

Case Study: How to create a Podcast Discovery ChatGPT plugin using PodcastAPI.com and Cloudflare Pages

Requirements

Our plugin should be able to search for podcasts or episodes based on keywords, languages, countries, audio length, and other factors.

We will be using PodcastAPI.com and Cloudflare Pages to create this ChatGPT plugin.

PodcastAPI.com is a widely used worldwide podcast API that powers thousands of podcast apps/sites. It is a typical RESTful API.

For example, to find podcasts related to the word "startup" in English, you send an API request of the form GET /search?q=startup&type=podcast&language=English. You can easily try out all the Podcast API endpoints using the mockup server and see what the JSON response data looks like on the API documentation page.

Cloudflare Pages is a serverless platform with a generous free quota. It allows you to create dynamic JavaScript web applications and securely send requests to external APIs without exposing API credentials. And because the platform is serverless, you don't have to worry about server provisioning, scalability, or operational issues.

We've had some experience using Cloudflare Pages to build microfeed, a lightweight serverless alternative to WordPress that can be used to host podcasts and media files for free.

How exactly does the plugin work?

The source code for the Listen Notes ChatGPT plugin can be found on GitHub: github.com/ListenNotes/listennotes-chatgpt-plugin.

The plugin, built in JavaScript, is deployed as a web application on the Cloudflare Pages serverless platform. This deployment serves three vital resources under the custom domain name ai.listennotes.com:

  1. The file ai-plugin.json: It can always be found at https://ai.listennotes.com/.well-known/ai-plugin.json. The path to this file is static and should not be changed. Below is the source code for familiarization.
  2. Openapi.json file: This location is determined by the ai-plugin.json file. In our case, it is located at https://ai.listennotes.com/chatgpt-plugin/openapi.json. You can read the source code here.
  3. Proxy API endpoints: For example, https://ai.listennotes.com/api/v2/search_episodes. These are essentially thin wrappers of the real PodcastAPI.com endpoints. The source code of these endpoints can be found here.

So how do these parts work together? Let's delve deeper into this question:

First, ChatGPT identifies the ai-plugin.json file at the fixed path /. well-known/ai-plugin.json. This file contains important metadata about the plugin and tells ChatGPT the location of the openapi.json file. Here's what it looks like:

Second, ChatGPT uses the openapi.json file to understand the available API endpoints and their parameters. This file essentially helps ChatGPT understand how to interact with the API.

Finally, using the description and other metadata specified in the openapi.json file, ChatGPT can translate natural language requests into specific API requests.

For example, a user request like "search startup podcasts in English" is translated by ChatGPT into a GET request GET /search_podcasts?q=startup&language=English.

Securing the keys to the kingdom of God

When working with external APIs, as in our case with PodcastAPI.com, an important task is to keep API keys private. This can be done using indirect communication levels - "All problems in computer science can be solved with one more level of indirect communication." :)

First, the actual API key( in our caseLISTEN_API_KEY ) is provided as an environment variable on Cloudflare pages. This ensures that the API key is never exposed in the source code.

Next, we use the secret( in our caseCNATGPT_SECRET ) for ChatGPT to call the API endpoints of our proxy. When submitting the plugin to ChatGPT, you will be prompted to specify this secret.

After providing the secret, ChatGPT gives a verification token( in our caseCNATGPT_VERIFICATION_TOKEN ), which is placed in the file ai-plugin.json. It is perfectly fine if this verification token is public.

In our case, LISTEN_API_KEY, CHATGPT_SECRET and CHATGPT_VERIFICATION_TOKEN are stored as encrypted environment variables on Cloudflare Pages, making them effectively inaccessible to prying eyes:

How to go through the peer review process?

Before your plugin is hosted in the ChatGPT Plugin store, you can test it through your custom domain (in our case ai.listennotes.com).

When you are ready to submit your plugin for review, you will do so via an Intercom ticket. You'll need to answer a few questions and provide examples of prompts. In our experience, it took about 2 days for a ChatGPT staff member to review the application.

Initially our application was rejected because there were no punctuation marks in the description. We quickly added a period to the description of our ai-plugin.json, resubmitted and received approval within 2 hours. So from submission to approval took about 2 days.

How to adapt the process for other APIs?

If you want to adapt the listennotes-chatgpt-plugin repository to work with other APIs, you will need to make changes in three main areas:

  1. Update the ai-plugin.json file (source code): More information about this can be found at openai.com.
  2. Update openapi.json (source code): This is very important because ChatGPT relies on this OpenAPI specification to determine available proxy endpoints. More information can be found at openai.com.
  3. Update proxy API endpoints (source code) to align with other APIs: You need to update the proxy endpoints running on Cloudflare Pages so that they send API requests to APIs of your choice. You may need to familiarize yourself with how Cloudflare Pages features work.

Once these updates are done, you can deploy the plugin to Cloudflare Pages and then submit it to ChatGPT for review.

Summarizing

While this review is intended to provide useful information, keep in mind that the ChatGPT plugin is in beta and is subject to change.

We hope to update this article as changes occur. The world of artificial intelligence is rapidly evolving, but a solid understanding of these principles will allow you to navigate it.

More Questions

Why is stable diffusion better? Updated 2 years ago

Although DALL-E 2 is the best known in the field of AI image generation, it might make sense to try Stable Diffusion first: it has a free trial, it's cheaper, it's more powerful, and it has wider usage rights. If you get completely sidetracked, you can also use it to develop your own generative AI.

What is the stable diffusion method? Updated 2 years ago

Stable Diffusion is a hidden diffusion model, a type of deep generative artificial neural network. Its code and model weights are published in the public domain, and it can run on most consumer hardware equipped with a modest GPU with at least 8 GB of VRAM.

What is stable diffusion for developers? Updated 2 years ago

The Stable Diffusion model provides the following benefits to developers interested in building applications based on it: Generation of new data: The Stable Diffusion model can be used to generate new data similar to the original training data, which proves useful when creating new images, text, or sounds.

Can anyone make plugins for ChatGPT? Updated 2 years ago

You can create a plugin to solve these problems and still improve usability for everyone, as they can simply install your plugin and use it! The only question that remains is, how do I get access to the exclusive alpha of plugins that OpenAI is hosting and how do I create a plugin for ChatGPT?

What are the best plugins for ChatGPT? Updated 2 years ago

Prompt Perfect. Let's start with Prompt Perfect, one of the best ChatGPT extensions that allows users to write perfect prompts for an artificial intelligence chatbot. OpenTable. One of the best ChatGPT plugins we used was OpenTable for quick and easy restaurant reservations on the go.

How is ChatGPT used in development? Updated 2 years ago

Using ChatGPT for predictive analytics This artificial intelligence language model enables predictive analytics by analyzing large amounts of data and extracting meaningful information from it. The model's ability to understand natural language and generate human-like responses makes it an ideal tool for predicting user or customer behavior.

Let's get in touch!

Please feel free to send us a message through the contact form.

Drop us a line at mailrequest@nosota.com / Give us a call over skypenosota.skype