chatbot-template/components/chat.tsx

52 lines
1.2 KiB
TypeScript
Raw Normal View History

'use client'
2023-06-13 17:31:15 -04:00
import { useChat, type Message } from 'ai-connector/react'
import { cn } from '@/lib/utils'
import { ChatList } from '@/components/chat-list'
import { ChatPanel } from '@/components/chat-panel'
import { EmptyScreen } from '@/components/empty-screen'
2023-06-15 15:27:41 +04:00
import { ChatScrollAnchor } from '@/components/chat-scroll-anchor'
export interface ChatProps extends React.ComponentProps<'div'> {
initialMessages?: Message[]
2023-06-16 15:20:42 +04:00
id?: string
}
2023-06-16 15:20:42 +04:00
export function Chat({ id, title, initialMessages, className }: ChatProps) {
const { messages, append, reload, stop, isLoading, input, setInput } =
useChat({
initialMessages,
2023-06-15 11:31:03 +04:00
id,
body: {
id
}
})
return (
<>
<div className={cn('pb-[200px] pt-4 md:pt-10', className)}>
{messages.length ? (
2023-06-15 15:27:41 +04:00
<>
<ChatList messages={messages} />
<ChatScrollAnchor trackVisibility={isLoading} />
</>
) : (
<EmptyScreen setInput={setInput} />
)}
</div>
<ChatPanel
id={id}
isLoading={isLoading}
stop={stop}
append={append}
reload={reload}
messages={messages}
input={input}
setInput={setInput}
/>
</>
)
}