import React, { useState } from "react"; import "./style.css"; import ChatBoxMessages from "./ChatMessages.js"; const ChatBoxProps = (props) => { const { visible, updateNeedForm, messages, updateMessages } = props.props; const [inputValue, setInputValue] = useState(""); const backendUrl = process.env.REACT_APP_BACKEND_URL; function handleKeyDown(event) { if (event.key === "Enter") { onSend(inputValue); } } function onSend(text) { if (inputValue === "") { return; } let msg1 = { name: "User", message: inputValue }; updateMessages(msg1); //setMessages((prevMessages) => [msg1, ...prevMessages]); /*let msg2 = { name: "Sam", message: "response" + inputValue, query: "query" + inputValue, history: messages, modQuery: inputValue };*/ //let msg2 = { name: "Sam", message: inputValue}; //setMessages((prevMessages) => [msg2, ...prevMessages]); //updateMessages(msg2) //setInputValue(""); //updateNeedForm(true); //setMessages([msg2, ...messages]); fetch(backendUrl + '/predict', { method: 'POST', body: JSON.stringify({ message: inputValue }), mode: 'cors', headers: { 'Content-Type': 'application/json' }, }) .then(r => r.json()) .then(r => { let msg2 = { name: "Sam", message: r.answer, query: r.query, cand: r.cand, history: r.history, modQuery: r.modQuery}; //setMessages((prevMessages) => [msg2, ...prevMessages]); updateMessages(msg2); setInputValue(""); updateNeedForm(true); setInputValue(""); }).catch((error) => { console.error('Error:', error); setInputValue(""); }); } function handleInputChange(event) { setInputValue(event.target.value); } return (

Janet

Hi, it's Janet. I am here to help you in utilizing the VRE.

); }; export default ChatBoxProps;