Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JavaScript Version of Plugins Quickstart #6

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chatgptailist@notyourneighborson****


## 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.
Expand Down
68 changes: 68 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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);
}
});
});

app.listen(5003, '0.0.0.0', () => {
console.log('App is running on port 5003');
});
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.2"
}
}