Repository: YOYZHANG/ai-ppt Branch: master Commit: 3443269f5776 Files: 58 Total size: 90.6 KB Directory structure: gitextract_bom1etdj/ ├── .eslintrc.json ├── .gitignore ├── LICENSE ├── README.md ├── README_CN.md ├── app/ │ ├── api/ │ │ ├── chat/ │ │ │ └── route.ts │ │ ├── convertd/ │ │ │ └── route.ts │ │ └── limit/ │ │ └── route.ts │ ├── globals.css │ ├── layout.tsx │ ├── page.tsx │ └── provider.tsx ├── components/ │ ├── artifact-view.tsx │ ├── auth-dialog.tsx │ ├── auth-form.tsx │ ├── chat.tsx │ ├── code-view.tsx │ ├── navbar.tsx │ ├── price-dialog.tsx │ ├── price.tsx │ ├── share-dialog.tsx │ ├── share.tsx │ ├── side-view.tsx │ ├── ui/ │ │ ├── alert.tsx │ │ ├── avatar.tsx │ │ ├── button.tsx │ │ ├── card.tsx │ │ ├── dialog.tsx │ │ ├── dropdown-menu.tsx │ │ ├── input.tsx │ │ ├── label.tsx │ │ ├── select.tsx │ │ ├── separator.tsx │ │ ├── skeleton.tsx │ │ ├── switch.tsx │ │ ├── tabs.tsx │ │ ├── textarea.tsx │ │ ├── toast.tsx │ │ └── toaster.tsx │ ├── user.tsx │ └── welcome.tsx ├── components.json ├── debug/ │ └── apitest.http ├── hooks/ │ └── use-toast.ts ├── lib/ │ ├── auth.ts │ ├── messages.ts │ ├── ratelimit.ts │ ├── schema.ts │ ├── supabase.ts │ ├── template.ts │ └── utils.ts ├── next.config.mjs ├── package.json ├── postcss.config.mjs ├── sandbox-templates/ │ ├── e2b.Dockerfile │ └── e2b.toml ├── tailwind.config.ts └── tsconfig.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintrc.json ================================================ { "extends": ["next/core-web-vitals"] } ================================================ FILE: .gitignore ================================================ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies /node_modules /.pnp .pnp.js .yarn/install-state.gz # testing /coverage # next.js /.next/ /out/ # production /build # misc .DS_Store *.pem # debug npm-debug.log* yarn-debug.log* yarn-error.log* # local env files .env*.local # vercel .vercel # typescript *.tsbuildinfo next-env.d.ts public/presentations ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2024 Xiaoqian Zhang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================

Welcome to RevealJS AI 👋

[中文说明](/README_CN.md) ## ✨ Demo [/public/demo.mp4](https://github.com/user-attachments/assets/d5a4b37a-553b-41b4-ba33-ad457d118311) Try it Online ⚡️: [Revealjs AI](https://ppt.revealjs.online) ## 🚀 Getting Started ### install ```sh pnpm install ``` ### set environmental values set .env.local under root dir with values list below ```sh NEXT_PUBLIC_SUPABASE_URL= NEXT_PUBLIC_SUPABASE_ANON_KEY= KV_REST_API_URL= KV_REST_API_TOKEN= GEMINI_API_KEY= ``` ### usege ```sh pnpm run dev ``` ## 💻 TechStack - [Nextjs](https://nextjs.org/docs) - Full Stack Development - [Tailwindcss](https://tailwindcss.com/) - CSS Engine - [Supabase](https://supabase.com/) - User OAuth - [Stripe](https://stripe.com/docs/development) - Payment ## 💗 Credit - [Gemini API](https://gemini.google.com/app) - AI Powered - [ai-artifacts](https://github.com/e2b-dev/ai-artifacts) - Reference ## 👤 Author **YOYZHANG** - Twitter: [@alexu19049062](https://twitter.com/alexuzhang19049062) - Github: [@YOYZHANG](https://github.com/YOYZHANG) - Wechat: whdxzxq ## 🤝 Contributing Contributions, issues and feature requests are welcome. 😄
Feel free to check [issues page](https://github.com/YOYZHANG/ai-ppt/issues) if you want to contribute.
## 📝 License MIT License © 2024 YOYZHANG ## Others Please ⭐️ this repository if this project helped you! Your appreciation is my greatest strength in updating content! Buy Me A Coffee --- ================================================ FILE: README_CN.md ================================================

欢迎来到 RevealJS AI 👋

## ✨ 示例 [/public/demo.mp4](https://github.com/user-attachments/assets/d5a4b37a-553b-41b4-ba33-ad457d118311) 在线地址: ⚡️ [Revealjs AI](https://ppt.revealjs.online) ## 🚀 快速开始 ### 安装依赖 ```sh pnpm install ``` ### 设置环境变量 set .env.local under root dir with values list below ```sh NEXT_PUBLIC_SUPABASE_URL= NEXT_PUBLIC_SUPABASE_ANON_KEY= KV_REST_API_URL= KV_REST_API_TOKEN= GEMINI_API_KEY= ``` ### 本地开发 ```sh pnpm run dev ``` ## 💻 技术栈 - [Nextjs](https://nextjs.org/docs) - Full Stack Development - [Tailwindcss](https://tailwindcss.com/) - CSS Engine - [Supabase](https://supabase.com/) - User OAuth - [Stripe](https://stripe.com/docs/development) - Payment ## 💗 感谢以下项目 - [ai-artifacts](https://github.com/e2b-dev/ai-artifacts) - Reference - [Gemini API](https://gemini.google.com/app) - AI Powered ## 👤作者 如果有任何疑问或技术上的交流,可以在 Twitter 或微信上联系我。 **YOYZHANG** - twitter: [@alexu19049062](https://twitter.com/alexuzhang19049062) - 微信: whdxzxq ## 🤝 贡献 欢迎贡献 [issues](https://github.com/YOYZHANG/ai-ppt/issues). 如果这个项目对你有帮助,欢迎 ⭐️ 或 Fork. ## 📝 License MIT License © 2024 YOYZHANG ## 👀 其他 你的赞赏是我更新内容最大的功力: Buy Me A Coffee --- ================================================ FILE: app/api/chat/route.ts ================================================ import { streamObject, LanguageModel, CoreMessage, } from 'ai' import { createGoogleGenerativeAI } from '@ai-sdk/google'; import {htmlTemplate} from '@/lib/template' import ratelimit from '@/lib/ratelimit' import { artifactSchema } from '@/lib/schema' export type LLMModel = { id: string name: string provider: string providerId: string } export type LLMModelConfig = { model?: string apiKey?: string baseURL?: string temperature?: number topP?: number topK?: number frequencyPenalty?: number presencePenalty?: number maxTokens?: number } interface Req { messages: CoreMessage[], userID: string, } export async function POST(req: Request) { const { messages } = await req.json() as Req const client = createGoogleGenerativeAI({ apiKey: process.env.GEMINI_API_KEY})('models/gemini-1.5-flash-latest') const stream = await streamObject({ model: client as LanguageModel, schema: artifactSchema, system: ` Generate a visually appealing reveal.js presentation in HTML. The presentation should include the following slides: appealing cover, bullet points with links, conclusion and end page. more than 6 slides. use the template: ${htmlTemplate} `, messages }) return stream.toTextStreamResponse() } ================================================ FILE: app/api/convertd/route.ts ================================================ import { supabase } from '@/lib/supabase'; async function uploadFileContent(fileContent: string, fileName: string) { const { data, error } = await supabase.storage .from('ppt') .upload(`public/${fileName}`, fileContent, { contentType: 'text/html', }) if (error) { console.error('covert file failed', error) return null } const { publicUrl } = supabase.storage.from('ppt').getPublicUrl(data.path).data return publicUrl } export async function POST(req: Request) { const { artifact} = await req.json() const url = await uploadFileContent(artifact.code, `ppt_${Date.now()}.html`) if (!url) { return new Response('upload ppt html failed.', { status: 403 }) } // Send file URL back to client return new Response(JSON.stringify({ url })) } ================================================ FILE: app/api/limit/route.ts ================================================ import ratelimit from '@/lib/ratelimit' export const maxDuration = 60 const rateLimitMaxRequests = 10 const ratelimitWindow = '1d' export async function GET(req: Request) { const limit = await ratelimit(req.headers.get('x-forwarded-for'), rateLimitMaxRequests, ratelimitWindow) if (limit && !limit?.success) { return new Response('You have reached your request limit for the day.', { status: 429, headers: { 'X-RateLimit-Limit': limit.amount.toString(), 'X-RateLimit-Remaining': limit.remaining.toString(), 'X-RateLimit-Reset': limit.reset.toString() } }) } return new Response(JSON.stringify(limit)) } ================================================ FILE: app/globals.css ================================================ @tailwind base; @tailwind components; @tailwind utilities; @layer base { :root { --background: 240, 6%, 10%; --foreground: 0 0% 98%; --card: 240 10% 3.9%; --card-foreground: 0 0% 98%; --popover: 240, 5%, 13%; --popover-foreground: 0 0% 98%; --primary: 0 0% 98%; --primary-foreground: 240 5.9% 10%; --secondary: 240 3.7% 15.9%; --secondary-foreground: 0 0% 98%; --muted: 240 3.7% 15.9%; --muted-foreground: 240 5% 64.9%; --accent: 240 3.7% 15.9%; --accent-foreground: 0 0% 98%; --destructive: 0 62.8% 30.6%; --destructive-foreground: 0 0% 98%; --border: 270, 2%, 19%; --input: 240 3.7% 15.9%; --ring: 240 4.9% 83.9%; --chart-1: 220 70% 50%; --chart-2: 160 60% 45%; --chart-3: 30 80% 55%; --chart-4: 280 65% 60%; --chart-5: 340 75% 55%; --radius: 0.5rem; } } @layer base { * { @apply border-border; } body { @apply bg-background text-foreground; } } ================================================ FILE: app/layout.tsx ================================================ import type { Metadata } from "next"; import "./globals.css"; import { Inter } from 'next/font/google' import { PostHogProvider } from './provider' import { ToastContainer } from "react-toastify"; const inter = Inter({ subsets: ['latin'] }) export const metadata: Metadata = { title: "AI RevealJS", description: "Generate RevealJS PPT by AI", }; export default function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { return ( {children} ); } ================================================ FILE: app/page.tsx ================================================ 'use client' import Chat from '@/components/chat' import SideView from '@/components/side-view' import NavBar from '@/components/navbar' import { AuthViewType, useAuth } from '@/lib/auth' import { useEffect, useState } from 'react' import { useLocalStorage } from 'usehooks-ts' import { ChatMessage, toAISDKMessages } from '@/lib/messages' import { experimental_useObject as useObject } from 'ai/react' import {ArtifactSchema, artifactSchema } from '@/lib/schema' import { usePostHog } from 'posthog-js/react' import { supabase } from '@/lib/supabase' import { AuthDialog } from '@/components/auth-dialog' import { PriceDialog } from '@/components/price-dialog' import { toast } from 'react-toastify' export default function Home() { const posthog = usePostHog() const [currentTab, setCurrentTab] = useState<'code' | 'artifact'>('code') const [isPreviewLoading, setIsPreviewLoading] = useState(false) const [artifact, setArtifact] = useState | undefined>() const [authView, setAuthView] = useState('sign_in') const [isAuthDialogOpen, setAuthDialog] = useState(false) const [isPriceDialogOpen, setPriceDialogOpen] = useState(false) const { session, apiKey } = useAuth(setAuthDialog, setAuthView) const { object, submit, isLoading, stop } = useObject({ api: '/api/chat', schema: artifactSchema, onFinish: async ({ object: artifact, error }) => { if (error) { return } setCurrentTab('artifact') setIsPreviewLoading(false) } }) useEffect(() => { if (object) { setArtifact(object as ArtifactSchema) const lastAssistantMessage = messages.findLast(message => message.role === 'assistant') if (lastAssistantMessage) { lastAssistantMessage.content = [{ type: 'text', text: object.commentary || '' }, { type: 'code', text: object.code || '' }] lastAssistantMessage.meta = { title: object.title, description: object.description } } } }, [object]) const logout = () => { supabase.auth.signOut() } const checkLimit = async (): Promise => { const res = await fetch('/api/limit', { method: 'GET', }); if (res.status === 429) { toast.error('You have reached your request limit for the day') return true } return false } const [chatInput, setChatInput] = useLocalStorage('chat', '') const handleSaveInputChange = (e: React.ChangeEvent) => { setChatInput(e.target.value) } const [messages, setMessages] = useState([]) const addMessage = (message: ChatMessage) => { setMessages(previousMessages => [...previousMessages, message]) return [...messages, message] } const handleSubmitAuth = async (e?: React.FormEvent) => { e?.preventDefault() if (!session) { return setAuthDialog(true) } if (isLoading) { stop() } const limited = await checkLimit() if (limited) { return } const content: ChatMessage['content'] = [{ type: 'text', text: chatInput }] submit({ userID: session?.user?.id, messages: toAISDKMessages(addMessage({role: 'user', content})), }) addMessage({ role: 'assistant', content: [{ type: 'text', text: 'Generating RevealJS ppt...' }], }) setChatInput('') setCurrentTab('code') setIsPreviewLoading(true) posthog.capture('chat_submit') } return (
{<> } setAuthDialog(true)} signOut={logout} showPrice={() => setPriceDialogOpen(true)} />
) } ================================================ FILE: app/provider.tsx ================================================ 'use client' import posthog from 'posthog-js' import { PostHogProvider as PostHogProviderJS } from 'posthog-js/react' posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY ?? '', { api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST, person_profiles: 'identified_only', session_recording: { recordCrossOriginIframes: true, } }) export function PostHogProvider({ children }: { children: React.ReactNode }) { return ( {children} ) } ================================================ FILE: components/artifact-view.tsx ================================================ 'use client' import { useEffect, useState } from "react" interface ArtifactViewProps { result: string } export function ArtifactView({ result, }: ArtifactViewProps) { const [iframeKey, setIframeKey] = useState(0); useEffect(() => { setIframeKey(prevKey => prevKey + 1); }, [result]); if (!result) return null const encodedHTML = encodeURIComponent(result); const dataURI = `data:text/html;charset=utf-8,${encodedHTML}`; return (