2023-06-02 15:33:48 -04:00
|
|
|
'use client'
|
2023-05-19 12:33:56 -04:00
|
|
|
|
2023-06-02 15:33:48 -04:00
|
|
|
import { useRouter } from 'next/navigation'
|
|
|
|
|
import { Prompt } from './prompt'
|
|
|
|
|
import { useChat, type Message } from 'ai-connector'
|
|
|
|
|
import { ChatList } from './chat-list'
|
2023-06-07 16:17:59 +04:00
|
|
|
import { ExternalLink } from '@/app/external-link'
|
2023-05-19 12:33:56 -04:00
|
|
|
|
|
|
|
|
export interface ChatProps {
|
|
|
|
|
// create?: (input: string) => Chat | undefined;
|
2023-06-02 15:33:48 -04:00
|
|
|
initialMessages?: Message[]
|
|
|
|
|
id?: string
|
2023-05-19 12:33:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function Chat({
|
2023-05-22 13:10:52 +02:00
|
|
|
id,
|
2023-05-19 12:33:56 -04:00
|
|
|
// create,
|
2023-06-02 15:33:48 -04:00
|
|
|
initialMessages
|
2023-05-19 12:33:56 -04:00
|
|
|
}: ChatProps) {
|
2023-06-02 15:33:48 -04:00
|
|
|
const router = useRouter()
|
2023-05-19 12:33:56 -04:00
|
|
|
|
2023-06-02 11:15:04 -04:00
|
|
|
const { isLoading, messages, reload, append } = useChat({
|
|
|
|
|
initialMessages: initialMessages as any[],
|
2023-06-02 15:33:48 -04:00
|
|
|
id
|
2023-06-02 11:15:04 -04:00
|
|
|
// onCreate: (id: string) => {
|
|
|
|
|
// router.push(`/chat/${id}`);
|
|
|
|
|
// },
|
2023-06-02 15:33:48 -04:00
|
|
|
})
|
2023-05-19 12:33:56 -04:00
|
|
|
|
|
|
|
|
return (
|
2023-06-07 16:17:59 +04:00
|
|
|
<div className="h-full w-full overflow-auto pb-[200px]">
|
|
|
|
|
<ChatList messages={messages} />
|
|
|
|
|
<div className="fixed bottom-0 left-1 right-3 p-6 bg-gradient-to-b from-background/10 via-background/50 to-background/80 backdrop-blur-lg">
|
|
|
|
|
<div className="max-w-2xl mx-auto pl-10">
|
|
|
|
|
<Prompt
|
|
|
|
|
onSubmit={value => {
|
|
|
|
|
append({
|
|
|
|
|
content: value,
|
|
|
|
|
role: 'user'
|
|
|
|
|
})
|
|
|
|
|
}}
|
|
|
|
|
onRefresh={messages.length ? reload : undefined}
|
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
/>
|
|
|
|
|
<p className="text-muted-foreground text-xs leading-normal text-center pt-2">
|
|
|
|
|
This is an open source AI chatbot app built with{' '}
|
|
|
|
|
<ExternalLink href="https://nextjs.org">Next.js</ExternalLink> and{' '}
|
|
|
|
|
<ExternalLink href="https://vercel.com/storage/kv">
|
|
|
|
|
Vercel KV
|
|
|
|
|
</ExternalLink>
|
|
|
|
|
.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2023-05-19 12:33:56 -04:00
|
|
|
</div>
|
2023-06-07 16:17:59 +04:00
|
|
|
</div>
|
2023-06-02 15:33:48 -04:00
|
|
|
)
|
2023-05-19 12:33:56 -04:00
|
|
|
}
|