Wait for AI response before letting user send another message in GUI

This commit is contained in:
2024-03-09 03:12:19 -05:00
parent 226f4bf409
commit 0ab585943f
3 changed files with 28 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ function displayMessage(message, sender) {
document.addEventListener('DOMContentLoaded', () => {
const chatForm = document.getElementById('chatForm');
const promptInput = document.getElementById('promptInput');
const sendButton = document.getElementById('sendButton');
if (chatForm && promptInput) {
chatForm.addEventListener('submit', async (event) => {
@@ -24,6 +25,9 @@ document.addEventListener('DOMContentLoaded', () => {
const userInput = promptInput.value;
promptInput.value = '';
sendButton.disabled = true;
promptInput.disabled = true;
displayMessage(userInput, 'user');
try {
@@ -33,9 +37,13 @@ document.addEventListener('DOMContentLoaded', () => {
} catch (error) {
console.error(`Error sending prompt: ${error.message}`);
displayMessage(`Error: ${error.message}`, 'assistant');
} finally {
sendButton.disabled = false;
promptInput.disabled = false;
promptInput.focus();
}
});
} else {
console.error('chatForm or promptInput elements not found!');
}
});
});