Giter VIP home page Giter VIP logo

plugins-quickstart's Introduction

ChatGPT plugins quickstart

Get a TODO list ChatGPT plugin up and running in under 5 minutes using Python. This plugin is designed to work in conjunction with the ChatGPT plugins documentation. Plugins have been superseded by GPTs, learn more about creating a GPT with actions.

Setup locally

To install the required packages for this plugin, run the following command:

pip install -r requirements.txt

To run the plugin, enter the following command:

python main.py

Once the local server is running:

  1. Navigate to https://chat.openai.com.
  2. In the Model drop down, select "Plugins" (note, if you don't see it there, you don't have access yet).
  3. Select "Plugin store"
  4. Select "Develop your own plugin"
  5. Enter in localhost:5003 since this is the URL the server is running on locally, then select "Find manifest file".

The plugin should now be installed and enabled! You can start with a question like "What is on my todo list" and then try adding something to it as well!

Getting help

If you run into issues or have questions building a plugin, please join our Developer community forum.

plugins-quickstart's People

Contributors

joedevon avatar logankilpatrick 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  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  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plugins-quickstart's Issues

Manifest has invalid JSON and prevents plugin from loading

Description

The manifest file contains a trailing comma, so this is a malformed JSON. This creates a CORS error:

Failed to fetch localhost manifest. Check to ensure your localhost is running and your localhost server has CORS enabled.

Proposed fix

Format the JSON to remove this comma on line 12 of ai-plugin.json: "url": "http://localhost:5003/openapi.yaml",

New manifest:

{
    "schema_version": "v1",
    "name_for_human": "TODO Plugin (no auth)",
    "name_for_model": "todo",
    "description_for_human": "Plugin for managing a TODO list, you can add, remove and view your TODOs.",
    "description_for_model": "Plugin for managing a TODO list, you can add, remove and view your TODOs.",
    "auth": {
        "type": "none"
    },
    "api": {
        "type": "openapi",
        "url": "http://localhost:5003/openapi.yaml"
    },
    "logo_url": "http://localhost:5003/logo.png",
    "contact_email": "[email protected]",
    "legal_info_url": "http://example.com/legal"
}

I've attached a PR that resolves this issue. #41

I keep getting an error 'No module named 'quart''

Even when I manually re-install the quart module, I get this error when trying to run python3 main.py....

a********@********* plugins-quickstart % python3 main.py Traceback (most recent call last): File "/*****/plugins-quickstart/main.py", line 3, in <module> import quart ModuleNotFoundError: No module named 'quart'

In windows Ubuntu on WSL - on pip install gives X509 Flag error

pip3 install -r requirements.txt
Traceback (most recent call last):
File "/usr/bin/pip3", line 11, in
load_entry_point('pip==20.0.2', 'console_scripts', 'pip3')()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 490, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2854, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2445, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2451, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in
from pip._internal.cli import cmdoptions
File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 24, in
from pip._internal.exceptions import CommandError
File "/usr/lib/python3/dist-packages/pip/_internal/exceptions.py", line 10, in
from pip._vendor.six import iteritems
File "/usr/lib/python3/dist-packages/pip/_vendor/init.py", line 65, in
vendored("cachecontrol")
File "/usr/lib/python3/dist-packages/pip/_vendor/init.py", line 36, in vendored
import(modulename, globals(), locals(), level=0)
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 655, in _load_unlocked
File "", line 618, in _load_backward_compatible
File "", line 259, in load_module
File "/usr/share/python-wheels/CacheControl-0.12.6-py2.py3-none-any.whl/cachecontrol/init.py", line 9, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 655, in _load_unlocked
File "", line 618, in _load_backward_compatible
File "", line 259, in load_module
File "/usr/share/python-wheels/CacheControl-0.12.6-py2.py3-none-any.whl/cachecontrol/wrapper.py", line 1, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 655, in _load_unlocked
File "", line 618, in _load_backward_compatible
File "", line 259, in load_module
File "/usr/share/python-wheels/CacheControl-0.12.6-py2.py3-none-any.whl/cachecontrol/adapter.py", line 5, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 655, in _load_unlocked
File "", line 618, in _load_backward_compatible
File "", line 259, in load_module
File "/usr/share/python-wheels/requests-2.22.0-py2.py3-none-any.whl/requests/init.py", line 95, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 655, in _load_unlocked
File "", line 618, in _load_backward_compatible
File "", line 259, in load_module
File "/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl/urllib3/contrib/pyopenssl.py", line 46, in
File "/usr/lib/python3/dist-packages/OpenSSL/init.py", line 8, in
from OpenSSL import crypto, SSL
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1553, in
class X509StoreFlags(object):
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'

FastAPI vs quart

I'm wondering what your thoughts are on the tradeoffs between quart and fastapi.

In my understanding, the hardest part of plugin development by far is maintaining the accompanying OpenAPI spec, which is what FastAPI excels at.

It looks like Quart has some support for OpenAPI via quart-openapi, but it's not maintained, and it doesn't have nearly the same developer community as FastAPI.

Def not saying you should be using one or the other; I'd just like to understand the tradeoffs from OpenAI's perspective since I think setting a high quality precedent for how people will start building ChatGPT Pluginsn early is really important.

Thanks! 🙏

"Develop your own plugin" no longer available

Hi,

I am trying to run the plugin locally, following the instructions.

However, the "Develop your own plugin" is not available within the Plugin Store modal.

Is this because of the release of Actions? Is it possible to run this as an Action?

Plugin search bar

I don't know if this is the right place to make this enhancement request since its actually probably more for the web application developers, but with so many plugins coming out it would be great if we could have a type search to help select which plugin you want instead of clicking through the whole list.

redirect_uri mismatch error when I try authenticate with Google

I've set up my plugin on Google Cloud Platform but no matter what values I set in the dashboard or code for the redirect_uri I get the same error

You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy.

If you're the app developer, register the redirect URI in the Google Cloud Console.
Request details: redirect_uri=http://localhost:8080/
image

I originially set the redirect_uri to an ngrok domain, that I pointed at my local port 5003. Then I realized that the flow app was setting the redirect_uri in it's domain as 8080 by default

Does anyone know if there's a particular redirect_uri I should be using to work with Chatgpt based plugins? Here's my code but take it with a pinch of salt with regards the port configurations, as I've tried every variation I can think of to no avail.

import json

import quart
import quart_cors
from quart import request

from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

app = quart_cors.cors(quart.Quart(__name__), allow_origin="https://chat.openai.com")

@app.get("/logo.png")
async def plugin_logo():
    filename = 'logo.png'
    return await quart.send_file(filename, mimetype='image/png')

@app.get("/.well-known/ai-plugin.json")
async def plugin_manifest():
    host = request.headers['Host']
    with open("./.well-known/ai-plugin.json") as f:
        text = f.read()
        return quart.Response(text, mimetype="text/json")

@app.get("/openapi.yaml")
async def openapi_spec():
    host = request.headers['Host']
    with open("openapi.yaml") as f:
        text = f.read()
        return quart.Response(text, mimetype="text/yaml")

# The scope required to modify Google Calendar
SCOPES = ['https://www.googleapis.com/auth/calendar.events']

def authenticate_and_get_service():
    flow = InstalledAppFlow.from_client_secrets_file('client_secrets.json', SCOPES, redirect_uri="http://localhost:8080")

    # This will prompt the user's browser to open a Google login screen
    # After logging in and approving access, the user will be redirected to a local server
    # The server will get the authorization code from the response and continue the flow
    creds = flow.run_local_server()
    
    # With the credentials, we can build the service
    service = build('calendar', 'v3', credentials=creds)
    
    return service

@app.route("/create-calendar-event", methods=['POST'])
async def create_calendar_event():
    # Get the event details from the request
    # event_details = await request.get_json()

    # Authenticate and get the Google Calendar service
    service = authenticate_and_get_service()

    # Now you can use the service object to create a calendar event
    # You will need to implement the create_event function
    # This function should use the Google Calendar API to create an event with the provided details
    # create_event(service, event_details)

    return quart.Response("Event created successfully", status=200)

def main():
    app.run(debug=True, host="0.0.0.0", port=8080)

# Now you can use the service object to interact with the Google Calendar API

if __name__ == "__main__":
    main()

Cannot run the event loop while another loop is running

I am getting this error after 'run main.py' command. Im usgin 'run main.py' instead "python main.py" since in jupyter "python main.py" runs into a syntax error.

"* Serving Quart app 'main'

  • Environment: production
  • Please use an ASGI server (e.g. Hypercorn) directly in production
  • Debug mode: True
  • Running on http://0.0.0.0:5003/ (CTRL + C to quit)
    Cannot run the event loop while another loop is running*
    """"

I do not have developer access yet, should it matter to run this code?

Remotely

Your comment on setting up remotely includes a list of what appears to be hyperlinks to each service like Replit etc, but they're not clickable

JS/TS Plugins Quickstart

Hey Logan & OpenAI devs 👋

I created a similar quickstart for JS/TS developers over here: https://github.com/transitive-bullshit/chatgpt-plugin-ts

I'd love to get feedback from OpenAI on the initiative, and I'd be very open to migrating this project to the OpenAI org at some point if you were open to it.

Happy to chat more synchronously if you'd like; otherwise, feedback via GitHub issues is fine too 😄

Thanks! 🙏

[Bug] Incompatibility issues with Quart and Quart-CORS due to unspecific version requirements

Environment Information:

  • OS: Ubuntu 18.04.6 LTS
  • Python Version: 3.6.9
  • Quart Version: 0.6.15
  • Quart-CORS Version: 0.1.3

Current Situation:

The versions are unspecific, leading to issues with Quart and Quart-CORS APIs when used. For instance:

Traceback (most recent call last):
  File "main.py", line 12, in <module>
    @app.post("/todos/<string:username>")
AttributeError: 'Quart' object has no attribute 'post'

Changing all @app HTTP method calls to this style:

@app.route("/todos/<string:username>", methods=["POST"])

allows successful execution of main.py.

However, it's unable to load the sample project "TODO Plugin (no auth)" at https://chat.openai.com/ and the following error is displayed:

[2023-05-17 15:08:42,918] ERROR in app: Exception on request GET /logo.png
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/quart/app.py", line 1451, in handle_request
    return await self.full_dispatch_request(request_context)
  File "/usr/local/lib/python3.6/dist-packages/quart/app.py", line 1473, in full_dispatch_request
    result = await self.handle_user_exception(error)
  File "/usr/local/lib/python3.6/dist-packages/quart/app.py", line 892, in handle_user_exception
    raise error
  File "/usr/local/lib/python3.6/dist-packages/quart/app.py", line 1471, in full_dispatch_request
    result = await self.dispatch_request(request_context)
  File "/usr/local/lib/python3.6/dist-packages/quart/app.py", line 1519, in dispatch_request
    return await handler(**request_.view_args)
  File "main.py", line 36, in plugin_logo
    return await quart.send_file(filename, mimetype='image/png')
TypeError: send_file() got an unexpected keyword argument 'mimetype'

This issue seems to be related to the versioning of Quart and Quart-CORS. Can we specify the versions in the requirements to prevent these issues?

ERROR: Caused by: java.io.EOFException: \n not found: limit=0 content=…

Exception in thread "main" java.lang.RuntimeException: java.io.IOException: unexpected end of stream on https://api.openai.com/...
at io.reactivex.internal.util.ExceptionHelper.wrapOrThrow(ExceptionHelper.java:45)
at io.reactivex.internal.observers.BlockingMultiObserver.blockingGet(BlockingMultiObserver.java:90)
at io.reactivex.Single.blockingGet(Single.java:2002)
at com.theokanning.openai.service.OpenAiService.execute(OpenAiService.java:260)
at com.theokanning.openai.service.OpenAiService.createCompletion(OpenAiService.java:119)
at com.shool.chatai.bootaichat.OpenAiTest.main(OpenAiTest.java:36)
Caused by: java.io.IOException: unexpected end of stream on https://api.openai.com/...
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:202)
at okhttp3.internal.connection.RealConnection.createTunnel(RealConnection.kt:457)
at okhttp3.internal.connection.RealConnection.connectTunnel(RealConnection.kt:262)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:201)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at com.theokanning.openai.service.AuthenticationInterceptor.intercept(AuthenticationInterceptor.java:28)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:204)
at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:46)
at io.reactivex.Observable.subscribe(Observable.java:10151)
at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:35)
at io.reactivex.Observable.subscribe(Observable.java:10151)
at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
at io.reactivex.Single.subscribe(Single.java:2517)
at io.reactivex.Single.blockingGet(Single.java:2001)
... 3 more
Caused by: java.io.EOFException: \n not found: limit=0 content=…
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:332)
at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29)
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:178)
... 30 more

Failed to fetch localhost manifest

I am getting this error:
Failed to fetch localhost manifest. Check to ensure your localhost is running and your localhost server has CORS enabled.

I checked and can see the manifest file at http://localhost:5003/.well-known/ai-plugin.json

Any idea what might be wrong here?

Log:

  • Serving Quart app 'main'
  • Environment: production
  • Please use an ASGI server (e.g. Hypercorn) directly in production
  • Debug mode: True
  • Running on http://0.0.0.0:5003 (CTRL + C to quit)
    [2023-04-19 18:44:54 +0200] [20687] [INFO] Running on http://0.0.0.0:5003 (CTRL + C to quit)

How does ChatGPT consume the request?

I'm working on a plugin to create a calendar event with Google via the text interface. I wrote a function with the route /create-calendar-event

@app.route("/create-calendar-event", methods=['POST'])
async def create_calendar_event():
    # Get the event details from the request
    event_details = await request.get_json()
    print('event_details', event_details)

    # Authenticate and get the Google Calendar service
    service = authenticate_and_get_service()
    print('event_details', event_details)

    # Now you can use the service object to create a calendar event
    # You will need to implement the create_event function
    # This function should use the Google Calendar API to create an event with the provided details
    # create_event(service, event_details)

    return quart.Response("Event created successfully", status=200)

When I write "create calendar event" in the ChatGPT interface it successfully identifies the calendar event route as the appropriate route to call

image

but it doesn't log event details I pass in the prompt as the event_details as part of the request.

image

How does ChatGPT figure out what the request is when it identifies the correct route to associate with a prompt?

Localhost plugins failing

Everything used to work, now no matter what I tried, the plugin shows in the OpenAI devtools just fine, it can see the manifest, spec, logo, prompt.

But ChatGPT cannot reach the localhost, it is sending the right calls, but they never reach my server log.

Please check on your end if something is hanging or needs to be reset on the plugins backend.

Thanks!

Update docs to avoid UnrecognizedKwargsError error

I stumbled into this issue on Friday and found two messages on OpenAI's community related to it (both without a clear resolution)

https://community.openai.com/t/getting-strange-unrecognizedkwargserror-error/169600
https://community.openai.com/t/unrecognizedkwargserror-error/197313

After checking the example repo, most specifically the openapi.yaml file, I've noticed that you need to explicitly declare the parameters that are going to be sent to the plugin's API endpoint, and after adding them, the issue went away.

OpenAPI definition documentation

Ideally, it should have one more example showing parameters being declared, just like the example repo.

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.