-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathpage.tsx
40 lines (35 loc) · 1.11 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use client';
import { Card } from '@/app/components';
import { useChat } from 'ai/react';
export default function Page() {
const { messages, input, handleSubmit, handleInputChange, isLoading } =
useChat({
api: '/api/chat?protocol=text',
streamProtocol: 'text',
});
return (
<div className="flex flex-col gap-2">
<div className="flex flex-col p-4 gap-2">
{messages.map(message => (
<div key={message.id} className="flex flex-row gap-2">
<div className="w-24 text-zinc-500 flex-shrink-0">{`${message.role}: `}</div>
<div className="flex flex-col gap-2">{message.content}</div>
</div>
))}
</div>
{messages.length === 0 && <Card type="chat-text" />}
<form
onSubmit={handleSubmit}
className="flex flex-col fixed bottom-0 w-full border-t"
>
<input
value={input}
placeholder="Why is the sky blue?"
onChange={handleInputChange}
className="w-full p-4 outline-none bg-transparent"
disabled={isLoading}
/>
</form>
</div>
);
}