├── .eslintignore ├── .eslintrc.cjs ├── .gitignore ├── .npmrc ├── .prettierignore ├── .prettierrc ├── Dockerfile ├── README.md ├── netlify.toml ├── package-lock.json ├── package.json ├── playwright.config.ts ├── src ├── app.html ├── data │ ├── MessageLogStore.ts │ ├── TabDescriptions.ts │ └── proompts.ts ├── index.test.ts ├── lib │ ├── Footer.svelte │ └── Icon.svelte ├── routes │ ├── +layout.svelte │ ├── +page.svelte │ └── +server.ts ├── styles │ ├── color-palette.css │ ├── globals.css │ ├── really-bad-styles.scss │ └── typography.css └── types │ ├── app.d.ts │ └── chat.types.d.ts ├── static ├── favicon.ico ├── favicon.png └── fonts │ └── Sono-Variable.ttf ├── svelte.config.js ├── tests └── test.ts ├── tsconfig.json ├── vite.config.js └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /.svelte-kit 5 | /package 6 | .env 7 | .env.* 8 | !.env.example 9 | 10 | # Ignore files for PNPM, NPM and YARN 11 | pnpm-lock.yaml 12 | package-lock.json 13 | yarn.lock 14 | -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parser: '@typescript-eslint/parser', 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:@typescript-eslint/recommended', 7 | 'prettier', 8 | ], 9 | plugins: ['svelte3', '@typescript-eslint'], 10 | ignorePatterns: ['*.cjs'], 11 | overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }], 12 | settings: { 13 | 'svelte3/typescript': () => require('typescript'), 14 | }, 15 | parserOptions: { 16 | sourceType: 'module', 17 | ecmaVersion: 2020, 18 | }, 19 | env: { 20 | browser: true, 21 | es2017: true, 22 | node: true, 23 | }, 24 | }; 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /.svelte-kit 5 | /package 6 | .env 7 | .env.* 8 | !.env.example 9 | vite.config.js.timestamp-* 10 | vite.config.ts.timestamp-* 11 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /.svelte-kit 5 | /package 6 | .env 7 | .env.* 8 | !.env.example 9 | 10 | # Ignore files for PNPM, NPM and YARN 11 | pnpm-lock.yaml 12 | package-lock.json 13 | yarn.lock 14 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "useTabs": false, 3 | "tabWidth": 2, 4 | "singleQuote": true, 5 | "trailingComma": "es5", 6 | "printWidth": 80, 7 | "plugins": ["prettier-plugin-svelte"], 8 | "pluginSearchDirs": ["."], 9 | "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] 10 | } 11 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:18-alpine AS BUILD_IMAGE 2 | 3 | # Set the platform to build image for 4 | ARG TARGETPLATFORM 5 | ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} 6 | 7 | # Get environment variables 8 | ARG NODE_ENV 9 | 10 | # Install additional tools needed if on arm64 / armv7 11 | RUN \ 12 | case "${TARGETPLATFORM}" in \ 13 | 'linux/arm64') apk add --no-cache python3 make g++ ;; \ 14 | 'linux/arm/v7') apk add --no-cache python3 make g++ ;; \ 15 | 'linux/arm64/v8') apk add --no-cache python3 make g++ ;; \ 16 | esac 17 | 18 | # Create and set the working directory 19 | WORKDIR /app 20 | 21 | # Install app dependencies 22 | COPY package.json package-lock.json ./ 23 | RUN npm install 24 | 25 | # Copy over all project files and folders to the working directory 26 | COPY . ./ 27 | 28 | # Build initial app for production 29 | RUN npm run build 30 | 31 | # Production stage 32 | FROM node:18-alpine 33 | 34 | # Define some ENV Vars 35 | ENV PORT=80 \ 36 | DIRECTORY=/app \ 37 | IS_DOCKER=true 38 | 39 | # Create and set the working directory 40 | WORKDIR ${DIRECTORY} 41 | 42 | # Update tzdata for setting timezone 43 | RUN apk add --no-cache tzdata 44 | 45 | # Copy built application from build phase 46 | COPY --from=BUILD_IMAGE /app ./ 47 | 48 | # Finally, run start command to serve up the built application 49 | CMD [ "npm", "start" ] 50 | 51 | # Expose the port 52 | EXPOSE ${PORT} 53 | 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

💫 Cheat Code

2 |

3 | An AI-powered coding assistant, to generate, fix and improve code
4 | Built as a demo of OpenAI's GPT API
5 | cheat-code.as93.net 6 |

7 |

8 | 9 | 10 |
11 |
12 | Yes, the UI is really ugly 13 |

14 | 15 | 16 | --- 17 | 18 | ## Getting Started 19 | 20 | ### Developing 21 | 22 | ```bash 23 | # 1. Clone the repo and cd into it (update username if you've forked) 24 | git clone git@github.com:Lissy93/cheat-code.git && cd cheat-code 25 | 26 | # 2. Install dependencies 27 | pnpm install 28 | 29 | # 3. Start the development server 30 | pnpm run dev -- --open 31 | ``` 32 | 33 | ### Manual Deploy 34 | 35 | - Fork the repo, then follow the steps above to clone and install dependencies 36 | - Add your `OPENAI_API_KEY` as an enviornmental variable (get a key [here](https://platform.openai.com/account/api-keys)) 37 | - Push changes to your repository 38 | - Enable the build action, to deploy to a service of your choice 39 | 40 | You can also build the site yourself `npm run build`, then either run `node build` to start the server, or use an appropriate [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. 41 | 42 | ### Quick Deploy 43 | 44 | Use the 1-click deploy to get up and running in seconds. 45 | 46 | [![Depoly Cheat Code to Netlify](https://img.shields.io/badge/Deploy-Netlify-%2330c8c9?style=for-the-badge&logo=netlify&labelColor=1e0e41 'Deploy Cheat Code to Netlify, via 1-Click Script')](https://app.netlify.com/start/deploy?repository=https://github.com/lissy93/cheat-code 'Deploy Cheat Code to Render, via 1-Click Script') [![Depoly Cheat Code to Render](https://img.shields.io/badge/Deploy-Render-%236c83fa?style=for-the-badge&logo=render&labelColor=1e0e41&logoColor=6c83fa)](https://render.com/deploy?repo=https://github.com/lissy93/cheat-code 'Deploy Cheat Code to Render, via 1-Click Script') [![Deploy Cheat Code to Railway](https://img.shields.io/badge/Deploy-Railway-%23853bce?style=for-the-badge&logo=railway&labelColor=1e0e41&logoColor=853bce)](https://railway.app/new/template/hROvhb 'Deploy Cheat Code to Railway, via 1-Click Script') [![Deploy Cheat Code to Vercel](https://img.shields.io/badge/Deploy-Vercel-%23ffffff?style=for-the-badge&logo=vercel&labelColor=1e0e41)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Flissy93%2Fcheat-code&env=GITHUB_TOKEN,TWITTER_TOKEN&project-name=cheat-code&repository-name=cheat-code_My-Developer-Portfolio 'Deploy Cheat Code to Vercel, via 1-Click Script') 47 | 48 | ### Docker Deploy 49 | 50 | There's a multi-arch [`Dockerfile`](https://github.com/Lissy93/cheat-code/blob/master/Dockerfile). 51 | 52 | --- 53 | 54 | ## Community 55 | 56 | ### Report an Issue 57 | 58 | Found something that's not working? [Open an issue](https://github.com/Lissy93/cheat-code/issues/new/choose), and describe the problem, steps to reproduce alond with expected and actual output. If relevant, also include details about your environment. I'll try and fix / respond to any tickets within 48-hours. 59 | 60 | ### Contributing 61 | 62 | Contributions of any kind are very welcome, and would be much appreciated. 63 | For Code of Conduct, see [Contributor Convent](https://www.contributor-covenant.org/version/2/1/code_of_conduct/). 64 | 65 | To get started, fork the repo, make your changes, add, commit and push the code, then come back here to open a pull request. If you're new to GitHub or open source, [this guide](https://www.freecodecamp.org/news/how-to-make-your-first-pull-request-on-github-3#let-s-make-our-first-pull-request-) or the [git docs](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) may help you get started, but feel free to reach out if you need any support. 66 | 67 | [![Submit a PR](https://img.shields.io/badge/Submit_a_PR-GitHub-%23060606?style=for-the-badge&logo=github&logoColor=fff)](https://github.com/Lissy93/cheat-code/compare) 68 | 69 | ### Support 70 | 71 | [![Sponsor Lissy93 on GitHub](https://img.shields.io/badge/Sponsor_on_GitHub-Lissy93-%23ff4dda?style=for-the-badge&logo=githubsponsors&logoColor=ff4dda)](https://github.com/sponsors/Lissy93) 72 | 73 | --- 74 | 75 | ## License 76 | 77 | > _**[Lissy93/Cheat-Code](https://github.com/Lissy93/cheat-code)** is licensed under [MIT](https://gist.github.com/Lissy93/143d2ee01ccc5c052a17) © [Alicia Sykes](https://aliciasykes.com) 2022._
> For information, see TLDR Legal > MIT 78 | 79 |
80 | Expand License 81 | 82 | ``` 83 | The MIT License (MIT) 84 | Copyright (c) Alicia Sykes 85 | 86 | Permission is hereby granted, free of charge, to any person obtaining a copy 87 | of this software and associated documentation files (the "Software"), to deal 88 | in the Software without restriction, including without limitation the rights 89 | to use, copy, modify, merge, publish, distribute, sub-license, and/or sell 90 | copies of the Software, and to permit persons to whom the Software is furnished 91 | to do so, subject to the following conditions: 92 | 93 | The above copyright notice and this permission notice shall be included install 94 | copies or substantial portions of the Software. 95 | 96 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 97 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANT ABILITY, FITNESS FOR A 98 | PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 99 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 100 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 101 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 102 | ``` 103 | 104 |
105 | 106 | --- 107 | 108 | 109 |

110 | © Alicia Sykes 2023
111 | Licensed under MIT
112 |
113 | Thanks for visiting :) 114 |

115 | 116 | 117 | 129 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | # Confliguration file for deploying Cheat-Code to Netlify 2 | # Without the need to set anything in through the UI 3 | # Docs: https://netlify.com/docs/netlify-toml-reference/ 4 | 5 | # Main site config 6 | [build] 7 | base = "/" 8 | command = "npm run build" 9 | publish = "build/" 10 | functions = "functions/" 11 | 12 | # Meta config, for the 1-Click deploy listing 13 | [template.environment] 14 | STATUSKIT_PAGE_TITLE = "Cheat-Code" 15 | STATUSKIT_COMPANY_LOGO = "https://github.com/Lissy93/cheat-code/raw/master/static/pwa/android-chrome-512x512.png" 16 | STATUSKIT_SUPPORT_CONTACT_LINK = "https://github.com/lissy93/cheat-code" 17 | STATUSKIT_RESOURCES_LINK = "https://github.com/lissy93/cheat-code" 18 | 19 | # Set any security headers here 20 | [[headers]] 21 | for = "/*" 22 | [headers.values] 23 | # Uncomment to enable Netlify user control. Requires premium plan. 24 | # Basic-Auth = "someuser:somepassword anotheruser:anotherpassword" 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "i-cant-code", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "dev": "vite dev", 7 | "build": "vite build", 8 | "preview": "vite preview", 9 | "test": "playwright test", 10 | "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", 11 | "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", 12 | "test:unit": "vitest", 13 | "lint": "prettier --plugin-search-dir . --check . && eslint .", 14 | "format": "prettier --plugin-search-dir . --write ." 15 | }, 16 | "devDependencies": { 17 | "@playwright/test": "^1.28.1", 18 | "@sveltejs/adapter-auto": "^1.0.0", 19 | "@sveltejs/adapter-netlify": "^2.0.6", 20 | "@sveltejs/adapter-node": "^1.2.3", 21 | "@sveltejs/adapter-vercel": "^2.4.0", 22 | "@sveltejs/kit": "^1.0.0", 23 | "@typescript-eslint/eslint-plugin": "^5.45.0", 24 | "@typescript-eslint/parser": "^5.45.0", 25 | "eslint": "^8.28.0", 26 | "eslint-config-prettier": "^8.5.0", 27 | "eslint-plugin-svelte3": "^4.0.0", 28 | "openai": "^3.2.1", 29 | "prettier": "^2.8.0", 30 | "prettier-plugin-svelte": "^2.8.1", 31 | "sass": "^1.57.0", 32 | "svelte": "^3.54.0", 33 | "svelte-check": "^2.9.2", 34 | "svelte-markdown": "^0.2.3", 35 | "tslib": "^2.4.1", 36 | "typescript": "^4.9.3", 37 | "vite": "^4.0.0", 38 | "vitest": "^0.25.3" 39 | }, 40 | "type": "module" 41 | } 42 | -------------------------------------------------------------------------------- /playwright.config.ts: -------------------------------------------------------------------------------- 1 | import type { PlaywrightTestConfig } from '@playwright/test'; 2 | 3 | const config: PlaywrightTestConfig = { 4 | webServer: { 5 | command: 'npm run build && npm run preview', 6 | port: 4173, 7 | }, 8 | testDir: 'tests', 9 | }; 10 | 11 | export default config; 12 | -------------------------------------------------------------------------------- /src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %sveltekit.head% 8 | 9 | 10 |
%sveltekit.body%
11 | 12 | 13 | -------------------------------------------------------------------------------- /src/data/MessageLogStore.ts: -------------------------------------------------------------------------------- 1 | import { writable } from 'svelte/store'; 2 | import type { MessageLog } from '$/types/chat.types'; 3 | import { proompts } from '$/data/proompts'; 4 | 5 | const tabs = ['Refactor', 'Find Bug', 'Explain', 'Generate'] as const; 6 | 7 | const initialMessages: MessageLog = tabs.reduce((acc, tab) => { 8 | acc[tab] = [{ role: 'system', content: proompts[tab] }]; 9 | return acc; 10 | }, {} as MessageLog); 11 | 12 | export const messageLog = writable(initialMessages); 13 | -------------------------------------------------------------------------------- /src/data/TabDescriptions.ts: -------------------------------------------------------------------------------- 1 | import type { Descriptions } from '$/types/chat.types'; 2 | 3 | export const descriptions: Descriptions = { 4 | Refactor: { 5 | intro: 6 | 'The refactor tool will improve your pasted code, to make it more readable, efficient, or maintainable.', 7 | placeholder: 'Paste your code to refactor here...', 8 | btnText: 'Improve!', 9 | }, 10 | 'Find Bug': { 11 | intro: 12 | 'The bug finding tool, will identify any issues that may be causing your code to fail, and suggest fixes.', 13 | placeholder: 'Paste your code to debug here...', 14 | btnText: 'Fix!', 15 | }, 16 | Explain: { 17 | intro: 18 | 'The code explainer tool, will attempt to explain what your code is doing, and how it works.', 19 | placeholder: 20 | "Paste your code to generate an explanation of what's happening...", 21 | btnText: 'Explain!', 22 | }, 23 | Generate: { 24 | intro: 25 | 'The generate tool, will generate code in your given language, based on your inputted prompt. You can also use this to generate code from a given example.', 26 | placeholder: 'Write a prompt to generate code from here...', 27 | btnText: 'Generate!', 28 | }, 29 | }; 30 | -------------------------------------------------------------------------------- /src/data/proompts.ts: -------------------------------------------------------------------------------- 1 | import type { tabs } from '$/types/chat.types.d'; 2 | 3 | type Proompts = { 4 | [tab in typeof tabs[number]]: string; 5 | }; 6 | 7 | const appendToPrompt = ` 8 | Please start with the code, and add explanation after. 9 | If I send you anything that is not code, please ignore it, and say so. 10 | Please avoid conversation words, like Sure / Happy to help / No problem / etc. 11 | `; 12 | 13 | export const proompts: { 14 | [tab in typeof tabs[number]]: string; 15 | } = { 16 | Refactor: ` 17 | I would like you to act as a code reviewer, and refactor code snippets. 18 | Please analyze the code, identify issues and areas for improvement, and suggest changes. 19 | Apply refactoring techniques, test and validate the changes, and explain your reasoning. 20 | ${appendToPrompt} 21 | `, 22 | 'Find Bug': ` 23 | I'm developing software and I need you help me to find and 24 | fix all the errors in my code, following the best practices. I'll provide you my code 25 | and you'll give me the code with all the corrections explained line by line 26 | ${appendToPrompt} 27 | `, 28 | Explain: ` 29 | I would like you to act as a teacher, and explain code snippets. 30 | I need to understand how the code works, and what each line does. 31 | ${appendToPrompt} 32 | `, 33 | Generate: ` 34 | I would like you to generate functional code snippets for me. 35 | I'll provide you with a description of what I need, and you'll give me the code. 36 | ${appendToPrompt} 37 | `, 38 | }; 39 | -------------------------------------------------------------------------------- /src/index.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, it, expect } from 'vitest'; 2 | 3 | describe('sum test', () => { 4 | it('adds 1 + 2 to equal 3', () => { 5 | expect(1 + 2).toBe(3); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/lib/Footer.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 | 29 | 30 | 60 | -------------------------------------------------------------------------------- /src/lib/Icon.svelte: -------------------------------------------------------------------------------- 1 | 53 | 54 | 62 | {@html displayIcon?.svg} 63 | 64 | 65 | 86 | -------------------------------------------------------------------------------- /src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | Cheat_Code 10 | 11 | 12 | 13 | 14 | 15 |