Giter Club home page Giter Club logo

chatgpt_plugins's Introduction

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

chatgpt_plugins's People

Contributors

abhinav-upadhyay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

chatgpt_plugins's Issues

I hope to convert minutes into crontab format in prompt

def get_description(self) -> str:
return """
Perform targeted push for a given query. If the app version has not been upgraded, push will be performed. If it includes "push every n minutes" and continuous push "n hours", you need to use celery scheduled tasks.
django_celery_beat scheduled task configuration:
minute, hour, day_of_week, day_of_month, month_of_year, timezone
/1,,,,,Asia/Shanghai
Please tell me what tasks you want to perform, and how often and for how long. For example, you can say:
1. "Devices with the mdm device app version number 2.0.14 perform targeted push, once every 15 minutes, and push continuously for 3 hours."
Please note that you need to provide the frequency of execution of the task (for example, every 10 minutes) and the duration (for example, 2 consecutive hours). You can also provide a start time for the task (e.g. 20:00 tonight or 8:00 tomorrow morning).
When you say "every 10 minutes", I would convert the minutes to Crontab format (e.g., "
/10"). Execute the converted crontab format minutes and hours transfer function.
"""

I hope to convert minutes into crontab format in prompt, so that the plug-in can pass params to execute when executing, but minutes is still 10 minutes, not */10. Please tell me what went wrong, thank you.
parameters = {
"type": "object",
"properties": {
"minutes": {
"type": "integer",
"description": "Execute the task every how many minutes",
},
"hours": {
"type": "integer",
"description": "How many hours the task has been executed continuously",
"default": 1
}
}
}
return parameters

 def execute(self, **kwargs) -> Dict:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.