How to

Developing a ChatGPT Plugin: A Comprehensive Guide

Aug 1, 2023

·

Mar 15, 2022

ChatGPT plugins provide a powerful way to extend the capabilities of AI clients by integrating additional functionalities through APIs. In this blog post, we'll guide you through the process of creating a ChatGPT plugin and discuss some potential business use cases. Finally, we'll touch upon how Dify supports the integration of both in-house and third-party plugins for seamless AI application orchestration.

Creating a ChatGPT Plugin

At its core, a ChatGPT plugin is an ai-plugin.json file that describes the plugin's functionality and API information. Here's an example of what the file might look like:

{
  "schema_version": "v1",
  "name_for_human": "TODO Manager",
  "name_for_model": "todo_manager",
  "description_for_human": "Manages your TODOs!",
  "description_for_model": "An app for managing a user's TODOs",
  "api": { "url": "/openapi.json" },
  "auth": { "type": "none" },
  "logo_url": "https://example.com/logo.png",
  "legal_info_url": "http://example.com",
  "contact_email": "hello@example.com"
}

By accessing this JSON file, ChatGPT or other AI clients can learn about the plugin's purpose and functionality, allowing them to integrate the plugin into their toolbox for use when needed. This is similar to Langchain's proxy mode, where both public and private APIs can serve as plugins for AI clients, acting as their eyes and hands.

If you're starting from scratch to create a ChatGPT plugin, such as one that performs a Google Search, you can follow these steps to develop and deploy the plugin to a Serverless platform:

  1. First, choose a specific task for your plugin, such as performing a Google Search using the Google Search API.

  2. Create a new Serverless project using your preferred Serverless framework (e.g., AWS Lambda, Google Cloud Functions, or Azure Functions).

  3. Write the necessary code to handle the Google Search functionality using the Google Search API in your Serverless project. Make sure to handle any necessary authentication, input validation, and error handling.

  4. Create an openapi.json file in your Serverless project to define the API endpoints and data structures required for your plugin. This file should follow the OpenAPI Specification (OAS) standard. You can use online tools like the Swagger Editor or the OpenAPI Generator to help create the openapi.json file.

  5. Deploy your Serverless project to your preferred Serverless platform. After deployment, you will receive a public URL for your project, which can be used to access your plugin's API.

  6. Create the ai-plugin.json file for your plugin, as described in my previous response, and update the api.url field with the public URL obtained from your Serverless platform in step 5.

Here's an example of a simple openapi.json file for the Google Search plugin:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Google Search Plugin",
    "version": "1.0.0"
  },
  "paths": {
    "/search": {
      "get": {
        "summary": "Perform a Google Search",
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "description": "Search query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful search",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "title": {
                        "type": "string"
                      },
                      "link": {
                        "type": "string"
                      },
                      "snippet": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Here's an example of the ai-plugin.json file for the Google Search plugin:

{
  "schema_version": "v1",
  "name_for_human": "Google Search",
  "name_for_model": "google_search",
  "description_for_human": "Perform a Google Search using the Google Search API!",
  "description_for_model": "An app for performing Google Searches using the Google Search API",
  "api": { "url": "https://your-serverless-function-url.com/openapi.json" },
  "auth": { "type": "api_key", "key_name": "google_search_api_key" },
  "logo_url": "https://example.com/google_search_logo.png",
  "legal_info_url": "http://example.com",
  "contact_email": "hello@example.com"
}

By following these steps, you can create a custom ChatGPT plugin that performs Google Searches and deploy it to a Serverless platform for easy integration into AI applications.

Business Use Cases

There are numerous potential business scenarios where ChatGPT plugins can provide valuable functionality. Some examples include:

  1. Customer Support: A plugin that integrates a company's customer support ticket system, allowing AI agents to create, update, and close tickets on behalf of users.

  2. E-commerce: A plugin that connects to an e-commerce platform's API, enabling the AI to assist users with product recommendations, order status updates, and even processing returns.

  3. Project Management: A plugin that integrates with popular project management tools, such as Trello or Asana, allowing the AI to create tasks, update progress, and provide project overviews to team members.

  4. Calendar Management: A plugin that connects to a user's calendar, enabling the AI to schedule appointments, send reminders, and help users manage their time more effectively.

Dify Integration

Dify application orchestration supports the seamless integration of both Dify-produced tools and third-party plugins. To integrate a third-party plugin, developers simply need to provide the JSON file URL, and the plugin will be loaded into the application.

Developing ChatGPT plugins can unlock a wealth of new possibilities for AI-driven applications by extending their capabilities through API integrations. By understanding the structure of a ChatGPT plugin and its potential use cases, developers can harness the power of these plugins to create more sophisticated and powerful AI applications. With Dify support for both in-house and third-party plugins, the process of incorporating these plugins into AI applications has never been easier.

via @dify_ai and @goocarlos