From 356ca2001a49ff81b6c8a42cc8d11018f2211b39 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Wed, 2 Oct 2024 03:45:08 -0400 Subject: [PATCH] update AI page --- views/chat.ejs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) 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 + });