Created
August 16, 2024 03:50
-
-
Save MarcoF1/8ce12cde2c36e107a663cd67fa657f39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use client' | |
import { useChat } from 'ai/react' | |
export default function Chat() { | |
const { messages, input, handleInputChange, handleSubmit } = useChat() | |
return ( | |
<div className="flex flex-col w-full max-w-md py-24 mx-auto stretch"> | |
{messages.length > 0 | |
? messages.map(m => ( | |
<div key={m.id} className="whitespace-pre-wrap"> | |
{m.role === 'user' ? 'User: ' : 'AI: '} | |
{m.content} | |
</div> | |
)) | |
: null} | |
<form onSubmit={handleSubmit}> | |
<input | |
className="fixed bottom-0 w-full max-w-md p-2 mb-8 border border-gray-300 rounded shadow-xl" | |
value={input} | |
placeholder="Say something..." | |
onChange={handleInputChange} | |
/> | |
</form> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment