├── .eslintrc.json ├── src ├── app │ ├── favicon.ico │ ├── page.tsx │ ├── layout.tsx │ ├── globals.css │ └── api │ │ ├── completion │ │ └── route.ts │ │ ├── chat │ │ └── route.ts │ │ └── generate │ │ └── route.ts ├── pages │ ├── about.tsx │ ├── _app.tsx │ ├── chat.tsx │ └── check.tsx └── components │ ├── pages-layout.tsx │ └── editor │ ├── data.ts │ ├── utils.ts │ └── editor.tsx ├── postcss.config.js ├── next.config.js ├── .env.example ├── .gitignore ├── tailwind.config.js ├── public ├── vercel.svg └── next.svg ├── tsconfig.json ├── package.json ├── LICENSE └── README.md /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LlamaGenAI/note-ai/HEAD/src/app/favicon.ico -------------------------------------------------------------------------------- /src/pages/about.tsx: -------------------------------------------------------------------------------- 1 | export default function About() { 2 | return
About
; 3 | } 4 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { reactStrictMode: true }; 3 | 4 | module.exports = nextConfig; 5 | -------------------------------------------------------------------------------- /src/app/page.tsx: -------------------------------------------------------------------------------- 1 | import dynamic from "next/dynamic"; 2 | const Editor = dynamic(() => import("@/components/editor/editor"), { 3 | ssr: false, 4 | }); 5 | 6 | export default function Home() { 7 | return ( 8 |
9 | 10 |
11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import Layout from "../components/pages-layout"; 2 | import { AppProps } from "next/app"; 3 | export default function MyApp({ Component, pageProps }: AppProps) { 4 | return ( 5 | 6 | 7 | 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/components/pages-layout.tsx: -------------------------------------------------------------------------------- 1 | import "./../app/globals.css"; 2 | import { ReactNode } from "react"; 3 | interface LayoutProps { 4 | children: ReactNode; 5 | } 6 | export default function Layout({ children }: LayoutProps) { 7 | return ( 8 | <> 9 |
{children}
10 | 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # Get your OpenAI API key here: https://platform.openai.com/account/api-keys 2 | OPENAI_API_KEY= 3 | 4 | # OPTIONAL: Vercel Blob (for uploading images) 5 | # Get your Vercel Blob credentials here: https://vercel.com/docs/storage/vercel-blob/quickstart#quickstart 6 | BLOB_READ_WRITE_TOKEN= 7 | 8 | # OPTIONAL: Vercel KV (for ratelimiting) 9 | # Get your Vercel KV credentials here: https://vercel.com/docs/storage/vercel-kv/quickstart#quickstart 10 | KV_REST_API_URL= 11 | KV_REST_API_TOKEN= 12 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import './globals.css' 2 | import type { Metadata } from 'next' 3 | import { Inter } from 'next/font/google' 4 | 5 | const inter = Inter({ subsets: ['latin'] }) 6 | 7 | export const metadata: Metadata = { 8 | title: 'Create Next App', 9 | description: 'Generated by create next app', 10 | } 11 | 12 | export default function RootLayout({ 13 | children, 14 | }: { 15 | children: React.ReactNode 16 | }) { 17 | return ( 18 | 19 | {children} 20 | 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | "./src/pages/**/*.{js,ts,jsx,tsx,mdx}", 5 | "./src/components/**/*.{js,ts,jsx,tsx,mdx}", 6 | "./src/app/**/*.{js,ts,jsx,tsx,mdx}", 7 | ], 8 | theme: { 9 | extend: { 10 | backgroundImage: { 11 | "gradient-radial": "radial-gradient(var(--tw-gradient-stops))", 12 | "gradient-conic": 13 | "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))", 14 | }, 15 | }, 16 | }, 17 | plugins: [], 18 | }; 19 | -------------------------------------------------------------------------------- /src/app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | html { 6 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, 7 | Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif; 8 | font-size: 16px; 9 | line-height: 1.5; 10 | color: #333; 11 | } 12 | 13 | body { 14 | margin: 0; 15 | padding: 0; 16 | } 17 | 18 | /* You can add global styles to this file, and also import other style files */ 19 | .affine-default-page-block-container { 20 | margin: 0 !important; 21 | padding-bottom: 15px !important; 22 | } 23 | -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "incremental": true, 17 | "plugins": [ 18 | { 19 | "name": "next" 20 | } 21 | ], 22 | "paths": { 23 | "@/*": ["./src/*"] 24 | } 25 | }, 26 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 27 | "exclude": ["node_modules"] 28 | } 29 | -------------------------------------------------------------------------------- /src/components/editor/data.ts: -------------------------------------------------------------------------------- 1 | export const presetMarkdown = `This playground is designed to: 2 | 3 | * 📝 Test basic editing experience. 4 | * ⚙️ Serve as E2E test entry. 5 | * 🔗 Demonstrate how BlockSuite reconciles real-time collaboration with [local-first](https://martin.kleppmann.com/papers/local-first.pdf) data ownership. 6 | 7 | ## Controlling Playground Data Source 8 | You might initially enter this page with the \`?init\` URL param. This is the default (opt-in) setup that automatically loads this built-in article. Meanwhile, you'll connect to a random single-user room via a WebRTC provider by default. This is the "single-user mode" for local testing.; 9 | 10 | > Note that the second and subsequent users should not open the page with the \`?init\` param in this case. Also, due to the P2P nature of WebRTC, as long as there is at least one user connected to the room, the content inside the room will **always** exist. 11 | `; 12 | -------------------------------------------------------------------------------- /src/pages/chat.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { useChat } from "ai/react"; 4 | 5 | export default function Chat() { 6 | const { messages, input, handleInputChange, handleSubmit } = useChat(); 7 | 8 | return ( 9 |
10 | {messages.map((m) => ( 11 |
12 | {m.role === "user" ? "User: " : "AI: "} 13 | {m.content} 14 |
15 | ))} 16 | 17 |
18 | 26 | 27 |
28 |
29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "note-ai", 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 | }, 11 | "dependencies": { 12 | "@types/node": "20.4.1", 13 | "@types/react": "18.2.14", 14 | "@types/react-dom": "18.2.6", 15 | "autoprefixer": "10.4.14", 16 | "eslint": "8.44.0", 17 | "eslint-config-next": "13.4.9", 18 | "next": "13.4.9", 19 | "postcss": "8.4.25", 20 | "react": "18.2.0", 21 | "react-dom": "18.2.0", 22 | "tailwindcss": "3.3.2", 23 | "typescript": "5.1.6", 24 | "@blocksuite/blocks": "0.6.0", 25 | "@blocksuite/editor": "0.6.0", 26 | "@blocksuite/lit": "0.6.0", 27 | "@blocksuite/store": "0.6.0", 28 | "ahooks": "^3.7.7", 29 | "@upstash/ratelimit": "^0.4.3", 30 | "@vercel/kv": "^0.2.2", 31 | "ai": "^2.1.16", 32 | "openai-edge": "^1.2.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/app/api/completion/route.ts: -------------------------------------------------------------------------------- 1 | import { Configuration, OpenAIApi } from 'openai-edge' 2 | import { OpenAIStream, StreamingTextResponse } from 'ai' 3 | 4 | // Create an OpenAI API client (that's edge friendly!) 5 | const config = new Configuration({ 6 | apiKey: process.env.OPENAI_API_KEY 7 | }) 8 | const openai = new OpenAIApi(config) 9 | 10 | // IMPORTANT! Set the runtime to edge 11 | export const runtime = 'edge' 12 | 13 | export async function POST(req: Request) { 14 | // Extract the `prompt` from the body of the request 15 | const { prompt } = await req.json() 16 | 17 | // Ask OpenAI for a streaming completion given the prompt 18 | const response = await openai.createCompletion({ 19 | model: 'text-davinci-003', 20 | stream: true, 21 | prompt 22 | }) 23 | 24 | // Convert the response into a friendly text-stream 25 | const stream = OpenAIStream(response) 26 | 27 | // Respond with the stream 28 | return new StreamingTextResponse(stream) 29 | } -------------------------------------------------------------------------------- /src/app/api/chat/route.ts: -------------------------------------------------------------------------------- 1 | import { Configuration, OpenAIApi } from "openai-edge"; 2 | import { OpenAIStream, StreamingTextResponse } from "ai"; 3 | 4 | // Create an OpenAI API client (that's edge friendly!) 5 | const config = new Configuration({ 6 | apiKey: process.env.OPENAI_API_KEY, 7 | }); 8 | const openai = new OpenAIApi(config); 9 | 10 | // IMPORTANT! Set the runtime to edge 11 | export const runtime = "edge"; 12 | 13 | export async function POST(req: Request) { 14 | // Extract the `messages` from the body of the request 15 | const { messages } = await req.json(); 16 | 17 | // Ask OpenAI for a streaming chat completion given the prompt 18 | const response = await openai.createChatCompletion({ 19 | model: "gpt-3.5-turbo", 20 | stream: true, 21 | messages, 22 | }); 23 | // Convert the response into a friendly text-stream 24 | const stream = OpenAIStream(response); 25 | // Respond with the stream 26 | return new StreamingTextResponse(stream); 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 tzhangchi 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 | -------------------------------------------------------------------------------- /public/next.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/pages/check.tsx: -------------------------------------------------------------------------------- 1 | // app/page.tsx 2 | "use client"; 3 | 4 | import { useCompletion } from "ai/react"; 5 | import { useState, useCallback } from "react"; 6 | 7 | export default function PostEditorPage() { 8 | // Locally store our blog posts content 9 | const [content, setContent] = useState(""); 10 | const { complete } = useCompletion({ 11 | api: "/api/generate", 12 | }); 13 | 14 | const checkAndPublish = useCallback( 15 | async (c: string) => { 16 | const completion = await complete(c); 17 | if (!completion) throw new Error("Failed to check typos"); 18 | const typos = JSON.parse(completion); 19 | // you should more validation here to make sure the response is valid 20 | if (typos?.length && !window.confirm("Typos found… continue?")) return; 21 | else alert("Post published"); 22 | }, 23 | [complete] 24 | ); 25 | 26 | return ( 27 |
28 |

Post Editor

29 |