Skip to content

Code for the article showing how to use the function call feature of OpenAI's chat APIs to create ChatGPT plugins

License

Notifications You must be signed in to change notification settings

codeplusme/chatgpt_plugins

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creating ChatGPT Plugins using the Function Call Feature

The introduction of the function call features in the chat completions API of OpenAI opens up the possibilities of implmenting plugins similar to the plugins supported in ChatGPT. However, OpenAI documentation does not show how this can be done. I took the opportunity to try to do this myself by building a chat application powered by GPT and then using the function call feature to design and implment plugins.

Write-Ups

Structure of a Plugin

Creating a plugin in this system requires doing two things.

  • Extend the PluginInterface class, which defines the API that a plugin should follow
  • Implement the 4 API methods expected by a plugin. These are:
    • get_name: Returns the name of the plugin
    • get_description: Provides a description of what the plugin does
    • get_parameters: Gives a JSON specification of the parameters of the plugin.
    • execute: This is the meat of the plugin, where it receives the parameters as declared by it in the get_parameters method and it executes its function.

Implemented Plugins

Setup Requirements for Running This Locally

Install following Python packages in a virtual environment:

pip install openai --upgrade
pip install flask requests python-dotenv

Create an OpenAI API Key

OPEN_AI_KEY="<your api key here>"

Create Brave Search API Key

This is required for the web search/browser plugin. For this, you need to create an account with Brave at: https://brave.com/search/api/. Next, you need to create an API key from Brave. You can select the Free plan to start with. The free plan allows 2000 requests per month. Once you have generated the key, put this also in the .env file as shown below:

BRAVE_API_KEY="<your Brave API key>"

Generating a key for Flask

Flask also needs a secret key in order to create a user session. You can use something like uuid to generate the key. For example:

import uuid
print(str(uuid.uuid4()))

Put the generated value from the above code in the .env, as shown below:

CHAT_APP_SECRET_KEY="<your secret key>"

Running the Application

Use the following command to run the application:

flask --app run.py run

Demo

Following is the web search plugin in action: Web search plugin in action

About

Code for the article showing how to use the function call feature of OpenAI's chat APIs to create ChatGPT plugins

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 60.6%
  • HTML 39.4%