diff --git a/views/chat.ejs b/views/chat.ejs index 1c94c89..1adb770 100644 --- a/views/chat.ejs +++ b/views/chat.ejs @@ -406,24 +406,31 @@ } } - // Resets the chat messages - async function resetChat() { + // Helper function to reset the conversation on the server + async function sendResetRequest() { + const response = await fetch('https://infer.x64.world/reset-conversation', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + } + }); + return response; + } + + // Resets the chat messages and optionally displays a success message + async function resetChat(displaySuccessMessage = true) { try { - // Send a POST request to reset the conversation on the server - const response = await fetch('https://infer.x64.world/reset-conversation', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - } - }); + const response = await sendResetRequest(); if (response.ok) { // Clear the messages in the UI const messagesContainer = document.getElementById('messages'); messagesContainer.innerHTML = ''; // Clear all messages - // Display success message - displayAlert('success', 'Messages Cleared!'); + // Optionally display a success message + if (displaySuccessMessage) { + displayAlert('success', 'Messages Cleared!'); + } } else { // Handle error response from the server displayAlert('error', 'Failed to reset conversation. Please try again.'); @@ -433,6 +440,11 @@ displayAlert('error', 'An error occurred while resetting the conversation.'); } } + + // Resets the chat on page load without displaying the success message + document.addEventListener('DOMContentLoaded', function () { + resetChat(false); // Call without displaying success message + });