2023-06-11 00:23:23 +04:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
import { UseChatHelpers } from 'ai-connector'
|
2023-06-11 15:08:59 +04:00
|
|
|
import { RefreshCcw, StopCircle } from 'lucide-react'
|
|
|
|
|
|
|
|
|
|
import { ExternalLink } from '@/components/external-link'
|
|
|
|
|
import { PromptForm } from '@/components/prompt-form'
|
|
|
|
|
import { Button } from '@/components/ui/button'
|
2023-06-11 00:23:23 +04:00
|
|
|
|
|
|
|
|
export interface ChatPanelProps
|
2023-06-11 15:08:59 +04:00
|
|
|
extends Pick<
|
|
|
|
|
UseChatHelpers,
|
|
|
|
|
'append' | 'isLoading' | 'reload' | 'messages' | 'stop'
|
|
|
|
|
> {
|
2023-06-11 00:23:23 +04:00
|
|
|
id?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function ChatPanel({
|
|
|
|
|
isLoading,
|
2023-06-11 15:08:59 +04:00
|
|
|
stop,
|
|
|
|
|
append,
|
2023-06-11 00:23:23 +04:00
|
|
|
reload,
|
|
|
|
|
messages
|
|
|
|
|
}: ChatPanelProps) {
|
|
|
|
|
return (
|
2023-06-11 15:08:59 +04:00
|
|
|
<div className="fixed bottom-0 left-0 right-0 bg-gradient-to-b from-muted/10 from-10% to-muted/30 to-50%">
|
|
|
|
|
<div className="sm:max-w-2xl sm:px-4 mx-auto">
|
|
|
|
|
<div className="flex items-center justify-center py-2">
|
|
|
|
|
{isLoading ? (
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
onClick={() => stop()}
|
|
|
|
|
className="bg-background"
|
|
|
|
|
>
|
|
|
|
|
<StopCircle className="h-4 w-4 mr-2" />
|
|
|
|
|
Stop generating
|
|
|
|
|
</Button>
|
|
|
|
|
) : (
|
|
|
|
|
messages?.length > 0 && (
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
onClick={() => reload()}
|
|
|
|
|
className="bg-background"
|
|
|
|
|
>
|
|
|
|
|
<RefreshCcw className="h-4 w-4 mr-2" />
|
|
|
|
|
Regenerate response
|
|
|
|
|
</Button>
|
|
|
|
|
)
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="sm:p-4 border-t sm:border bg-background space-y-4 shadow-lg sm:rounded-t-xl">
|
2023-06-11 00:23:23 +04:00
|
|
|
<PromptForm
|
|
|
|
|
onSubmit={value => {
|
|
|
|
|
append({
|
|
|
|
|
content: value,
|
|
|
|
|
role: 'user'
|
|
|
|
|
})
|
|
|
|
|
}}
|
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
/>
|
2023-06-11 15:08:59 +04:00
|
|
|
<p className="hidden sm:block text-muted-foreground text-xs leading-normal text-center px-2">
|
|
|
|
|
Open source AI chatbot app built with{' '}
|
2023-06-11 00:23:23 +04:00
|
|
|
<ExternalLink href="https://nextjs.org">Next.js</ExternalLink> and{' '}
|
|
|
|
|
<ExternalLink href="https://vercel.com/storage/kv">
|
|
|
|
|
Vercel KV
|
|
|
|
|
</ExternalLink>
|
|
|
|
|
.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|