'use client';
import { useChat } from 'ai/react';
export default function Page() {
// Replace 'your_chat_token' with the actual token value for the chat session
const token = 'your_chat_token';
// Use the hook and specify the API endpoint for streaming chat
const { messages, input, handleInputChange, handleSubmit } = useChat({
api: `https://aitutor-api.vercel.app/api/v1/chat/${token}/stream`,
keepLastMessageOnError: true,
});
return (
<>
{messages.map(message => (
<div key={message.id}>
{message.role === 'user' ? 'User: ' : 'AI: '}
{message.content}
</div>
))}
<form onSubmit={handleSubmit}>
<input name="prompt" value={input} onChange={handleInputChange} />
<button type="submit">Submit</button>
</form>
</>
);
}