-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpage.tsx
29 lines (25 loc) · 859 Bytes
/
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
'use client';
import { useChat } from 'ai/react';
export default function Chat() {
const { messages, input, handleInputChange, handleSubmit } = useChat({
initialInput: "Tell me a joke!"
});
return (
<div className="flex flex-col w-full max-w-md pb-20 mx-auto stretch">
{messages.map(m => (
<div key={m.id} className="whitespace-pre-wrap dark:text-gray-100 mb-4">
{m.role === 'user' ? 'User: ' : 'AI: '}
{m.content}
</div>
))}
<form onSubmit={handleSubmit}>
<input
className="fixed bottom-0 w-full max-w-md p-2 mb-8 border border-gray-300 rounded shadow-xl dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100"
value={input}
placeholder="Say something..."
onChange={handleInputChange}
/>
</form>
</div>
);
}