import React, { useState } from 'react'; import axios from 'axios'; function Chat() { const [messages, setMessages] = useState([]); const [currentMessage, setCurrentMessage] = useState(''); const handleSubmit = async (e) => { e.preventDefault(); setMessages([...messages, { type: 'user', content: currentMessage }]); try { const response = await axios.post('http://0.0.0.0:8000/generate-text/', { query: currentMessage }); setMessages(prevMessages => [...prevMessages, { type: 'bot', content: response.data.response }]); } catch (error) { console.error("Error while querying:", error); } setCurrentMessage(''); }; return (
{messages.map((message, idx) => (
{message.content}
))}
setCurrentMessage(e.target.value)} placeholder="Ask something..." />
); } export default Chat;