Skip to content

Instantly share code, notes, and snippets.

@MarcoF1
Created August 16, 2024 03:50
Show Gist options
  • Save MarcoF1/8ce12cde2c36e107a663cd67fa657f39 to your computer and use it in GitHub Desktop.
Save MarcoF1/8ce12cde2c36e107a663cd67fa657f39 to your computer and use it in GitHub Desktop.
'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