update AI page

This commit is contained in:
Raven Scott 2024-10-02 03:45:08 -04:00
parent 8006c44f81
commit 356ca2001a

View File

@ -406,24 +406,31 @@
} }
} }
// Resets the chat messages // Helper function to reset the conversation on the server
async function resetChat() { async function sendResetRequest() {
try {
// Send a POST request to reset the conversation on the server
const response = await fetch('https://infer.x64.world/reset-conversation', { const response = await fetch('https://infer.x64.world/reset-conversation', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}); });
return response;
}
// Resets the chat messages and optionally displays a success message
async function resetChat(displaySuccessMessage = true) {
try {
const response = await sendResetRequest();
if (response.ok) { if (response.ok) {
// Clear the messages in the UI // Clear the messages in the UI
const messagesContainer = document.getElementById('messages'); const messagesContainer = document.getElementById('messages');
messagesContainer.innerHTML = ''; // Clear all messages messagesContainer.innerHTML = ''; // Clear all messages
// Display success message // Optionally display a success message
if (displaySuccessMessage) {
displayAlert('success', 'Messages Cleared!'); displayAlert('success', 'Messages Cleared!');
}
} else { } else {
// Handle error response from the server // Handle error response from the server
displayAlert('error', 'Failed to reset conversation. Please try again.'); displayAlert('error', 'Failed to reset conversation. Please try again.');
@ -433,6 +440,11 @@
displayAlert('error', 'An error occurred while resetting the conversation.'); 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
});
</script> </script>
</body> </body>