| 2 | import { usePipe } from '@baseai/core/react'; |
| 3 | |
| 4 | const ChatSimple = () => { |
| 5 | const { messages, input, handleInputChange, handleSubmit, isLoading, error } = |
| 6 | usePipe({ |
| 7 | apiRoute: '/api/langbase/pipes/run-stream', |
| 8 | }); |
| 9 | |
| 10 | return ( |
| 11 | <div className="flex flex-col w-full max-w-md py-24 mx-auto stretch"> |
| 12 | {messages.map((m, i) => ( |
| 13 | <div key={i} className="whitespace-pre-wrap"> |
| 14 | {m.role === 'user' ? 'User: ' : 'AI: '} |
| 15 | {m.content} |
| 16 | </div> |
| 17 | ))} |
| 18 | <form onSubmit={handleSubmit} className="bg-black flex w-full"> |
| 19 | <Input |
| 20 | className="fixed bottom-0 w-full max-w-md p-2 mb-8 border border-gray-300 rounded shadow-xl " |
| 21 | value={input} |
| 22 | placeholder="Say something..." |
| 23 | onChange={handleInputChange} |
| 24 | autoFocus |
| 25 | /> |
| 26 | </form> |
| 27 | {isLoading && <div>AI is thinking...</div>} |
| 28 | {error && ( |
| 29 | <div className="text-red-500">Error: {error.message}</div> |
| 30 | )} |
| 31 | </div> |
| 32 | ); |
| 33 | }; |
| 34 | |
| 35 | export default ChatSimple; |