├── .env.local.template ├── .eslintrc.json ├── .github └── workflows │ └── autopr.yml ├── .gitignore ├── LICENSE ├── README.md ├── jest.config.js ├── jest.setup.js ├── next.config.js ├── package-lock.json ├── package.json ├── postcss.config.js ├── public ├── favicon.ico └── vercel.svg ├── src ├── components │ ├── CopyButton.tsx │ └── TextArea.tsx ├── pages │ ├── __snapshots__ │ │ └── index.test.jsx.snap │ ├── _app.tsx │ ├── _document.tsx │ ├── api │ │ ├── date-detection.ts │ │ └── improve.ts │ ├── copy-editor.tsx │ ├── date-detection.tsx │ ├── index.test.jsx │ └── index.tsx └── styles │ └── globals.css ├── tailwind.config.js └── tsconfig.json /.env.local.template: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY= 2 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /.github/workflows/autopr.yml: -------------------------------------------------------------------------------- 1 | on: 2 | issues: 3 | types: [labeled] 4 | 5 | permissions: 6 | contents: write 7 | issues: write 8 | pull-requests: write 9 | 10 | jobs: 11 | autopr: 12 | if: ${{ contains( github.event.label.name, 'AutoPR') }} 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Install jq 16 | run: sudo apt-get install jq 17 | - name: Check if label was added by a collaborator 18 | env: 19 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 20 | run: | 21 | is_collaborator=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ 22 | "https://api.github.com/repos/${{ github.repository }}/collaborators/${{ github.event.sender.login }}" | jq -r '.message') 23 | if [ "$is_collaborator" == "Not Found" ]; then 24 | echo "Label not added by a collaborator. Skipping action." 25 | exit 78 26 | fi 27 | - name: Checkout 28 | uses: actions/checkout@v2 29 | with: 30 | ref: main 31 | fetch-depth: 1 32 | - name: AutoPR 33 | uses: docker://ghcr.io/irgolic/autopr:latest 34 | env: 35 | OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} 36 | with: 37 | github_token: ${{ secrets.GITHUB_TOKEN }} 38 | model: gpt-3.5-turbo 39 | context_limit: 4096 40 | -------------------------------------------------------------------------------- /.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 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env*.local 29 | 30 | # vercel 31 | .vercel 32 | 33 | # typescript 34 | *.tsbuildinfo 35 | next-env.d.ts 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Jordan Scales 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## magic-editor 2 | 3 | LLM-powered experiments in writing. 4 | 5 | ### copy editing 6 | 7 | https://user-images.githubusercontent.com/287268/235374566-79eff59a-9e73-4323-8144-c8683a59716e.mov 8 | 9 | ### date detection 10 | 11 | https://user-images.githubusercontent.com/287268/236683875-8bb83a41-800f-4acb-ab28-ec15f089055f.mov 12 | 13 | ### usage 14 | 15 | * npm install 16 | * copy .env.local.template to .env.local and populate with OpenAI key 17 | * npm run dev 18 | 19 | ### license 20 | 21 | MIT 22 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | const nextJest = require("next/jest"); 2 | 3 | const createJestConfig = nextJest({ 4 | // Provide the path to your Next.js app to load next.config.js and .env files in your test environment 5 | dir: "./", 6 | }); 7 | 8 | // Add any custom config to be passed to Jest 9 | const customJestConfig = { 10 | setupFilesAfterEnv: ["/jest.setup.js"], 11 | testEnvironment: "jest-environment-jsdom", 12 | }; 13 | 14 | // createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async 15 | module.exports = createJestConfig(customJestConfig); 16 | -------------------------------------------------------------------------------- /jest.setup.js: -------------------------------------------------------------------------------- 1 | // Optional: configure or set up a testing framework before each test. 2 | // If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js` 3 | 4 | // Used for __tests__/testing-library.js 5 | // Learn more: https://github.com/testing-library/jest-dom 6 | import "@testing-library/jest-dom/extend-expect"; 7 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | reactStrictMode: true, 4 | } 5 | 6 | module.exports = nextConfig 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "copyediting", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint", 10 | "test": "jest" 11 | }, 12 | "dependencies": { 13 | "@types/node": "18.16.3", 14 | "@types/react": "18.2.0", 15 | "@types/react-dom": "18.2.1", 16 | "autoprefixer": "10.4.14", 17 | "dedent": "^0.7.0", 18 | "diff-match-patch": "^1.0.5", 19 | "eslint": "8.39.0", 20 | "eslint-config-next": "13.3.2", 21 | "next": "13.3.2", 22 | "openai": "^3.2.1", 23 | "postcss": "8.4.23", 24 | "react": "18.2.0", 25 | "react-dom": "18.2.0", 26 | "tailwindcss": "3.3.2", 27 | "typescript": "5.0.4" 28 | }, 29 | "devDependencies": { 30 | "@testing-library/jest-dom": "^5.16.5", 31 | "@types/dedent": "^0.7.0", 32 | "@types/diff-match-patch": "^1.0.32", 33 | "jest": "^29.5.0", 34 | "jest-environment-jsdom": "^29.5.0", 35 | "react-test-renderer": "^18.2.0" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdan/magic-editor/960f57ce8d67dcb5fed94030413c71f234a103f1/public/favicon.ico -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/components/CopyButton.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | export function CopyButton(props: { text: string }) { 4 | const [copyLabel, setCopyLabel] = useState("Copy"); 5 | 6 | return ( 7 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /src/components/TextArea.tsx: -------------------------------------------------------------------------------- 1 | interface Props { 2 | value: string; 3 | onChange: (value: string) => void; 4 | onKeyDown: (e: React.KeyboardEvent) => void; 5 | } 6 | 7 | export function TextArea({ value, onChange, onKeyDown }: Props) { 8 | return ( 9 |