• Stars
    star
    256
  • Rank 159,219 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

✅ ChatGPT Plugin for managing a TODO list

ChatGPT TODO List

chat-todo-plugin

ChatGPT Plugin for managing a TODO list


Plugin development

[plugin-repo]
|- main.py
|- manifest.json
|- openapi.yaml
|- logo.png
`- ... # other

manifest.json

plugin-manifest: Every plugin requires a ai-plugin.json file, which needs to be hosted on the API’s domain.

{
  "schema_version": "v1",
  "name_for_human": "TODO Plugin (service http)",
  "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": "service_http",
    "authorization_type": "bearer",
    "verification_tokens": {
      "openai": "<YOUR_OPENAI_KEY>"
    }
  },
  "api": {
    "type": "openapi",
    "url": "https://<YOUR_REPO>.<YOUR_OWNER>.repl.co/openapi.yaml",
    "is_user_authenticated": false
  },
  "logo_url": "https://<YOUR_REPO>.<YOUR_OWNER>.repl.co/logo.png",
  "contact_email": "<YOUR_EMAIL>",
  "legal_info_url": "http://www.example.com/legal"
}
  • <YOUR_OPENAI_KEY>: your OpenAI API key
  • <YOUR_REPO>: your replit app name
  • <YOUR_OWNER>: your replit username
  • <YOUR_EMAIL>: your email

openapi.yaml

openapi-definition: OpenAPI specification to document the API. The model in ChatGPT does not know anything about your API other than what is defined in the OpenAPI specification and manifest file. This means that if you have an extensive API, you need not expose all functionality to the model and can choose specific endpoints.

openapi: 3.0.1
info:
  title: TODO Plugin
  description: A plugin that allows the user to create and manage a TODO list using ChatGPT. If you do not know the user's username, ask them first before making queries to the plugin. Otherwise, use the username "global".
  version: 'v1'
servers:
  # product: http://www.example.com
  - url: http://localhost:5002
paths:
  /todos/{username}:
    get:
      operationId: getTodos
      summary: Get the list of todos
      parameters:
      - in: path
        name: username
        schema:
            type: string
        required: true
        description: The name of the user.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/getTodosResponse'
# ...

main.py

import os
import quart
import quart_cors
from quart import Quart, jsonify, request

PORT = 5002
TODOS = {}
# Get authentication key from environment variable
SERVICE_AUTH_KEY = os.environ.get("SERVICE_AUTH_KEY")


# Create a Quart app and enable CORS
app = quart_cors.cors(
  Quart(__name__),
  allow_origin=[
    f"http://localhost:{PORT}",
    "https://chat.openai.com",
  ]
)


# Add a before_request hook to check for authorization header
@app.before_request
def assert_auth_header():
  auth_header = request.headers.get("Authorization")
  print(auth_header)
  # check if the header is missing or incorrect, and return an error if needed
  if not auth_header or auth_header != f"Bearer {SERVICE_AUTH_KEY}":
        return jsonify({"error": "Unauthorized"}), 401


# Add a route to get all todos
@app.route("/todos", methods=["GET"])
async def get_todos():
  return jsonify(TODOS)


# Add a route to get all todos for a specific user
@app.route("/todos/<string:username>", methods=["GET"])
async def get_todo_user(username):
    todos = TODOS.get(username, [])
    return jsonify(todos)


# Add a route to add a todo for a specific user
@app.route("/todos/<string:username>", methods=["POST"])
async def add_todo(username):
    request_data = await request.get_json()
    todo = request_data.get("todo", "")
    TODOS.setdefault(username, []).append(todo)
    return jsonify({"status": "success"})


# Add a route to delete a todo for a specific user
@app.route("/todos/<string:username>", methods=["DELETE"])
async def delete_todo(username):
    request_data = await request.get_json()
    todo_idx = request_data.get("todo_idx", -1)
    if 0 <= todo_idx < len(TODOS.get(username, [])):
        TODOS[username].pop(todo_idx)
    return jsonify({"status": "success"})


@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("manifest.json") as f:
    text = f.read()
    text = text.replace("PLUGIN_HOSTNAME", f"https://{host}")
    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()
    text = text.replace("PLUGIN_HOSTNAME", f"https://{host}")
    return quart.Response(text, mimetype="text/yaml")


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


if __name__ == "__main__":
  main()

Plugin Deploy (Replit)

  • Open Replit and click the Create Repl button.
  • When the pop-up window appears, click the Import from GitHub button in the top right corner.
  • In the GitHub URL field, enter https://github.com/lencx/chat-todo-plugin and select Python as the language.
  • Then click the Import from GitHub button in the bottom right corner and wait for the initialization to complete.
  • Click the Run button and wait for the execution to finish.

TODO API

all list

curl -X GET http://0.0.0.0:5002/todos \
 -H 'Content-Type: application/json' \
 -H 'Authorization: Bearer $SERVICE_AUTH_KEY'

specific user

curl -X GET http://0.0.0.0:5002/todos/lencx \
 -H 'Content-Type: application/json' \
 -H 'Authorization: Bearer $SERVICE_AUTH_KEY'

specific user: add

curl -X POST http://0.0.0.0:5002/todos/lencx \
 -H 'Content-Type: application/json' \
 -H 'Authorization: Bearer $SERVICE_AUTH_KEY' \
 -d '{ "todo": "hello" }'

specific user: delete

curl -X DELETE http://0.0.0.0:5002/todos/lencx \
 -H 'Content-Type: application/json' \
 -H 'Authorization: Bearer $SERVICE_AUTH_KEY' \
 -d '{ "todo_idx": 0 }'

More Repositories

1

ChatGPT

🔮 ChatGPT Desktop Application (Mac, Windows and Linux)
Rust
52,379
star
2

Noi

🚀 Power Your World with AI - Explore, Extend, Empower.
JavaScript
6,134
star
3

nofwl

NoFWL Desktop Application
Rust
4,246
star
4

tauri-tutorial

📚 Tauri Tutorial (系列教程 - 打造属于自己的跨端应用)
TypeScript
557
star
5

GPTHub

🔍 Discover the Best in Custom GPT at OpenAI's GPT Store – Your Adventure Begins Here!
TypeScript
502
star
6

awesome-ai

🤖 Awesome AI
361
star
7

z

〽️ 浮之静
TypeScript
156
star
8

awesome

😎 Awesome lists about all kinds of interesting topics
100
star
9

WA

🤩 WA+ = W(eb) + A(pp) + more...
Rust
93
star
10

app

🏖️ No Free Work Life
JavaScript
84
star
11

rust-fe

🦀 Rust in front-end (系列教程 - 用前端视角学习 Rust)
Rust
64
star
12

create-mpl

⚡️ Create a project in seconds!
TypeScript
58
star
13

gg

🦄 GG (Gatsby + GitHub) - A gatsby website builder based on github discussions
TypeScript
48
star
14

code-snippets

✍️ code - 手写系列
TypeScript
41
star
15

.lencx

about me
28
star
16

fe-tips

JavaScript
22
star
17

sd-webui-qrcode

🔲 Stable Diffusion WebUI's QR Code Generator
Python
22
star
18

dev

🙈 开发那些事儿
TypeScript
20
star
19

create-xc-app

⚡️ Create a project in seconds!
TypeScript
18
star
20

tauri-release

🔗 tauri release toolchain
TypeScript
18
star
21

vite-bytecode

13
star
22

rsw-node

⚪️ `wasm-pack build` executed in remote deployment
Rust
13
star
23

wiki

🗺 lencx 的知识地图
TypeScript
12
star
24

woap

🌀 GitHub Discussions - 生成微信文章 (支持二维码及脚注形式)
JavaScript
10
star
25

web

〽️ No free working life
TypeScript
9
star
26

rgd

🍱 GitHub Discussions API - RSS & JSON
JavaScript
7
star
27

cos

🖥 操作系统学习
SWIG
7
star
28

download-github

⬇️ Download directory from a GitHub repo.
TypeScript
7
star
29

deno-example

🦕 Deno Example
TypeScript
6
star
30

book

👨🏻‍💻 学习 + 思考 + 总结
Handlebars
6
star
31

learn-rust

🦀 Learning Rust
Rust
6
star
32

xi

X IDE
TypeScript
5
star
33

vue-multi-pages

☘️ Vue Multi Pages([email protected] & [email protected] & pug)
JavaScript
4
star
34

resume

📝 简历模板,开发中...
TypeScript
4
star
35

music

Music Generator
Vue
4
star
36

utils-rs

🦑 Rust utility library
Rust
4
star
37

vsg

:octocat: Explore Github repositories directly from Visual Studio Code.
TypeScript
4
star
38

algorithms

🤖 Data structure and algorithms
Shell
3
star
39

short-link

Link shortener
Nunjucks
3
star
40

deno-getfiles

📂 Recursively get all files in a directory
TypeScript
3
star
41

multipage-template

Multi-module(webpack4, vue2, pug, scss, postcss)
JavaScript
2
star
42

post

🔥 Article, Concept, Language, Tools, Tricks
C
2
star
43

english

TypeScript
2
star
44

sponsor

❤️ 开源不易,给点鼓励,感恩!
2
star
45

cloudevents

☁️ koa + cloudevents
JavaScript
2
star
46

compiler

🌀 constructing a compiler.
2
star
47

jaeger-node

koa + jaeger
JavaScript
2
star
48

GD

🍭 Blog template based on GitHub Discussions
TypeScript
2
star
49

share

🎦 technology sharing
JavaScript
1
star
50

library

🦄 JavaScript Libraries
JavaScript
1
star
51

rust-learn-demo

📝 Note & Demo
Rust
1
star
52

rsw-action

TypeScript
1
star
53

homebrew-nofwl

NoFWL
Ruby
1
star
54

test-action

TypeScript
1
star
55

travel

🏖 游记
TypeScript
1
star
56

explore

💡 ideas and try
Dart
1
star
57

learn-puppeteer

puppeteer 学习笔记
JavaScript
1
star
58

blog

🌈 Lencx's Blog
HTML
1
star
59

conf

⚙️ Config
Shell
1
star
60

demo

📌 Demo
HTML
1
star
61

imgmaps

1
star
62

use-ant

Ant Hooks
1
star
63

clang-learn-demo

1
star
64

nx

🐠 js utils, react hooks, antd hook, etc.
TypeScript
1
star
65

lightworld

☀️ 光
Rust
1
star
66

covid19

🦠2019 Novel Coronavirus
TypeScript
1
star
67

mess

react components
JavaScript
1
star
68

hazy-vs-theme

Hazy VSCode Theme for Operator Mono
1
star
69

angular-hero-app

hero app (angular4+pug+material+sass+indexedDB)
TypeScript
1
star
70

electron-forge-terminal-demo

Test
TypeScript
1
star
71

angular2-init

⚡️ Angular2 Beta Boilerplate
CSS
1
star