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