├── LLM-IS-BACKEND.jpeg ├── README.md ├── backend ├── .gitignore ├── README.md ├── db.json ├── requirements.txt └── server.py ├── frontend-chess ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt └── src │ ├── App.css │ ├── App.js │ ├── App.test.js │ ├── ChessBoard.js │ ├── Highlight.js │ ├── api │ └── api.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js └── frontend ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── APIHelper.js ├── App.css ├── App.js ├── App.test.js ├── index.css ├── index.js ├── logo.svg ├── serviceWorker.js └── setupTests.js └── yarn.lock /LLM-IS-BACKEND.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RootbeerComputer/backend-GPT/e1cd4c0cb0b44ac72da9b2a27d879416108c6f12/LLM-IS-BACKEND.jpeg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GPT is all you need for the backend 2 | 3 |
4 | 5 | [![Discord](https://img.shields.io/discord/1122949106558570648)](https://discord.gg/3ASBTJWgGS) 6 |
7 | 8 | ![Galaxy brain meme (a) Writing a backend (b) hiring a backend engineer (c) Asking ChatGPT for a backend (d) The LLM is the backend](LLM-IS-BACKEND.jpeg) 9 | 10 | People have been saying Github Copilot will replace programmers. We think that's wrong. We have all powerful models and we want to restrict them to writing code? All code has bugs! 11 | 12 | Code is not the ideal way to encode business logic. Code must be reviewed, and it does what you tell it, not what you want. The proper format for business logic is human intelligence. 13 | 14 | So we thought, who needs python and ec2s and biz logic and postgres? 15 | 16 | We've built a entire Backend+Database powered by an LLM. It infers business logic based on the name of the API call and can persist a kilobyte of state! 17 | 18 | Here's the experience of the future: 19 | 1. Instruct the LLM on the purpose of the backend (i.e. "This is a todo list app") 20 | 2. Write the initial json blob for the database state (i.e. {todo_items: [{title: "eat breakfast", completed: true}, {title: "go to school", completed: false}]} 21 | 3. Start making API calls! You now have infinite backend endpoints that will infer their own business logic and update the persistent state! 22 | 23 | ## Why 24 | This is the future we imagine 25 | 1. You can iterate on your frontend without knowing exactly what the backend needs to look like. 26 | 2. Backend gives you the wrong format? `https://backend-gpt.com/chess/get_board_state()` -> `https://backend-gpt.com/chess/get_board_state_as_fen()` 27 | 3. Mistype an API name? It doesn't matter! 28 | 4. Serverless w/o the cold start: The only difference between your server and someone elses is the 1KB of state and the LLM instructions, these can be swapped out in milliseconds 29 | 30 | 31 | ## Still don't get it? 32 | Here's how it works in Parker's words 33 | 34 | We basically used GPT to handle all the backend logic for a todo-list app. We represented the state of the app as a json with some prepopulated entries which helped define the schema. Then we pass the prompt, the current state, and some user-inputted instruction/API call in and extract a response to the client + the new state. So the idea is that instead of writing backend routes, the LLM can handle all the basic CRUD logic for a simple app so instead of writing specific routes, you can input commands like add_five_housework_todos() or delete_last_two_todos() or sort_todos_alphabetically() . It tends to work better when the commands are expressed as functions/pseudo function calls but natural language instructions like delete last todos also work. 35 | 36 |
37 | 38 | [![Discord](https://img.shields.io/discord/1122949106558570648)](https://discord.gg/3ASBTJWgGS) 39 |
40 | -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | env -------------------------------------------------------------------------------- /backend/README.md: -------------------------------------------------------------------------------- 1 | sry you can't use this repo for free anymore :( 2 | insert your open ai API keys in server.py 3 | ``` 4 | python3 server.py 5 | curl "http://127.0.0.1:5000/todo_list/mark_incomplete(3)" 6 | curl "http://127.0.0.1:5000/todo_list/get_all()" 7 | ``` 8 | -------------------------------------------------------------------------------- /backend/db.json: -------------------------------------------------------------------------------- 1 | { 2 | "todo_list": { 3 | "prompt": "This is a todo list app.", 4 | "state": { 5 | "todos": [ 6 | { 7 | "title": "Learn react", 8 | "completed": true 9 | }, 10 | { 11 | "title": "Buy Milk", 12 | "completed": true 13 | }, 14 | { 15 | "title": "Do laundry", 16 | "completed": false 17 | }, 18 | { 19 | "title": "Clean room", 20 | "completed": true 21 | } 22 | ] 23 | } 24 | }, 25 | "chess": { 26 | "prompt": "You are a chess assistant", 27 | "state": { 28 | "board": [ 29 | [ 30 | "r", 31 | "n", 32 | "b", 33 | "q", 34 | "k", 35 | "b", 36 | "n", 37 | "r" 38 | ], 39 | [ 40 | "p", 41 | "p", 42 | "p", 43 | "p", 44 | "p", 45 | "p", 46 | "p", 47 | "p" 48 | ], 49 | [ 50 | " ", 51 | " ", 52 | " ", 53 | " ", 54 | " ", 55 | " ", 56 | " ", 57 | " " 58 | ], 59 | [ 60 | " ", 61 | " ", 62 | " ", 63 | " ", 64 | " ", 65 | " ", 66 | " ", 67 | " " 68 | ], 69 | [ 70 | " ", 71 | " ", 72 | " ", 73 | " ", 74 | " ", 75 | " ", 76 | " ", 77 | " " 78 | ], 79 | [ 80 | " ", 81 | " ", 82 | " ", 83 | " ", 84 | " ", 85 | " ", 86 | " ", 87 | " " 88 | ], 89 | [ 90 | "P", 91 | "P", 92 | "P", 93 | "P", 94 | "P", 95 | "P", 96 | "P", 97 | "P" 98 | ], 99 | [ 100 | "R", 101 | "N", 102 | "B", 103 | "Q", 104 | "K", 105 | "B", 106 | "N", 107 | "R" 108 | ] 109 | ], 110 | "turn": "white", 111 | "white_castle_kingside": true, 112 | "white_castle_queenside": true, 113 | "black_castle_kingside": true, 114 | "black_castle_queenside": true, 115 | "en_passant": null, 116 | "halfmove_clock": 0, 117 | "fullmove_number": 1 118 | } 119 | } 120 | } -------------------------------------------------------------------------------- /backend/requirements.txt: -------------------------------------------------------------------------------- 1 | openai 2 | flask 3 | flask-cors 4 | tiktoken 5 | -------------------------------------------------------------------------------- /backend/server.py: -------------------------------------------------------------------------------- 1 | import json 2 | from flask import Flask 3 | from flask_cors import CORS 4 | import re 5 | import openai 6 | import ast 7 | import tiktoken 8 | enc = tiktoken.get_encoding("gpt2") 9 | openai.api_key = # put key here 10 | def gpt3(input): 11 | completion = openai.Completion.create( 12 | prompt=input, 13 | model="text-davinci-003", 14 | max_tokens=4000-len(enc.encode(input)), 15 | temperature=0 16 | ) 17 | return completion.choices[0].text 18 | 19 | def dict_to_json(d): 20 | return d.__dict__ 21 | 22 | app = Flask(__name__) 23 | CORS(app) 24 | db = json.load(open('db.json','r')) 25 | print("INITIAL DB STATE") 26 | print(db['todo_list']["state"]) 27 | 28 | @app.route('//') 29 | def api(app_name, api_call): 30 | db = json.load(open('db.json','r')) 31 | print("INPUT DB STATE") 32 | print(db[app_name]["state"]) 33 | gpt3_input = f"""{db[app_name]["prompt"]} 34 | API Call (indexes are zero-indexed): 35 | {api_call} 36 | 37 | Database State: 38 | {db[app_name]["state"]} 39 | 40 | Output the API response as json prefixed with '!API response!:'. Then output the new database state as json, prefixed with '!New Database State!:'. If the API call is only requesting data, then don't change the database state, but base your 'API Response' off what's in the database. 41 | """ 42 | completion = gpt3(gpt3_input) 43 | 44 | # parsing "API Response" and "New Database State" with regex 45 | api_response_match = re.search("(?<=!API Response!:).*(?=!New Database State!:)", completion, re.DOTALL) 46 | new_database_match = re.search("(?<=!New Database State!:).*", completion, re.DOTALL) 47 | 48 | # converting regex result into json string 49 | api_response_text = api_response_match.string[api_response_match.regs[0][0]:api_response_match.regs[0][1]].strip() 50 | new_database_text = new_database_match.string[new_database_match.regs[0][0]:new_database_match.regs[0][1]].strip() 51 | 52 | response = json.loads(json.dumps(ast.literal_eval(api_response_text))) 53 | print("RESPONSE") 54 | print(response) 55 | 56 | new_state = json.loads(json.dumps(ast.literal_eval(new_database_text))) 57 | print("NEW_STATE") 58 | print(new_state) 59 | 60 | db[app_name]["state"] = new_state 61 | json.dump(db, open('db.json', 'w'), indent=4, default=dict_to_json) 62 | return response 63 | 64 | if __name__ == "__main__": 65 | app.run() -------------------------------------------------------------------------------- /frontend-chess/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /frontend-chess/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /frontend-chess/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scaleai-chess", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "axios": "^1.2.3", 10 | "chess.js": "^1.0.0-beta.2", 11 | "react": "^18.2.0", 12 | "react-chessboard": "^2.0.8", 13 | "react-dom": "^18.2.0", 14 | "react-scripts": "5.0.1", 15 | "web-vitals": "^2.1.4" 16 | }, 17 | "scripts": { 18 | "start": "react-scripts start", 19 | "build": "react-scripts build", 20 | "test": "react-scripts test", 21 | "eject": "react-scripts eject" 22 | }, 23 | "eslintConfig": { 24 | "extends": [ 25 | "react-app", 26 | "react-app/jest" 27 | ] 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /frontend-chess/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RootbeerComputer/backend-GPT/e1cd4c0cb0b44ac72da9b2a27d879416108c6f12/frontend-chess/public/favicon.ico -------------------------------------------------------------------------------- /frontend-chess/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /frontend-chess/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RootbeerComputer/backend-GPT/e1cd4c0cb0b44ac72da9b2a27d879416108c6f12/frontend-chess/public/logo192.png -------------------------------------------------------------------------------- /frontend-chess/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RootbeerComputer/backend-GPT/e1cd4c0cb0b44ac72da9b2a27d879416108c6f12/frontend-chess/public/logo512.png -------------------------------------------------------------------------------- /frontend-chess/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /frontend-chess/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /frontend-chess/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /frontend-chess/src/App.js: -------------------------------------------------------------------------------- 1 | import logo from "./logo.svg"; 2 | import ChessBoard from "./ChessBoard"; 3 | import Highlight from "./Highlight"; 4 | 5 | import { useState } from "react"; 6 | 7 | import "./App.css"; 8 | 9 | function App() { 10 | const [computerTurn, setComputerTurn] = useState(false); 11 | 12 | return ( 13 | <> 14 |
15 |
24 | 25 | 26 |
27 |
35 |
41 | 42 |
43 |
44 | {computerTurn 45 | ? "LLMagnus Carlsen is thinking..." 46 | : "It's your move to play!"} 47 |
48 |
49 |
50 | 51 | ); 52 | } 53 | 54 | export default App; 55 | -------------------------------------------------------------------------------- /frontend-chess/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /frontend-chess/src/ChessBoard.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | import { Chess } from "chess.js"; 3 | import { Chessboard } from "react-chessboard"; 4 | 5 | function ChessBoard({ setComputerTurn }) { 6 | const [game, setGame] = useState(new Chess()); 7 | 8 | function makeAMove(move) { 9 | // const gameCopy = game; 10 | let gameCopy = Object.assign( 11 | Object.create(Object.getPrototypeOf(game)), 12 | game 13 | ); 14 | 15 | const result = gameCopy.move(move); 16 | setGame(gameCopy); 17 | return result; // null if the move was illegal, the move object if the move was legal 18 | } 19 | 20 | function makeRandomMove() { 21 | let gameCopy = Object.assign( 22 | Object.create(Object.getPrototypeOf(game)), 23 | game 24 | ); 25 | let gameFen = gameCopy.fen(); 26 | const newFen = gameFen.replace("w", "b"); 27 | gameCopy.load(newFen); 28 | console.log(gameCopy); 29 | 30 | setGame(gameCopy); 31 | 32 | const possibleMoves = gameCopy.moves(); 33 | 34 | console.log(possibleMoves); 35 | if (game.isGameOver() || game.isDraw() || possibleMoves.length === 0) 36 | return; // exit if the game is over 37 | const randomIndex = Math.floor(Math.random() * possibleMoves.length); 38 | makeAMove(possibleMoves[randomIndex]); 39 | // makeAMove(possibleMoves[0]); 40 | setComputerTurn(false); 41 | } 42 | 43 | function onDrop(sourceSquare, targetSquare) { 44 | const move = makeAMove({ 45 | from: sourceSquare, 46 | to: targetSquare, 47 | promotion: "q", // always promote to a queen for example simplicity 48 | }); 49 | 50 | // illegal move 51 | if (move === null) return false; 52 | setComputerTurn(true); 53 | 54 | setTimeout(makeRandomMove, 4500); 55 | 56 | return true; 57 | } 58 | 59 | return ( 60 | <> 61 | 62 | 63 | ); 64 | } 65 | 66 | export default ChessBoard; 67 | -------------------------------------------------------------------------------- /frontend-chess/src/Highlight.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | function Highlight({ name }) { 4 | const [hover, setHover] = useState(false); 5 | 6 | return ( 7 |
setHover(true)} 19 | onMouseLeave={() => setHover(false)} 20 | > 21 |

22 | {name} 23 |

24 |
25 | ); 26 | } 27 | 28 | export default Highlight; 29 | -------------------------------------------------------------------------------- /frontend-chess/src/api/api.js: -------------------------------------------------------------------------------- 1 | import axios from "../lib/axios"; 2 | 3 | const makeChessMove = () => { 4 | // axios.get("/user?ID=12345").then(); 5 | }; 6 | -------------------------------------------------------------------------------- /frontend-chess/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /frontend-chess/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /frontend-chess/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend-chess/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /frontend-chess/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | /.pnp 3 | .pnp.js 4 | 5 | # testing 6 | /coverage 7 | 8 | # production 9 | /build 10 | 11 | # misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # RIZZ-meister 2 | 3 | In the project directory, you can run: 4 | 5 | Run `yarn start` to start the project. 6 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "todo-frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/core": "^4.12.4", 7 | "@testing-library/jest-dom": "^4.2.4", 8 | "@testing-library/react": "^9.5.0", 9 | "@testing-library/user-event": "^7.2.1", 10 | "axios": "^0.19.2", 11 | "react": "^16.13.1", 12 | "react-dom": "^16.13.1", 13 | "react-scripts": "3.4.1" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": "react-app" 23 | }, 24 | "browserslist": { 25 | "production": [ 26 | ">0.2%", 27 | "not dead", 28 | "not op_mini all" 29 | ], 30 | "development": [ 31 | "last 1 chrome version", 32 | "last 1 firefox version", 33 | "last 1 safari version" 34 | ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RootbeerComputer/backend-GPT/e1cd4c0cb0b44ac72da9b2a27d879416108c6f12/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /frontend/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RootbeerComputer/backend-GPT/e1cd4c0cb0b44ac72da9b2a27d879416108c6f12/frontend/public/logo192.png -------------------------------------------------------------------------------- /frontend/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RootbeerComputer/backend-GPT/e1cd4c0cb0b44ac72da9b2a27d879416108c6f12/frontend/public/logo512.png -------------------------------------------------------------------------------- /frontend/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /frontend/src/APIHelper.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | const API_URL = "http://localhost:5000/todo_list" 4 | async function createTodo(task) { 5 | const data = await (await axios.get(`${API_URL}/add_todo(${task})`)).data; 6 | return data.message; 7 | } 8 | 9 | async function deleteTodo(title) { 10 | const data = await (await axios.get(`${API_URL}/delete(${title})`)).data; 11 | return data.message; 12 | } 13 | 14 | async function markIncomplete(title) { 15 | const data = await (await axios.get(`${API_URL}/mark_incomplete(${title})`)).data; 16 | return data.message; 17 | } 18 | async function markComplete(title) { 19 | const data = await (await axios.get(`${API_URL}/mark_complete(${title})`)).data 20 | return data.message; 21 | } 22 | 23 | async function runCommand(command) { 24 | const data = await (await axios.get(`${API_URL}/${command})`)).data; 25 | return data.message; 26 | } 27 | 28 | async function getAllTodos() { 29 | const res = await axios.get(`${API_URL}/get_all()`); 30 | return res.data; 31 | } 32 | 33 | export default { createTodo, deleteTodo, markIncomplete, markComplete, getAllTodos, runCommand }; 34 | -------------------------------------------------------------------------------- /frontend/src/App.css: -------------------------------------------------------------------------------- 1 | .completed { 2 | text-decoration: line-through; 3 | color: gray; 4 | } 5 | 6 | .App{ 7 | margin: 10rem auto; 8 | width: 800px; 9 | display: flex; 10 | justify-content: center; 11 | flex-direction: column; 12 | align-items: center; 13 | align-content: center; 14 | 15 | } -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import "./App.css"; 3 | import APIHelper from "./APIHelper.js"; 4 | 5 | function App() { 6 | const [todos, setTodos] = useState([]); 7 | const [todo, setTodo] = useState(""); 8 | const [command, setCommand] = useState(""); 9 | const [commandOutput, setCommandOutput] = useState("No command output") 10 | 11 | useEffect(() => { 12 | const fetchTodoAndSetTodos = async () => { 13 | const todos = await APIHelper.getAllTodos(); 14 | setTodos(todos); 15 | }; 16 | fetchTodoAndSetTodos(); 17 | }, []); 18 | 19 | const runCommand = async e => { 20 | e.preventDefault(); 21 | if (!command) { 22 | alert("please enter something"); 23 | return; 24 | } 25 | setCommandOutput("Command in progress"); 26 | setCommandOutput(await APIHelper.runCommand(command)); 27 | const todoList = await APIHelper.getAllTodos(); 28 | setTodos([...todoList]); 29 | } 30 | 31 | const createTodo = async e => { 32 | e.preventDefault(); 33 | if (!todo) { 34 | alert("please enter something"); 35 | return; 36 | } 37 | if (todos.some(({ task }) => task === todo)) { 38 | alert(`Task: ${todo} already exists`); 39 | return; 40 | } 41 | setCommandOutput("Command in progress"); 42 | setCommandOutput(await APIHelper.createTodo(todo)); 43 | const todoList = await APIHelper.getAllTodos(); 44 | setTodos([...todoList]); 45 | }; 46 | 47 | const deleteTodo = async (e, id) => { 48 | try { 49 | e.stopPropagation(); 50 | setCommandOutput("Command in progress"); 51 | setCommandOutput(await APIHelper.deleteTodo(todos[id].title)); 52 | const todoList = await APIHelper.getAllTodos(); 53 | setTodos([...todoList]); 54 | } catch (err) { } 55 | }; 56 | 57 | const updateTodo = async (e, id) => { 58 | e.stopPropagation(); 59 | setCommandOutput("Command in progress"); 60 | if (todos[id].completed === true) { 61 | setCommandOutput(await APIHelper.markIncomplete(todos[id].title)); 62 | } 63 | else { 64 | setCommandOutput(await APIHelper.markComplete(todos[id].title)); 65 | } 66 | const todoList = await APIHelper.getAllTodos(); 67 | setTodos(todoList); 68 | 69 | }; 70 | 71 | return ( 72 |
73 |
74 | All backend logic is being handled by an LLM 75 |

76 |

77 |
78 | We've prebuilt requests to add todos, mark complete (click an incomplete todo), mark incomplete (click a completed todo), delete (click the x). Or you can run your own commands via the command bar. Play around! 79 |

80 | For example, try something like "delete last 2 todos". It can handle some natural language, but it's generally better to do a function in pseudocode, like "add_todo_twice(do squats)". 81 |

82 |

83 |
84 | setTodo(target.value)} 88 | placeholder="Enter a todo" 89 | /> 90 | 93 |
94 | 95 |
    96 | {todos.length ? todos.map(({ title, completed }, i) => ( 97 |
  • updateTodo(e, i)} 100 | className={completed ? "completed" : ""} 101 | > 102 | {title} deleteTodo(e, i)}>X 103 |
  • 104 | )) :

    No Todos Yet :(

    } 105 |
106 |
107 | http://localhost:5000/todo_list/ setCommand(target.value)} 111 | placeholder="Enter a command" 112 | /> 113 | 116 |
117 |
118 | Command Output: 119 |
120 | {commandOutput} 121 |
122 |
123 |
124 | ); 125 | } 126 | 127 | export default App; 128 | -------------------------------------------------------------------------------- /frontend/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /frontend/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want your app to work offline and load faster, you can change 15 | // unregister() to register() below. Note this comes with some pitfalls. 16 | // Learn more about service workers: https://bit.ly/CRA-PWA 17 | serviceWorker.unregister(); 18 | -------------------------------------------------------------------------------- /frontend/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /frontend/src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { 'Service-Worker': 'script' }, 105 | }) 106 | .then(response => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get('content-type'); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf('javascript') === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then(registration => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | 'No internet connection found. App is running in offline mode.' 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ('serviceWorker' in navigator) { 133 | navigator.serviceWorker.ready 134 | .then(registration => { 135 | registration.unregister(); 136 | }) 137 | .catch(error => { 138 | console.error(error.message); 139 | }); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /frontend/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | --------------------------------------------------------------------------------