Skip to content

Commit

Permalink
peerlist hackathon
Browse files Browse the repository at this point in the history
  • Loading branch information
SkidGod4444 committed Dec 21, 2024
1 parent d2ea4e8 commit 9b9b358
Show file tree
Hide file tree
Showing 21 changed files with 999 additions and 73 deletions.
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
UPSTASH_VECTOR_REST_URL="XXXXX"
UPSTASH_VECTOR_REST_TOKEN="XXXXX"


# if you use OpenAI compatible models
OPENAI_API_KEY="XXXXX"

# or if you use Upstash hosted models
QSTASH_TOKEN="XXXXX"

# Optional: For Redis-based chat history (default is in-memory)
UPSTASH_REDIS_REST_URL="XXXXX"
Expand Down
113 changes: 113 additions & 0 deletions app/(routes)/chat/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"use client";

import { useState } from 'react';
import { ChevronLeft, ChevronRight, PaperclipIcon, ArrowUpIcon } from 'lucide-react';
import { ScrollArea } from "@/components/ui/scroll-area";
import { Button } from "@/components/ui/button";
import { CustomTextArea } from "@/components/custom/text.area";
import { SideBar } from "@/components/custom/sidebar/sidebar";
import useLocalStorage from "@/lib/use.local";
import { LibSelector } from '@/components/custom/lib.selector';

export default function Component() {
const [isCodeCollapsed, setIsCodeCollapsed] = useState(false);
const [isSidebarExpanded, setIsSidebarExpanded] = useLocalStorage("acter-isCollapsed", false);

const toggleCodePanel = () => {
setIsCodeCollapsed(!isCodeCollapsed);
};

const messages = [
{ id: 1, text: "Hello! How can I help you today?" },
{ id: 2, text: "Can you explain how to use React hooks?" },
{ id: 3, text: "React hooks are functions that let you use state and other React features in functional components..." },
];

const codeExample = `
import React, { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
`.trim();

return (
<div className="flex h-screen">
{/* Sidebar */}
<SideBar
isSidebarExpanded={isSidebarExpanded}
setIsSidebarExpanded={setIsSidebarExpanded}
/>

{/* Left Panel */}
<div className="flex-1 flex flex-col p-4 border-r">
<nav className="flex items-center justify-between border-b pb-2 mb-4">
<h2 className="text-2xl font-bold">Messages</h2>
<Button
variant="ghost"
size="icon"
onClick={toggleCodePanel}
>
{isCodeCollapsed ? <ChevronLeft className="h-6 w-6" /> : <ChevronRight className="h-6 w-6" />}
</Button>
</nav>
<ScrollArea className="flex-1 mb-4 p-4 bg-gray-50 rounded-lg">
{messages.map((message) => (
<div key={message.id} className="mb-4 p-3 bg-white rounded-lg shadow-sm">
{message.text}
</div>
))}
</ScrollArea>

{/* Input Area */}
<form
// onSubmit={handleFormSubmit}
className="flex flex-col gap-2 bg-background border dark:bg-black rounded-xl dark:border-white p-2 min-h-[60px]"
>
<CustomTextArea
placeholder="Acter, make me a glowing button component..."
className="flex-1 bg-transparent focus:outline-none shadow-none"
/>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Button variant="outline" size="icon" disabled>
<PaperclipIcon className="w-4 h-4" />
</Button>
<LibSelector />
</div>
<Button size="icon">
<ArrowUpIcon className="w-4 h-4" />
</Button>
</div>
</form>
</div>

{/* Right Panel - Code Viewer */}
<div
className={`flex transition-all duration-300 ease-in-out ${
isCodeCollapsed ? 'w-12' : 'w-1/2'
}`}
>
{!isCodeCollapsed && (
<div className="flex-1 p-4 border-l">
<h2 className="text-2xl font-bold mb-4">Code</h2>
<ScrollArea className="h-[calc(100vh-8rem)]">
<pre className="p-4 bg-gray-100 rounded-lg overflow-x-auto">
<code>{codeExample}</code>
</pre>
</ScrollArea>
</div>
)}
</div>
</div>
);
}
113 changes: 109 additions & 4 deletions app/(routes)/chat/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,114 @@
import React from 'react'
"use client";

import { Badge } from "@/components/ui/badge";
import { MoveUpRight } from "lucide-react";
import useLocalStorage from "@/lib/use.local";
import { useUser } from "@/context/user.context";
import { OfcLinks } from "@/db/defaults";
import { SideBar } from "@/components/custom/sidebar/sidebar";
import { useEffect, useState } from "react";
import { ChatComp } from "@/components/custom/chat/comp";

export default function ChatPage() {
const { user } = useUser();
const [chatID, setChatID] = useState<string | number>("null");
const [isMsg, setMsg] = useState(false);

useEffect(() => {
const fetchChatID = async () => {
const id = Math.floor(Math.random() * 900000) + 100000;
setChatID(id.toString());
};

if (user) {
fetchChatID();
}
}, [user, chatID]);

useEffect(() => {
if (chatID && isMsg) {
window.location.href = `/chat/${chatID}`;
}
}, [chatID, isMsg]);

const [isSidebarExpanded, setIsSidebarExpanded] = useLocalStorage(
"acter-isCollapsed",
false
);

return (
<div>
Damn! bro can&apos;t you even wait for my wings?
<div className="relative h-screen flex z-50 flex-col dark:bg-black dark:text-white bg-background text-black font-[family-name:var(--font-geist-regular)] overflow-hidden">
{/* Background */}
<div className="fixed inset-0 z-20 h-full w-full bg-[linear-gradient(to_right,#f0f0f0_1px,transparent_1px),linear-gradient(to_bottom,#f0f0f0_1px,transparent_1px)] bg-[size:3rem_3rem] dark:bg-[linear-gradient(to_right,#333_1px,transparent_1px),linear-gradient(to_bottom,#333_1px,transparent_1px)] dark:bg-[size:3rem_3rem]" />

{/* Main Layout */}
<div className="flex h-full w-full z-30">
{/* Sidebar */}
<SideBar
isSidebarExpanded={isSidebarExpanded}
setIsSidebarExpanded={(expanded) => setIsSidebarExpanded(expanded)}
/>

{/* Main Content */}
<div className="flex flex-col flex-1 z-40">
{/* Header at the top */}
<header className="flex justify-end items-center p-4 bg-transparent border-none">
<Badge>Public Beta</Badge>
</header>

<main className="flex-1 flex flex-col items-center justify-center p-4">
<h2 className="text-4xl mb-4 font-[family-name:var(--font-geist-bold)] tracking-tighter select-none">
Need awesome components to ship?
</h2>
<p className="text-sm mb-4 select-none dark:text-white text-muted-foreground">
Am the one who supports Acternity UI, Magic UI and more libraries. Ask questions, modify component.
</p>

{/* Input area */}
<div className="w-full max-w-3xl mb-10">
<ChatComp chatId={chatID} onHasMessagesChange={setMsg} />
</div>

<div className="flex flex-wrap justify-center gap-4">
<Badge variant={"secondary"} className="cursor-pointer rounded-xl border border-muted-foreground">
Generate a SaaS pricing calculator
<MoveUpRight className="size-3 ml-1" />
</Badge>
<Badge variant={"secondary"} className="cursor-pointer rounded-xl border border-muted-foreground">
How can I structure LLM output?
<MoveUpRight className="size-3 ml-1" />
</Badge>
<Badge variant={"secondary"} className="cursor-pointer rounded-xl border border-muted-foreground">
Write code to implement a min heap
<MoveUpRight className="size-3 ml-1" />
</Badge>
</div>
</main>

{/* Footer at the bottom */}
<footer className="p-8">
<div className="flex justify-center items-center text-xs text-gray-500">
<div className="flex items-center">
<a href="/legal/ai-policy" className="hover:underline">
Terms
</a>
<div className="h-4 w-px bg-gray-300 mx-2"></div>
<a href="/legal/agreement" className="hover:underline">
AI Policy
</a>
<div className="h-4 w-px bg-gray-300 mx-2"></div>
<a href="/legal/privacy-policy" className="hover:underline">
Privacy
</a>
</div>
<div className="h-4 w-px bg-gray-300 mx-2"></div>
<a href={OfcLinks.portfolio} className="hover:underline">
By Saidev Dhal
</a>
</div>
</footer>
</div>
</div>
</div>
)
);
}
71 changes: 12 additions & 59 deletions app/(routes)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

import { useState } from "react";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import {
MenuIcon,
PlusIcon,
BookOpenIcon,
LayoutDashboardIcon,
ChevronLeftIcon,
PaperclipIcon,
ArrowUpIcon,
MoveUpRight,
Expand All @@ -17,13 +11,11 @@ import { CustomTextArea } from "@/components/custom/text.area";
import { Badge } from "@/components/ui/badge";
import { OsBtn } from "@/components/custom/os.button";
import { OfcLinks } from "@/db/defaults";
import { useUser } from "@/context/user.context";
import DragableCards from "@/components/custom/hero/dragable.cards";
import AuthDialog from "@/components/custom/auth/auth.dialog";
import { LibSelector } from "@/components/custom/lib.selector";

export default function Component() {
const { user } = useUser();
const [isSidebarExpanded, setIsSidebarExpanded] = useState(false);
export default function HomePage() {
const [isOpen, setIsOpen] = useState(false);

const handleFormSubmit = async(event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -39,48 +31,6 @@ export default function Component() {

{/* Main Layout */}
<div className="flex h-full w-full z-30">
{/* Sidebar */}
{user && (
<div
className={cn(
"hidden md:flex flex-col transition-all duration-300 border-r",
isSidebarExpanded ? "w-60" : "w-12",
)}
>
<div className="flex items-center justify-between p-2">
<span
className={cn(
"text-2xl font-bold",
!isSidebarExpanded && "hidden",
)}
>
Acter
</span>
<Button
variant="ghost"
size="icon"
onClick={() => setIsSidebarExpanded(!isSidebarExpanded)}
>
{isSidebarExpanded ? <ChevronLeftIcon /> : <MenuIcon />}
</Button>
</div>
<nav className="flex flex-col gap-2 p-4">
<Button variant="ghost" className="justify-start">
<PlusIcon className="mr-2" />
{isSidebarExpanded && "New Chat"}
</Button>
<Button variant="ghost" className="justify-start">
<BookOpenIcon className="mr-2" />
{isSidebarExpanded && "Docs"}
</Button>
<Button variant="ghost" className="justify-start">
<LayoutDashboardIcon className="mr-2" />
{isSidebarExpanded && "Dashboard"}
</Button>
</nav>
</div>
)}

{/* Main Content */}
<div className="flex flex-col flex-1 z-40">
{/* Header at the top */}
Expand All @@ -94,23 +44,26 @@ export default function Component() {
</div>
<main className="flex-1 flex flex-col items-center justify-center p-4">
<h2 className="text-4xl mb-4 font-[family-name:var(--font-geist-bold)] tracking-tighter select-none">
What can I help you ship?
Need awesome components to ship?
</h2>
<p className="text-sm mb-4 select-none dark:text-white text-muted-foreground">
Am the one who supports Acternity UI, ask questions, debug code.
Am the one who supports Acternity UI, Magic UI and more libraries. Ask questions, modify component.
</p>

{/* Input area */}
<div className="w-full max-w-3xl mb-10">
<form onSubmit={handleFormSubmit} className="flex flex-col gap-2 bg-background border-black dark:bg-black rounded-xl border border-dashed dark:border-white p-2 min-h-[60px]">
<form onSubmit={handleFormSubmit} className="flex flex-col gap-2 bg-background dark:bg-black rounded-xl border dark:border-white p-2 min-h-[60px]">
<CustomTextArea
placeholder="Acter make me a bra for my huge buttons..."
placeholder="Acter make me a glowing button component..."
className="flex-1 bg-transparent focus:outline-none shadow-none"
/>
<div className="flex items-center justify-between gap-2">
<Button variant="ghost" size="icon">
<PaperclipIcon className="w-4 h-4" />
</Button>
<div className='flex items-center gap-2 flex-row'>
<Button variant="outline" size="icon" disabled>
<PaperclipIcon className="w-4 h-4" />
</Button>
<LibSelector />
</div>
<Button size="icon">
<ArrowUpIcon className="w-4 h-4" />
</Button>
Expand Down
18 changes: 18 additions & 0 deletions app/api/ai/stream/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NextRequest } from "next/server";
import { aiUseChatAdapter } from "@upstash/rag-chat/nextjs";
import { ragChat } from "@/lib/rag";

export const POST = async (req: NextRequest) => {
const { messages } = await req.json();

const lastMsg = messages[messages.length - 1].content;
const res = await ragChat.chat(lastMsg, {
namespace: "acter-db",
streaming: true,
historyLength: 100,
historyTTL: 604_800,
similarityThreshold: 0.7,
});

return aiUseChatAdapter(res);
};
20 changes: 20 additions & 0 deletions app/api/vectors/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ragChat } from '@/lib/rag';
import { NextRequest, NextResponse } from 'next/server';

export async function POST(req: NextRequest) {
try {
const { source, namespace, metadata } = await req.json();

await ragChat.context.add({
type: "html",
source: source,
config: { chunkOverlap: 50, chunkSize: 200 },
options: { namespace: namespace, metadata: { title: metadata.title, description: metadata.description } },
});

return NextResponse.json({ message: "Content added successfully to ragChat context!" });
} catch (error) {
console.error("Error adding content to ragChat context:", error);
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
}
}
Binary file modified bun.lockb
Binary file not shown.
Loading

0 comments on commit 9b9b358

Please sign in to comment.