chatbot-template/components/chat-panel.tsx

79 lines
2 KiB
TypeScript
Raw Normal View History

2023-06-14 16:05:03 +04:00
import { type UseChatHelpers } from 'ai-connector/react'
import { Button } from '@/components/ui/button'
import { PromptForm } from '@/components/prompt-form'
2023-06-11 22:58:00 +04:00
import { ButtonScrollToBottom } from '@/components/button-scroll-to-bottom'
2023-06-13 16:02:07 +04:00
import { IconRefresh, IconStop } from '@/components/ui/icons'
2023-06-16 17:06:23 +04:00
import { FooterText } from '@/components/footer'
export interface ChatPanelProps
extends Pick<
UseChatHelpers,
| 'append'
| 'isLoading'
| 'reload'
| 'messages'
| 'stop'
| 'input'
| 'setInput'
> {
id?: string
}
export function ChatPanel({
2023-06-15 11:31:03 +04:00
id,
isLoading,
stop,
append,
reload,
input,
setInput,
messages
}: ChatPanelProps) {
return (
<div className="fixed inset-x-0 bottom-0 bg-gradient-to-b from-muted/10 from-10% to-muted/30 to-50%">
2023-06-11 22:58:00 +04:00
<ButtonScrollToBottom />
<div className="mx-auto sm:max-w-2xl sm:px-4">
2023-06-11 22:58:00 +04:00
<div className="flex h-10 items-center justify-center">
{isLoading ? (
<Button
variant="outline"
onClick={() => stop()}
className="bg-background"
>
2023-06-13 16:02:07 +04:00
<IconStop className="mr-2" />
Stop generating
</Button>
) : (
messages?.length > 0 && (
<Button
variant="outline"
onClick={() => reload()}
className="bg-background"
>
2023-06-13 16:02:07 +04:00
<IconRefresh className="mr-2" />
Regenerate response
</Button>
)
)}
</div>
2023-06-11 22:58:00 +04:00
<div className="space-y-4 border-t bg-background px-4 py-2 shadow-lg sm:rounded-t-xl sm:border md:py-4">
<PromptForm
2023-06-15 11:31:03 +04:00
onSubmit={async value => {
await append({
id,
content: value,
role: 'user'
})
}}
input={input}
setInput={setInput}
isLoading={isLoading}
/>
2023-06-16 17:06:23 +04:00
<FooterText className="hidden sm:block" />
</div>
</div>
</div>
)
}