generated from hc33brackles/cassandra-todolist-chatgpt-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 245b08a
Showing
12 changed files
with
551 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This configuration file was automatically generated by Gitpod. | ||
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml) | ||
# and commit this file to your remote git repository to share the goodness with others. | ||
|
||
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart | ||
|
||
tasks: | ||
- init: pip install -r requirements.txt | ||
command: python main.py | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"schema_version": "v1", | ||
"name_for_human": "Cassandra TODO List (no auth)", | ||
"name_for_model": "todo", | ||
"description_for_human": "Manage your TODO list in Apache Cassandra. 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 in Apache Cassandra.", | ||
"auth": { | ||
"type": "none" | ||
}, | ||
"api": { | ||
"type": "openapi", | ||
"url": "http://localhost:5003/openapi.yaml" | ||
}, | ||
"logo_url": "http://localhost:5003/logo.png", | ||
"contact_email": "legal@example.com", | ||
"legal_info_url": "http://example.com/legal" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 OpenAI | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
# Cassandra Todolist ChatGPT plugin 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](https://platform.openai.com/docs/plugins). If you do not already have plugin developer access, please [join the waitlist](https://openai.com/waitlist/plugins). | ||
|
||
## Quickstart in Gitpod | ||
|
||
You can either follow the directions below or [open this in gitpod](https://gitpod.io/#https://github.com/CassioML/cassandra-todolist-chatgpt-plugin). | ||
|
||
[](https://gitpod.io/#https://github.com/CassioML/cassandra-todolist-chatgpt-plugin) | ||
|
||
## Setup | ||
|
||
### Clone the Repo | ||
Before you can run the plugin, you need to get the code onto your computer. This is done by cloning the GitHub repository. If you have git installed, you can do this by running the following command in your terminal: | ||
|
||
```bash | ||
git clone https://github.com/CassioML/cassandra-todolist-chatgpt-plugin | ||
``` | ||
|
||
This will create a copy of the repository on your local machine. | ||
Once you have cloned the repository, navigate into the directory: | ||
|
||
```bash | ||
cd cassandra-todolist-chatgpt-plugin | ||
``` | ||
### Install Prerequisites | ||
|
||
To install the required packages for this plugin, run the following command: | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### Setup DB & API | ||
|
||
You can read up on how to setup the database and configure the API spec. It's important to either have a Cassandra server or use Datastax Astra DB, otherwise this example won't work. | ||
- [Database setup](/setup/database.md) - Create a database, keyspace, and import the schema/ | ||
- [API setup](/setup/database.md) - Update plugin and openapi spec for ChatGPT to discover your API's capabilities. | ||
|
||
#### Create/edit .env and add the DB details to your .env file | ||
```bash | ||
touch .env | ||
``` | ||
|
||
and add (if you are using DataStax Astra) the two components of the Astra Token to your .env file: | ||
```code | ||
astra_clientID="<<your clientID" | ||
astra_clientSecret="<<your clientSecret>>" | ||
``` | ||
If you are using Astra, you'll also need to download and add the Secure Connect Bundle into your ./setup folder. | ||
|
||
### Run the API | ||
|
||
To run the plugin, enter the following command: | ||
|
||
```bash | ||
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](https://community.openai.com/c/chat-plugins/20). | ||
|
||
## Todo | ||
- [ ] Update links to connect w/ CassioML community on Github , PlanetCassandra discord | ||
- [ ] Add Cassandra Driver/Cassio Lib to interact w/ Cassandra/Astra | ||
- [ ] Add CRUD code for TODOs in main.py | ||
|
||
## Done | ||
- [x] Add instructions to create schema in Cassandra/Astra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from cassandra.cluster import Cluster | ||
from cassandra.auth import PlainTextAuthProvider | ||
import os | ||
import json | ||
import quart | ||
import quart_cors | ||
from quart import request | ||
from dotenv import load_dotenv | ||
load_dotenv() | ||
|
||
#Configure the Python Driver for Cassandra | ||
#You'll need to have moved the secure connect bundle downloaded through your Astra UI (the Connect tab) to the specified location and ensure that the name matches | ||
cloud_config= { | ||
'secure_connect_bundle': './setup/secure-connect-cassio-ml.zip' | ||
} | ||
#In order for the Auth_Provider to work, your .env file must match the exact names specified here (or rename them and make sure the names match). | ||
auth_provider = PlainTextAuthProvider(os.getenv("astra_clientID"),os.getenv("astra_clientSecret")) | ||
cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider) | ||
session = cluster.connect() | ||
|
||
|
||
app = quart_cors.cors(quart.Quart(__name__), allow_origin="https://chat.openai.com") | ||
|
||
# Keep track of todo's. Todos written to astra will persist beyond the end of your python session. | ||
|
||
@app.route("/todos/<string:username>", methods=["POST"]) | ||
async def add_todo(username): | ||
request_data = await quart.request.get_json(force=True) | ||
todo = request_data["todo"] | ||
|
||
# Check if the username already exists in the Cassandra table | ||
query = f"SELECT COUNT(*) FROM cassio_tutorials.todos WHERE username = '{username}'" | ||
result = session.execute(query) | ||
count = result.one()[0] | ||
|
||
# If the username does not exist, insert it into the Cassandra table | ||
if count == 0: | ||
insert_query = f"INSERT INTO cassio_tutorials.todos (username, todo) VALUES ('{username}','test task')" | ||
session.execute(insert_query) | ||
|
||
# Insert the task into the Cassandra table | ||
todo_insert_query = f"INSERT INTO cassio_tutorials.todos (username, todo) VALUES ('{username}', '{todo}')" | ||
session.execute(todo_insert_query) | ||
return quart.Response(response='OK', status=200) | ||
|
||
@app.route("/todos/<string:username>", methods=["GET"]) | ||
async def get_todos(username): | ||
# Retrieve the tasks from the Cassandra table for the provided username | ||
query = f"SELECT todo FROM cassio_tutorials.todos WHERE username = '{username}'" | ||
result = session.execute(query) | ||
todos = [row.todo for row in result] | ||
return quart.jsonify(todos) | ||
|
||
@app.route("/todos/<string:username>", methods=["DELETE"]) | ||
async def delete_todo(username): | ||
request_data = await quart.request.get_json(force=True) | ||
todo_idx = request_data["todo_idx"] | ||
|
||
# Retrieve the task at the given index for the provided username | ||
query = f"SELECT todo FROM cassio_tutorials.todos WHERE username = '{username}'" | ||
result = session.execute(query) | ||
todos = [row.todo for row in result] | ||
|
||
if 0 <= todo_idx < len(todos): | ||
todos_to_delete = todos[todo_idx] | ||
|
||
# Delete the task from the Cassandra table | ||
query = f"DELETE FROM cassio_tutorials.todos WHERE username = '{username}' AND todo = '{todos_to_delete}'" | ||
session.execute(query) | ||
|
||
return quart.Response(response='OK', status=200) | ||
|
||
@app.route("/logo.png", methods=["GET"]) | ||
async def plugin_logo(): | ||
filename = 'logo.png' | ||
return await quart.send_file(filename, mimetype='image/png') | ||
|
||
@app.route("/.well-known/ai-plugin.json", methods=["GET"]) | ||
async def plugin_manifest(): | ||
host = request.headers['Host'] | ||
with open("./.well-known/ai-plugin.json") as f: | ||
text = f.read() | ||
return quart.Response(text, content_type="text/json") | ||
|
||
@app.route("/openapi.yaml", methods=["GET"]) | ||
async def openapi_spec(): | ||
host = request.headers['Host'] | ||
with open("openapi.yaml") as f: | ||
text = f.read() | ||
return quart.Response(text, content_type="text/json") | ||
|
||
def main(): | ||
app.run(debug=True, host="0.0.0.0", port=5003) | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.