Spaces:
Sleeping
Sleeping
| function sendQuery() { | |
| const userInput = document.getElementById('user-input').value; | |
| if (userInput.trim() !== '') { | |
| addMessage('user', userInput); | |
| fetch('/query', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ query: userInput }), | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| console.log("Answer:", data); | |
| addMessage('bot', data.response); | |
| }) | |
| .catch(error => console.error('Error:', error)); | |
| document.getElementById('user-input').value = ''; | |
| } | |
| } | |
| function resetChat() { | |
| document.getElementById('chat-log').innerHTML = ''; | |
| document.getElementById('user-input').value = ''; | |
| } | |
| function addMessage(sender, message) { | |
| const chatLog = document.getElementById('chat-log'); | |
| const messageDiv = document.createElement('div'); | |
| messageDiv.classList.add('message', `${sender}-message`); | |
| messageDiv.textContent = message; | |
| chatLog.appendChild(messageDiv); | |
| } | |