From e566331b29865d02da42a8ed8499fbd78e24b17c Mon Sep 17 00:00:00 2001 From: WFH Brian Date: Mon, 10 Apr 2023 21:03:33 -0400 Subject: [PATCH 1/4] Update README Add JavaScript Setup --- README.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 810c0ff6..f70bc9f0 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,35 @@ Get a Todo list ChatGPT plugin up and running in under 5 minutes using Python. If you do not already have plugin developer access, please [join the waitlist](https://openai.com/waitlist/plugins). -## Setup -To install the required packages for this plugin, run the following command: +## Python Setup -```bash +To install the required packages for the Python version of this plugin, run the following command: + +```bach pip install -r requirements.txt ``` -To run the plugin, enter the following command: +To run the Python plugin, enter the following command: ```bash python main.py ``` +## JavaScript Setup + +To install the required packages for the JavaScript version of this plugin, run the following command: + +```bash +npm install +``` + +To run the JavaScript plugin, enter the following command: + +```bash +node main.js +``` + Once the local server is running: 1. Navigate to https://chat.openai.com. From 02b82de1d1ec743d6fe879e5d7d986e65550bebb Mon Sep 17 00:00:00 2001 From: WFH Brian Date: Mon, 10 Apr 2023 21:06:34 -0400 Subject: [PATCH 2/4] Create package.json Requires --- package.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 00000000..eb297785 --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "cors": "^2.8.5", + "express": "^4.18.2" + } +} From cf9652a3b336b211d173e1bafccea2eb517222df Mon Sep 17 00:00:00 2001 From: WFH Brian Date: Mon, 10 Apr 2023 21:09:12 -0400 Subject: [PATCH 3/4] Create main.js Add option to use node.js --- main.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 main.js diff --git a/main.js b/main.js new file mode 100644 index 00000000..dcbf06c6 --- /dev/null +++ b/main.js @@ -0,0 +1,74 @@ +const express = require('express'); +const cors = require('cors'); +const fs = require('fs'); + +const app = express(); +app.use(express.json()); +app.use(cors({ origin: 'https://chat.openai.com' })); + +// Keep track of todo's. Does not persist if the Node.js process is restarted. +const TODOS = {}; + +app.post('/todos/:username', (req, res) => { + const username = req.params.username; + if (!TODOS[username]) { + TODOS[username] = []; + } + TODOS[username].push(req.body.todo); + res.status(200).send('OK'); +}); + +app.get('/todos/:username', (req, res) => { + const username = req.params.username; + res.status(200).json(TODOS[username] || []); +}); + +app.delete('/todos/:username', (req, res) => { + const username = req.params.username; + const todoIdx = req.body.todo_idx; + // fail silently, it's a simple plugin + if (0 <= todoIdx && todoIdx < TODOS[username].length) { + TODOS[username].splice(todoIdx, 1); + } + res.status(200).send('OK'); +}); + +app.get('/logo.png', (req, res) => { + res.sendFile('logo.png', { root: __dirname }, (err) => { + if (err) { + res.status(500).send(err); + } + }); +}); + +app.get('/.well-known/ai-plugin.json', (req, res) => { + fs.readFile('./.well-known/ai-plugin.json', 'utf8', (err, data) => { + if (err) { + res.status(500).send(err); + } else { + res.set('Content-Type', 'text/json'); + res.status(200).send(data); + } + }); +}); + +app.get('/openapi.yaml', (req, res) => { + fs.readFile('openapi.yaml', 'utf8', (err, data) => { + if (err) { + res.status(500).send(err); + } else { + res.set('Content-Type', 'text/yaml'); + res.status(200).send(data); + } + }); +}); + +const main = () => { + app.listen(5003, '0.0.0.0', () => { + console.log('App is running on port 5003'); + }); +}; + +if (require.main === module) { + main(); +} From 002f4f0ab94a14f3dd55267a32f5fd8a1ca7048e Mon Sep 17 00:00:00 2001 From: WFH Brian Date: Thu, 13 Apr 2023 09:02:01 -0400 Subject: [PATCH 4/4] Clean-up remove unnecessary wrapper --- main.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index dcbf06c6..37966e3d 100644 --- a/main.js +++ b/main.js @@ -63,12 +63,6 @@ app.get('/openapi.yaml', (req, res) => { }); }); -const main = () => { - app.listen(5003, '0.0.0.0', () => { - console.log('App is running on port 5003'); - }); -}; - -if (require.main === module) { - main(); -} +app.listen(5003, '0.0.0.0', () => { + console.log('App is running on port 5003'); +});