API integration

How to Create a ChatGPT Plugin for Currency Conversion

ChatGPT plugin creation guide with coding instructions for currency conversion.

Introduction to ChatGPT Plugins

A ChatGPT plugin is an add-on software developed to integrate external applications into ChatGPT's AI chatbot, unlocking capabilities beyond ChatGPT's original scope. These plugins facilitate the interface between the application and ChatGPT's API, connecting other services and tools to a chatbot, enabling a broader range of features and use cases than initially built in.

Getting Started

In order to make your plugin available to ChatGPT, you need to have developer access to ChatGPT plugins, which means you'll also need a ChatGPT Plus subscription. Regardless, you can still develop the plugin and have it ready for whenever you get that access.

In this tutorial, we will ask ChatGPT to help us come up with ideas for a plugin and also write the code for it. Subsequently, we will deploy our app on Replit to make it publicly available for ChatGPT to use.

Step 1: Brainstorming Plugin Ideas

Open ChatGPT in your browser and ask it to come up with ideas for a plugin. For simplicity's sake, we are going to choose the first idea: A Currency Exchange Rate converter that allows users to convert between different currencies. However, feel free to take any of the suggestions and apply the same process to build your own original plugin.

Step 2: Selecting an API

You can now ask ChatGPT to provide a list of APIs that can be used to develop the plugin. We will utilize the Exchange Rates API because it has a free option that suffices for our use case. Sign up for the free plan and save that API KEY for later use.

Step 3: Developing the Plugin

Next, copy the documentation for the Exchange Rates API from the API Layer website and provide it to ChatGPT. This information will assist in writing the necessary endpoints for our plugin. For our purpose, we only need the /convert endpoint information.

Make sure to copy the GET /convert endpoint code in Python (noting that it is initially in Javascript by default). Paste the documentation into ChatGPT and ask it to write a plugin based on this.

You might have to try a few times before obtaining a satisfactory response. Ensure it handles errors and creates a Flask app with the /convert endpoint and all other required endpoints for a fully functional plugin.

Step 4: Setting Up Your Repository on Replit

Now that we have the plugin coded, it's time to create a Replit repository. If you don't have a Replit account, create one and then start a new repository.

Copy the code generated by ChatGPT into a file named main.py in your Replit repository. Open the console tab, go to New Tab -> Secrets, and paste there your Exchange Rates API Key.

Step 5: Configuring the Environment

Modify the code to fetch the API_KEY from the repository's environment. Next, request ChatGPT to create the additional files necessary for the plugin's operation.

Go to the OpenAI plugin documentation, copy the relevant information under the Plugin Manifest section, and ask ChatGPT to write out a manifest file. In your Replit repo, create an ai-plugin.json file and insert the manifest code there.

Step 6: Adding Open API Definition

Repeating the last steps for the Open API definition, go back to the OpenAI section of the ChatGPT plugin documentation, copy the text under the Open API Definition title, and paste it into ChatGPT to request an Open API definition for your plugin.

Then, create an openapi.yaml file in your repository and insert the Open API definition code obtained.

Step 7: Installing Additional Packages and Finalizing Code

Open the main.py file and add any missing imports that were specified. Open a Shell tab in your Replit console and install Waitress. Next, add the required endpoints to serve your manifest and Open API definition files.

Step 8: Running the Application

Your complete main.py file should resemble:

# Complete code here

Hit the Run button on top of your Replit repository, await deployment, and capture the provided Replit URL. This URL should look something like:

https://currency-converter-plugin.< YOUR_REPLIT_USERNAME >.repl.co

Now, in your ai-plugin.json file, paste the full Open API definition path. Get the main URL into your openapi.yaml file, following the same steps.

Step 9: Installing and Testing Your Plugin

Head over to the ChatGPT plugin store, click on "Develop your own plugin," and if prompted, hit the "My manifest is ready" button to provide your app's base URL. Continue with the installation and you should now be set to test your plugin.

Bonus: Integrate Your Plugin with Stable Diffusion

As a little extra, let’s advance our plugin's functionality by also implementing another AI tool, Stable Diffusion. This will generate an image of the conversion we are attempting to make.

We will utilize a Stable Diffusion model hosted on Replicate, so first get your Replicate API TOKEN. Add the TOKEN to your secrets in the Replit repository, and then integrate it into your convert_currency() function to generate images based on the currency conversions.

Conclusion

In this tutorial, we explored how to construct a ChatGPT plugin for currency conversion alongside integrating image generation using Stable Diffusion. Plugins serve to broaden ChatGPT's functionality by allowing it to interface with various external applications and APIs. You are now prepared to create your own plugins or expand upon this one to develop something innovative.

If you have any questions or need further assistance, feel free to connect with me on LinkedIn or Twitter.

Reading next

Cohere Tutorial on Text Classification using Natural Language Processing techniques.
Creating a Virtual Assistant using Google's PaLM2 model tutorial.

Leave a comment

All comments are moderated before being published.

Trang web này được bảo vệ bằng hCaptcha. Ngoài ra, cũng áp dụng Chính sách quyền riêng tưĐiều khoản dịch vụ của hCaptcha.