├── app ├── favicon.ico ├── (chat) │ └── api │ │ ├── history │ │ └── route.ts │ │ ├── suggestions │ │ └── route.ts │ │ ├── vote │ │ └── route.ts │ │ ├── files │ │ └── upload │ │ │ └── route.ts │ │ ├── document │ │ └── route.ts │ │ └── chat │ │ └── route.ts ├── (papers) │ ├── api │ │ ├── suggested-questions │ │ │ └── route.ts │ │ ├── papers │ │ │ └── route.ts │ │ └── papers.ts │ └── papers │ │ └── [id] │ │ ├── backbutton.tsx │ │ ├── chat │ │ └── page.tsx │ │ └── page.tsx ├── layout.tsx ├── globals.css └── page.tsx ├── public ├── fonts │ ├── geist.woff2 │ └── geist-mono.woff2 └── images │ ├── cerebras-logo.png │ └── demo-thumbnail.png ├── src └── types │ └── weave.d.ts ├── ai ├── custom-middleware.ts ├── index.ts ├── models.ts └── prompts.ts ├── postcss.config.mjs ├── prettier.config.cjs ├── next-env.d.ts ├── .env.example ├── components ├── ui │ ├── skeleton.tsx │ ├── label.tsx │ ├── textarea.tsx │ ├── separator.tsx │ ├── input.tsx │ ├── tooltip.tsx │ ├── button.tsx │ ├── card.tsx │ ├── sheet.tsx │ ├── alert-dialog.tsx │ ├── select.tsx │ └── dropdown-menu.tsx └── custom │ ├── theme-provider.tsx │ ├── sign-out-form.tsx │ ├── document-skeleton.tsx │ ├── sidebar-toggle.tsx │ ├── submit-button.tsx │ ├── use-scroll-to-bottom.ts │ ├── block-stream-handler.tsx │ ├── preview-attachment.tsx │ ├── overview.tsx │ ├── auth-form.tsx │ ├── sidebar-user-nav.tsx │ ├── suggestion.tsx │ ├── app-sidebar.tsx │ ├── chat-header.tsx │ ├── model-selector.tsx │ ├── use-block-stream.tsx │ ├── document.tsx │ ├── diffview.tsx │ ├── version-footer.tsx │ ├── markdown.tsx │ ├── chat.tsx │ ├── editor.tsx │ ├── message-actions.tsx │ ├── message.tsx │ ├── weather.tsx │ └── multimodal-input.tsx ├── lib ├── editor │ ├── react-renderer.tsx │ ├── config.ts │ ├── functions.tsx │ └── suggestions.tsx ├── drizzle │ ├── meta │ │ ├── _journal.json │ │ ├── 0000_snapshot.json │ │ └── 0001_snapshot.json │ ├── 0000_keen_devos.sql │ ├── 0002_wandering_riptide.sql │ └── 0001_sparkling_blue_marvel.sql └── utils.ts ├── drizzle.config.ts ├── components.json ├── next.config.ts ├── .gitignore ├── LICENSE ├── hooks └── use-mobile.tsx ├── tsconfig.json ├── db ├── migrate.ts └── schema.ts ├── .eslintrc.json ├── README.md ├── tailwind.config.ts └── package.json /app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altryne/cerebras-neurips-2024-chatbot/main/app/favicon.ico -------------------------------------------------------------------------------- /public/fonts/geist.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altryne/cerebras-neurips-2024-chatbot/main/public/fonts/geist.woff2 -------------------------------------------------------------------------------- /public/fonts/geist-mono.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altryne/cerebras-neurips-2024-chatbot/main/public/fonts/geist-mono.woff2 -------------------------------------------------------------------------------- /public/images/cerebras-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altryne/cerebras-neurips-2024-chatbot/main/public/images/cerebras-logo.png -------------------------------------------------------------------------------- /public/images/demo-thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altryne/cerebras-neurips-2024-chatbot/main/public/images/demo-thumbnail.png -------------------------------------------------------------------------------- /src/types/weave.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'weave' { 2 | // You can leave this empty if you just need TypeScript to recognize the module 3 | } -------------------------------------------------------------------------------- /ai/custom-middleware.ts: -------------------------------------------------------------------------------- 1 | import { Experimental_LanguageModelV1Middleware } from 'ai'; 2 | 3 | export const customMiddleware: Experimental_LanguageModelV1Middleware = {}; 4 | -------------------------------------------------------------------------------- /postcss.config.mjs: -------------------------------------------------------------------------------- 1 | /** @type {import('postcss-load-config').Config} */ 2 | const config = { 3 | plugins: { 4 | tailwindcss: {}, 5 | }, 6 | }; 7 | 8 | export default config; 9 | -------------------------------------------------------------------------------- /prettier.config.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import('prettier').Config} */ 2 | module.exports = { 3 | endOfLine: 'lf', 4 | semi: true, 5 | useTabs: false, 6 | singleQuote: true, 7 | tabWidth: 2, 8 | trailingComma: 'es5', 9 | }; 10 | -------------------------------------------------------------------------------- /next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information. 6 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # Get your OpenAI API Key here: https://platform.openai.com/account/api-keys 2 | CEREBRAS_API_KEY=****** 3 | 4 | # Instructions to create a database here: https://vercel.com/docs/storage/vercel-postgres/quickstart 5 | POSTGRES_URL=****** 6 | 7 | HUGGINGFACE_API_KEY=****** 8 | 9 | WANDB_API_KEY=****** 10 | -------------------------------------------------------------------------------- /components/ui/skeleton.tsx: -------------------------------------------------------------------------------- 1 | import { cn } from "@/lib/utils" 2 | 3 | function Skeleton({ 4 | className, 5 | ...props 6 | }: React.HTMLAttributes) { 7 | return ( 8 |
12 | ) 13 | } 14 | 15 | export { Skeleton } 16 | -------------------------------------------------------------------------------- /lib/editor/react-renderer.tsx: -------------------------------------------------------------------------------- 1 | import { createRoot } from 'react-dom/client'; 2 | 3 | export class ReactRenderer { 4 | static render(component: React.ReactElement, dom: HTMLElement) { 5 | const root = createRoot(dom); 6 | root.render(component); 7 | 8 | return { 9 | destroy: () => root.unmount(), 10 | }; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /components/custom/theme-provider.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import { ThemeProvider as NextThemesProvider } from 'next-themes'; 4 | import { type ThemeProviderProps } from 'next-themes/dist/types'; 5 | 6 | export function ThemeProvider({ children, ...props }: ThemeProviderProps) { 7 | return {children}; 8 | } 9 | -------------------------------------------------------------------------------- /drizzle.config.ts: -------------------------------------------------------------------------------- 1 | import { config } from "dotenv"; 2 | import { defineConfig } from "drizzle-kit"; 3 | 4 | config({ 5 | path: ".env.local", 6 | }); 7 | 8 | export default defineConfig({ 9 | schema: "./db/schema.ts", 10 | out: "./lib/drizzle", 11 | dialect: "postgresql", 12 | dbCredentials: { 13 | url: process.env.POSTGRES_URL!, 14 | }, 15 | }); 16 | -------------------------------------------------------------------------------- /app/(chat)/api/history/route.ts: -------------------------------------------------------------------------------- 1 | import { getChatsByUserId } from '@/db/queries'; 2 | 3 | export async function GET() { 4 | const session = null; 5 | 6 | if (!session || !session.user) { 7 | return Response.json('Unauthorized!', { status: 401 }); 8 | } 9 | 10 | const chats = await getChatsByUserId({ id: session.user.id! }); 11 | return Response.json(chats); 12 | } 13 | -------------------------------------------------------------------------------- /components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "default", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.ts", 8 | "css": "app/globals.css", 9 | "baseColor": "zinc", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils", 16 | "ui": "@/components/ui", 17 | "lib": "@/lib", 18 | "hooks": "@/hooks" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /components/custom/sign-out-form.tsx: -------------------------------------------------------------------------------- 1 | import Form from 'next/form'; 2 | 3 | export const SignOutForm = () => { 4 | return ( 5 |
{ 8 | 'use server'; 9 | 10 | // await signOut({ 11 | // redirectTo: '/', 12 | // }); 13 | }} 14 | > 15 | 21 |
22 | ); 23 | }; 24 | -------------------------------------------------------------------------------- /ai/index.ts: -------------------------------------------------------------------------------- 1 | import { experimental_wrapLanguageModel as wrapLanguageModel } from 'ai'; 2 | 3 | import { customMiddleware } from './custom-middleware'; 4 | 5 | import { createOpenAI} from '@ai-sdk/openai'; 6 | 7 | export const cerebras = createOpenAI({ 8 | // name: 'Cerebras', 9 | baseURL: 'https://api.cerebras.ai/v1', 10 | apiKey: process.env.CEREBRAS_API_KEY, 11 | }); 12 | 13 | export const customModel = (apiIdentifier: string) => { 14 | return wrapLanguageModel({ 15 | model: cerebras(apiIdentifier), 16 | middleware: customMiddleware, 17 | }); 18 | }; 19 | -------------------------------------------------------------------------------- /next.config.ts: -------------------------------------------------------------------------------- 1 | import type { NextConfig } from 'next'; 2 | 3 | const nextConfig: NextConfig = { 4 | typescript: { 5 | ignoreBuildErrors: true, 6 | }, 7 | eslint: { 8 | ignoreDuringBuilds: true, 9 | }, 10 | experimental: { 11 | ppr: true, 12 | }, 13 | images: { 14 | remotePatterns: [ 15 | { 16 | hostname: 'avatar.vercel.sh', 17 | }, 18 | { 19 | hostname: 'picsum.photos', 20 | }, 21 | { 22 | hostname: 'source.unsplash.com', 23 | }, 24 | ], 25 | }, 26 | }; 27 | export default nextConfig; 28 | -------------------------------------------------------------------------------- /.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 | build 15 | 16 | # misc 17 | .DS_Store 18 | *.pem 19 | 20 | # debug 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | .pnpm-debug.log* 25 | 26 | # local env files 27 | .env.local 28 | .env.development.local 29 | .env.test.local 30 | .env.production.local 31 | 32 | # turbo 33 | .turbo 34 | 35 | .env 36 | .vercel 37 | .vscode 38 | .env*.local 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2024 Vercel, Inc. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /lib/drizzle/meta/_journal.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "7", 3 | "dialect": "postgresql", 4 | "entries": [ 5 | { 6 | "idx": 0, 7 | "version": "7", 8 | "when": 1728598022383, 9 | "tag": "0000_keen_devos", 10 | "breakpoints": true 11 | }, 12 | { 13 | "idx": 1, 14 | "version": "7", 15 | "when": 1730207363999, 16 | "tag": "0001_sparkling_blue_marvel", 17 | "breakpoints": true 18 | }, 19 | { 20 | "idx": 2, 21 | "version": "7", 22 | "when": 1730725226313, 23 | "tag": "0002_wandering_riptide", 24 | "breakpoints": true 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /hooks/use-mobile.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | const MOBILE_BREAKPOINT = 768 4 | 5 | export function useIsMobile() { 6 | const [isMobile, setIsMobile] = React.useState(undefined) 7 | 8 | React.useEffect(() => { 9 | const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`) 10 | const onChange = () => { 11 | setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) 12 | } 13 | mql.addEventListener("change", onChange) 14 | setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) 15 | return () => mql.removeEventListener("change", onChange) 16 | }, []) 17 | 18 | return !!isMobile 19 | } 20 | -------------------------------------------------------------------------------- /ai/models.ts: -------------------------------------------------------------------------------- 1 | // Define your models here. 2 | 3 | export interface Model { 4 | id: string; 5 | label: string; 6 | apiIdentifier: string; 7 | description: string; 8 | } 9 | 10 | export const models: Array = [ 11 | { 12 | id: 'llama3.1-8b', 13 | label: 'Llama 3.1 8b', 14 | apiIdentifier: 'llama3.1-8b', 15 | description: 'Small model for lighting fast responses.', 16 | }, 17 | { 18 | id: 'llama3.1-70b', 19 | label: 'Llama 3.1 70b', 20 | apiIdentifier: 'llama3.1-8b', 21 | description: 'Larger model for more complex tasks.', 22 | }, 23 | ] as const; 24 | 25 | export const DEFAULT_MODEL_NAME: string = 'llama3.1-70b'; 26 | -------------------------------------------------------------------------------- /app/(papers)/api/suggested-questions/route.ts: -------------------------------------------------------------------------------- 1 | import { getSuggestedQuestions } from '@/db/queries'; 2 | 3 | export async function GET(request: Request) { 4 | const { searchParams } = new URL(request.url); 5 | const id = searchParams.get('id') ?? undefined; 6 | 7 | try { 8 | if (!id) { 9 | return new Response('Bad Request', { status: 400 }); 10 | } 11 | 12 | const suggestions = await getSuggestedQuestions({ id: id }); 13 | return Response.json(suggestions, { status: 200 }); 14 | } catch (error) { 15 | console.error('Error fetching papers:', error); 16 | return new Response('Internal Server Error', { status: 500 }); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/drizzle/0000_keen_devos.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS "Chat" ( 2 | "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, 3 | "createdAt" timestamp NOT NULL, 4 | "messages" json NOT NULL, 5 | "userId" uuid NOT NULL 6 | ); 7 | --> statement-breakpoint 8 | CREATE TABLE IF NOT EXISTS "User" ( 9 | "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, 10 | "email" varchar(64) NOT NULL, 11 | "password" varchar(64) 12 | ); 13 | --> statement-breakpoint 14 | DO $$ BEGIN 15 | ALTER TABLE "Chat" ADD CONSTRAINT "Chat_userId_User_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE no action ON UPDATE no action; 16 | EXCEPTION 17 | WHEN duplicate_object THEN null; 18 | END $$; 19 | -------------------------------------------------------------------------------- /app/(papers)/api/papers/route.ts: -------------------------------------------------------------------------------- 1 | import { getPapers } from '@/db/queries'; 2 | 3 | export async function GET(request: Request) { 4 | const { searchParams } = new URL(request.url); 5 | const id = searchParams.get('id') ?? undefined; 6 | const query = searchParams.get('query') ?? undefined; 7 | 8 | try { 9 | const papers = query ? await getPapers({ query }) : await getPapers({ id }); 10 | 11 | if (!papers || papers.length === 0) { 12 | return new Response('Not Found', { status: 404 }); 13 | } 14 | 15 | return Response.json(papers, { status: 200 }); 16 | } catch (error) { 17 | console.error('Error fetching papers:', error); 18 | return new Response('Internal Server Error', { status: 500 }); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/(papers)/api/papers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | deleteDocumentsByIdAfterTimestamp, 3 | getDocumentsById, 4 | getPapers, 5 | saveDocument, 6 | } from '@/db/queries'; 7 | 8 | export async function GET(request: Request) { 9 | const { searchParams } = new URL(request.url); 10 | const id = searchParams.get('id') ?? undefined; 11 | const query = searchParams.get('id') ?? undefined; 12 | 13 | try { 14 | const papers = await getPapers({ id }); 15 | 16 | if (!papers || papers.length === 0) { 17 | return new Response('Not Found', { status: 404 }); 18 | } 19 | 20 | return Response.json(papers, { status: 200 }); 21 | } catch (error) { 22 | console.error('Error fetching papers:', error); 23 | return new Response('Internal Server Error', { status: 500 }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /components/custom/document-skeleton.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | export const DocumentSkeleton = () => { 4 | return ( 5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | ); 15 | }; 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "noEmit": true, 9 | "esModuleInterop": true, 10 | "module": "esnext", 11 | "moduleResolution": "bundler", 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "jsx": "preserve", 15 | "incremental": true, 16 | "plugins": [ 17 | { 18 | "name": "next" 19 | } 20 | ], 21 | "paths": { 22 | "@/*": ["./*"] 23 | } 24 | }, 25 | "include": [ 26 | "next-env.d.ts", 27 | "**/*.ts", 28 | "**/*.tsx", 29 | ".next/types/**/*.ts", 30 | "next.config.js" 31 | , "app/(papers)/papers/[id]" ], 32 | "exclude": ["node_modules"] 33 | } 34 | -------------------------------------------------------------------------------- /components/custom/sidebar-toggle.tsx: -------------------------------------------------------------------------------- 1 | import { ComponentProps } from 'react'; 2 | 3 | import { SidebarTrigger, useSidebar } from '@/components/ui/sidebar'; 4 | import { BetterTooltip } from '@/components/ui/tooltip'; 5 | import { cn } from '@/lib/utils'; 6 | 7 | import { SidebarLeftIcon } from './icons'; 8 | import { Button } from '../ui/button'; 9 | 10 | export function SidebarToggle({ 11 | className, 12 | }: ComponentProps) { 13 | const { toggleSidebar } = useSidebar(); 14 | 15 | return ( 16 | 17 | 24 | 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /components/ui/label.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as LabelPrimitive from "@radix-ui/react-label" 5 | import { cva, type VariantProps } from "class-variance-authority" 6 | 7 | import { cn } from "@/lib/utils" 8 | 9 | const labelVariants = cva( 10 | "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" 11 | ) 12 | 13 | const Label = React.forwardRef< 14 | React.ElementRef, 15 | React.ComponentPropsWithoutRef & 16 | VariantProps 17 | >(({ className, ...props }, ref) => ( 18 | 23 | )) 24 | Label.displayName = LabelPrimitive.Root.displayName 25 | 26 | export { Label } 27 | -------------------------------------------------------------------------------- /components/custom/submit-button.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import { useFormStatus } from 'react-dom'; 4 | 5 | import { LoaderIcon } from '@/components/custom/icons'; 6 | 7 | import { Button } from '../ui/button'; 8 | 9 | export function SubmitButton({ children }: { children: React.ReactNode }) { 10 | const { pending } = useFormStatus(); 11 | 12 | return ( 13 | 29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /components/ui/textarea.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { cn } from "@/lib/utils" 4 | 5 | export interface TextareaProps 6 | extends React.TextareaHTMLAttributes {} 7 | 8 | const Textarea = React.forwardRef( 9 | ({ className, ...props }, ref) => { 10 | return ( 11 |