2024-10-02 03:32:27 -04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
|
|
|
|
<head>
|
2024-10-02 03:38:25 -04:00
|
|
|
<!-- Meta and Title -->
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<meta name="description" content="<%= process.env.OWNER_NAME %>'s Blog">
|
|
|
|
<title>
|
2024-10-02 04:03:47 -04:00
|
|
|
<%= title %> | <%= process.env.OWNER_NAME %>'s Blog
|
2024-10-02 03:38:25 -04:00
|
|
|
</title>
|
|
|
|
<!-- Bootstrap CSS -->
|
|
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css">
|
|
|
|
<!-- Font Awesome CSS for Icons -->
|
|
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
2024-10-02 04:03:47 -04:00
|
|
|
<link rel="stylesheet"
|
|
|
|
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/atom-one-dark.min.css">
|
2024-10-02 03:38:25 -04:00
|
|
|
<!-- Custom CSS -->
|
|
|
|
<link rel="stylesheet" href="<%= process.env.HOST_URL %>/css/styles.css">
|
|
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
|
|
|
<link rel="manifest" href="/site.webmanifest">
|
|
|
|
<meta name="msapplication-TileColor" content="#da532c">
|
|
|
|
<meta name="theme-color" content="#ffffff">
|
2024-10-02 03:32:27 -04:00
|
|
|
<style>
|
|
|
|
html,
|
|
|
|
body {
|
|
|
|
height: 100%;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
background-color: #121212;
|
|
|
|
color: white;
|
|
|
|
font-family: Arial, sans-serif;
|
|
|
|
}
|
|
|
|
|
|
|
|
.bg-dark {
|
|
|
|
background-color: #121212 !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.chat-container {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.navbar {
|
|
|
|
flex-shrink: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.chat-box {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
flex-grow: 1;
|
|
|
|
background-color: #1e1e1e;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.messages {
|
|
|
|
flex-grow: 1;
|
|
|
|
overflow-y: auto;
|
|
|
|
padding: 20px;
|
|
|
|
background-color: #2e2e2e;
|
|
|
|
border-radius: 5px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
|
|
|
|
.message {
|
|
|
|
margin-bottom: 10px;
|
|
|
|
padding: 10px;
|
|
|
|
border-radius: 5px;
|
|
|
|
}
|
|
|
|
|
2024-10-02 04:37:52 -04:00
|
|
|
/* Ensure transparent background for the alert's parent container */
|
|
|
|
#success-alert,
|
|
|
|
#error-alert {
|
|
|
|
background-color: transparent;
|
|
|
|
/* Remove any background color */
|
2024-10-02 04:07:32 -04:00
|
|
|
}
|
|
|
|
|
2024-10-02 04:37:52 -04:00
|
|
|
/* Success Alert - Blue Theme with no extra background */
|
2024-10-02 04:11:27 -04:00
|
|
|
.alert-success {
|
|
|
|
background-color: #007bff;
|
2024-10-02 04:37:52 -04:00
|
|
|
/* Blue background for success */
|
2024-10-02 04:11:27 -04:00
|
|
|
color: white;
|
|
|
|
border: none;
|
|
|
|
padding: 10px 20px;
|
|
|
|
border-radius: 5px;
|
|
|
|
text-align: center;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2024-10-02 04:37:52 -04:00
|
|
|
opacity: 0;
|
|
|
|
/* Start hidden */
|
|
|
|
transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
|
2024-10-02 04:11:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Error Alert - Maroon Red Theme */
|
|
|
|
.alert-danger {
|
|
|
|
background-color: #800000;
|
2024-10-02 04:37:52 -04:00
|
|
|
/* Red background for error */
|
2024-10-02 04:11:27 -04:00
|
|
|
color: white;
|
|
|
|
border: none;
|
|
|
|
padding: 10px 20px;
|
|
|
|
border-radius: 5px;
|
|
|
|
text-align: center;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2024-10-02 04:37:52 -04:00
|
|
|
opacity: 0;
|
|
|
|
/* Start hidden */
|
|
|
|
transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
|
2024-10-02 04:11:27 -04:00
|
|
|
}
|
|
|
|
|
2024-10-02 04:37:52 -04:00
|
|
|
/* Common alert styles */
|
2024-10-02 04:11:27 -04:00
|
|
|
/* Common alert styles */
|
|
|
|
.alert {
|
2024-10-02 04:37:52 -04:00
|
|
|
position: fixed;
|
|
|
|
top: 20px;
|
|
|
|
/* Adjust to your preferred vertical location */
|
|
|
|
left: 45%;
|
|
|
|
/* This centers the alert horizontally */
|
|
|
|
transform: translateX(-50%);
|
|
|
|
/* This ensures the alert is exactly centered */
|
|
|
|
z-index: 9999;
|
|
|
|
/* Ensure it stays on top */
|
|
|
|
opacity: 0;
|
|
|
|
/* Start hidden */
|
|
|
|
transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fade in animation */
|
|
|
|
.alert.fade-in {
|
|
|
|
opacity: 1;
|
|
|
|
transform: translateY(0);
|
|
|
|
animation: fadeSlideIn 0.5s forwards;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fade out animation */
|
|
|
|
.alert.fade-out {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(-20px);
|
|
|
|
animation: fadeSlideOut 0.5s forwards;
|
2024-10-02 04:11:27 -04:00
|
|
|
}
|
|
|
|
|
2024-10-02 03:32:27 -04:00
|
|
|
.message.user {
|
|
|
|
background-color: #3a3a3a;
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
|
|
|
|
.message.assistant {
|
|
|
|
background-color: #282828;
|
|
|
|
color: #f1f1f1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.form-control {
|
|
|
|
background-color: #2e2e2e;
|
|
|
|
color: white;
|
|
|
|
border-color: #444;
|
|
|
|
}
|
|
|
|
|
|
|
|
.form-control:focus {
|
|
|
|
background-color: #2e2e2e;
|
|
|
|
color: white;
|
|
|
|
border-color: #888;
|
|
|
|
}
|
|
|
|
|
|
|
|
pre code {
|
|
|
|
background-color: #1e1e1e;
|
|
|
|
color: #f8f8f2;
|
|
|
|
padding: 10px;
|
|
|
|
border-radius: 5px;
|
|
|
|
display: block;
|
|
|
|
white-space: pre-wrap;
|
|
|
|
word-wrap: break-word;
|
|
|
|
}
|
|
|
|
|
|
|
|
.copy-button {
|
|
|
|
background-color: #444;
|
|
|
|
color: white;
|
|
|
|
border: none;
|
|
|
|
cursor: pointer;
|
|
|
|
padding: 5px;
|
|
|
|
margin-top: 5px;
|
2024-10-02 04:09:08 -04:00
|
|
|
margin-bottom: 5px;
|
2024-10-02 03:32:27 -04:00
|
|
|
display: inline-block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.copy-button:hover {
|
|
|
|
background-color: #555;
|
|
|
|
}
|
|
|
|
|
|
|
|
.input-area {
|
|
|
|
background-color: #1e1e1e;
|
|
|
|
padding: 10px 20px;
|
|
|
|
z-index: 10;
|
|
|
|
flex-shrink: 0;
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
flex-shrink: 0;
|
|
|
|
text-align: center;
|
|
|
|
padding: 10px;
|
|
|
|
background-color: #121212;
|
|
|
|
}
|
|
|
|
|
2024-10-02 04:03:47 -04:00
|
|
|
.copy-button {
|
|
|
|
background-color: #444;
|
|
|
|
/* Button background color */
|
|
|
|
color: white;
|
|
|
|
/* Button text color */
|
|
|
|
border: none;
|
|
|
|
/* Remove border */
|
|
|
|
cursor: pointer;
|
|
|
|
/* Pointer cursor for interaction */
|
|
|
|
padding: 5px 10px;
|
|
|
|
/* Adjusted padding for smaller size */
|
|
|
|
margin-top: 5px;
|
|
|
|
/* Space at the top */
|
|
|
|
display: inline-block;
|
|
|
|
/* Keep the button in line */
|
|
|
|
font-size: 14px;
|
|
|
|
/* Slightly smaller font size for compactness */
|
|
|
|
width: 147px;
|
|
|
|
/* Prevent the button from stretching */
|
|
|
|
text-align: left;
|
|
|
|
/* Align the text left */
|
|
|
|
}
|
|
|
|
|
|
|
|
.copy-button:hover {
|
|
|
|
background-color: #555;
|
|
|
|
/* Darker shade on hover */
|
|
|
|
}
|
2024-10-02 04:37:52 -04:00
|
|
|
|
|
|
|
/* Add animations for the alerts */
|
|
|
|
@keyframes fadeSlideIn {
|
|
|
|
0% {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(-20px);
|
|
|
|
}
|
|
|
|
|
|
|
|
100% {
|
|
|
|
opacity: 1;
|
|
|
|
transform: translateY(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes fadeSlideOut {
|
|
|
|
0% {
|
|
|
|
opacity: 1;
|
|
|
|
transform: translateY(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
100% {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(-20px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Success Alert with fade-in and slide-down animation */
|
|
|
|
.alert {
|
|
|
|
opacity: 0;
|
|
|
|
transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
animation: fadeSlideIn 0.5s forwards;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add class for fading out when alert is being removed */
|
|
|
|
.alert.fade-out {
|
|
|
|
animation: fadeSlideOut 0.5s forwards;
|
|
|
|
}
|
2024-10-02 04:03:47 -04:00
|
|
|
</style>
|
2024-10-02 03:32:27 -04:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body class="bg-dark text-white">
|
|
|
|
|
|
|
|
<div class="chat-container">
|
|
|
|
<!-- Navbar -->
|
2024-10-02 03:36:38 -04:00
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark">
|
2024-10-02 03:32:27 -04:00
|
|
|
<div class="container-fluid">
|
2024-10-02 03:38:25 -04:00
|
|
|
<a class="navbar-brand" href="<%= process.env.HOST_URL %>">
|
|
|
|
<%= process.env.SITE_NAME %>
|
|
|
|
</a>
|
|
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
|
|
|
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
2024-10-02 03:32:27 -04:00
|
|
|
<span class="navbar-toggler-icon"></span>
|
|
|
|
</button>
|
|
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
|
|
<ul class="navbar-nav ms-auto">
|
2024-10-02 03:38:25 -04:00
|
|
|
<% menuItems.forEach(item=> { %>
|
2024-10-02 03:32:27 -04:00
|
|
|
<li class="nav-item">
|
2024-10-02 03:38:25 -04:00
|
|
|
<a class="nav-link" href="<%= item.url %>" <%=item.openNewPage ? 'target="_blank"' : ''
|
|
|
|
%>><%= item.title %></a>
|
2024-10-02 03:32:27 -04:00
|
|
|
</li>
|
2024-10-02 03:38:25 -04:00
|
|
|
<% }) %>
|
2024-10-02 03:32:27 -04:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
<!-- Alert Messages -->
|
|
|
|
<div id="success-alert" class="alert alert-success mt-3" style="display: none;"></div>
|
|
|
|
<div id="error-alert" class="alert alert-danger mt-3" style="display: none;"></div>
|
|
|
|
<!-- Chat Box -->
|
|
|
|
<div class="chat-box">
|
|
|
|
<div id="messages" class="messages"></div>
|
|
|
|
|
|
|
|
<!-- Input area with sticky behavior -->
|
|
|
|
<div class="input-area">
|
|
|
|
<textarea id="messageInput" class="form-control mb-2" rows="3" placeholder=""
|
|
|
|
onkeydown="handleKeyDown(event)"></textarea>
|
|
|
|
|
|
|
|
<!-- Buttons side by side -->
|
|
|
|
<div class="d-flex justify-content-between">
|
|
|
|
<button class="btn btn-secondary" onclick="resetChat()">Reset Chat</button>
|
2024-10-02 04:19:03 -04:00
|
|
|
<!-- Loading Indicator -->
|
|
|
|
<div id="loading" class="text-center mt-3" style="display: none;">
|
2024-10-02 04:23:20 -04:00
|
|
|
<div class="spinner-border spinner-border-sm text-primary" role="status">
|
2024-10-02 04:19:03 -04:00
|
|
|
<span class="visually-hidden">Loading...</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-10-02 04:14:25 -04:00
|
|
|
<button class="btn btn-primary" onclick="sendMessage()">Send Message</button>
|
|
|
|
|
2024-10-02 03:32:27 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-10-02 04:19:03 -04:00
|
|
|
|
2024-10-02 03:32:27 -04:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Bootstrap JS Bundle -->
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
|
<!-- Additional Libraries -->
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/3.0.7/marked.min.js"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/he@1.2.0/he.min.js"></script>
|
|
|
|
|
|
|
|
<!-- Inline JavaScript -->
|
|
|
|
<script>
|
|
|
|
// Handles key down event to send message on Enter
|
|
|
|
function handleKeyDown(event) {
|
|
|
|
if (event.key === 'Enter' && !event.shiftKey) {
|
|
|
|
event.preventDefault();
|
|
|
|
sendMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sends a message to the chat API
|
|
|
|
async function sendMessage() {
|
|
|
|
const messageInput = document.getElementById('messageInput');
|
|
|
|
let message = messageInput.value.trim();
|
|
|
|
|
|
|
|
if (message === '') return;
|
|
|
|
|
|
|
|
// Encode the message to avoid XSS attacks
|
|
|
|
message = he.encode(message);
|
|
|
|
|
|
|
|
// Display the user's message in the chat
|
|
|
|
displayMessage(message, 'user');
|
|
|
|
messageInput.value = ''; // Clear the input
|
|
|
|
toggleLoading(true); // Show loading indicator
|
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await fetch('https://infer.x64.world/chat', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ message: message })
|
|
|
|
});
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
const data = await response.json();
|
|
|
|
displayMessage(data.content, 'assistant');
|
|
|
|
} else {
|
|
|
|
handleErrorResponse(response.status);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
displayMessage('Error: ' + error.message, 'assistant');
|
|
|
|
} finally {
|
|
|
|
toggleLoading(false); // Hide loading indicator
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Toggles the loading indicator
|
|
|
|
function toggleLoading(show) {
|
|
|
|
const loadingElement = document.getElementById('loading');
|
|
|
|
loadingElement.style.display = show ? 'block' : 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Displays a message in the chat window
|
|
|
|
function displayMessage(content, sender) {
|
|
|
|
const messages = document.getElementById('messages');
|
|
|
|
const messageElement = document.createElement('div');
|
|
|
|
messageElement.classList.add('message', sender);
|
|
|
|
|
|
|
|
// Decode HTML entities and render Markdown
|
|
|
|
const decodedContent = he.decode(content);
|
|
|
|
const htmlContent = marked(decodedContent);
|
|
|
|
messageElement.innerHTML = htmlContent;
|
|
|
|
|
|
|
|
messages.appendChild(messageElement);
|
|
|
|
messages.scrollTop = messages.scrollHeight; // Scroll to the bottom of the chat
|
|
|
|
|
|
|
|
// Highlight code blocks if any
|
|
|
|
document.querySelectorAll('pre code').forEach((block) => {
|
|
|
|
hljs.highlightElement(block);
|
|
|
|
if (sender === 'assistant') {
|
|
|
|
addCopyButton(block); // Add copy button to code blocks
|
|
|
|
}
|
|
|
|
});
|
2024-10-02 04:03:47 -04:00
|
|
|
|
|
|
|
// Add "Copy Full Response" button after each assistant response
|
|
|
|
if (sender === 'assistant') {
|
|
|
|
addCopyFullResponseButton(messages, messageElement);
|
|
|
|
}
|
2024-10-02 03:32:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Adds a copy button to a code block
|
|
|
|
function addCopyButton(block) {
|
|
|
|
const button = document.createElement('button');
|
|
|
|
button.classList.add('copy-button');
|
|
|
|
button.textContent = 'Copy';
|
|
|
|
button.addEventListener('click', () => copyToClipboard(block));
|
|
|
|
block.parentNode.appendChild(button);
|
|
|
|
}
|
|
|
|
|
2024-10-02 04:03:47 -04:00
|
|
|
// Adds "Copy Full Response" button below the assistant response
|
|
|
|
function addCopyFullResponseButton(messagesContainer, messageElement) {
|
|
|
|
const copyFullResponseButton = document.createElement('button');
|
|
|
|
copyFullResponseButton.classList.add('copy-button');
|
|
|
|
copyFullResponseButton.textContent = 'Copy Full Response';
|
|
|
|
copyFullResponseButton.addEventListener('click', () => copyFullResponse(messageElement));
|
|
|
|
|
|
|
|
messagesContainer.appendChild(copyFullResponseButton);
|
|
|
|
}
|
|
|
|
|
2024-10-02 03:32:27 -04:00
|
|
|
// Copies code block content to the clipboard
|
|
|
|
function copyToClipboard(block) {
|
|
|
|
const text = block.innerText;
|
|
|
|
navigator.clipboard.writeText(text).then(() => {
|
|
|
|
displayAlert('success', 'The code block was copied to the clipboard!');
|
|
|
|
}).catch((err) => {
|
|
|
|
displayAlert('error', 'Failed to copy code: ' + err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-02 04:03:47 -04:00
|
|
|
// Copies the full response content to the clipboard in Markdown format
|
|
|
|
function copyFullResponse(messageElement) {
|
|
|
|
const markdownContent = convertToMarkdown(messageElement);
|
|
|
|
navigator.clipboard.writeText(markdownContent).then(() => {
|
|
|
|
displayAlert('success', 'Full response copied to clipboard!');
|
|
|
|
}).catch((err) => {
|
|
|
|
displayAlert('error', 'Failed to copy response: ' + err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-02 04:29:24 -04:00
|
|
|
// Converts the HTML content of the response to Markdown, including language identifier
|
2024-10-02 04:03:47 -04:00
|
|
|
function convertToMarkdown(element) {
|
|
|
|
let markdown = '';
|
|
|
|
const nodes = element.childNodes;
|
|
|
|
|
|
|
|
nodes.forEach(node => {
|
|
|
|
if (node.nodeName === 'P') {
|
|
|
|
markdown += `${node.innerText}\n\n`;
|
|
|
|
} else if (node.nodeName === 'PRE') {
|
2024-10-02 04:29:24 -04:00
|
|
|
const codeBlock = node.querySelector('code');
|
|
|
|
const languageClass = codeBlock.className.match(/language-(\w+)/); // Extract language from class if available
|
|
|
|
const language = languageClass ? languageClass[1] : ''; // Default to empty if no language found
|
|
|
|
const codeText = codeBlock.innerText;
|
|
|
|
|
|
|
|
// Add language identifier to the Markdown code block
|
|
|
|
markdown += `\`\`\`${language}\n${codeText}\n\`\`\`\n\n`;
|
2024-10-02 04:03:47 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return markdown;
|
|
|
|
}
|
|
|
|
|
2024-10-02 04:37:52 -04:00
|
|
|
// Displays an alert message with animation
|
2024-10-02 03:32:27 -04:00
|
|
|
function displayAlert(type, message) {
|
|
|
|
const alertElement = document.getElementById(`${type}-alert`);
|
|
|
|
alertElement.textContent = message;
|
2024-10-02 04:37:52 -04:00
|
|
|
alertElement.style.display = 'flex'; // Show the alert
|
|
|
|
alertElement.classList.remove('fade-out'); // Remove fade-out class if present
|
|
|
|
alertElement.style.opacity = '1'; // Ensure it's fully visible
|
|
|
|
|
|
|
|
// Automatically hide the alert after 3 seconds with animation
|
2024-10-02 03:32:27 -04:00
|
|
|
setTimeout(() => {
|
2024-10-02 04:37:52 -04:00
|
|
|
alertElement.classList.add('fade-out'); // Add fade-out class to trigger animation
|
|
|
|
setTimeout(() => {
|
|
|
|
alertElement.style.display = 'none'; // Hide after animation finishes
|
|
|
|
}, 500); // Match this time to the animation duration
|
|
|
|
}, 3000); // Show the alert for 3 seconds before hiding
|
2024-10-02 03:32:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handles error responses based on status code
|
|
|
|
function handleErrorResponse(status) {
|
|
|
|
if (status === 429) {
|
|
|
|
displayAlert('error', 'Sorry, I am currently too busy at the moment!');
|
|
|
|
} else {
|
|
|
|
displayMessage('Error: ' + status, 'assistant');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-02 03:45:08 -04:00
|
|
|
// 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) {
|
2024-10-02 03:38:25 -04:00
|
|
|
try {
|
2024-10-02 03:45:08 -04:00
|
|
|
const response = await sendResetRequest();
|
2024-10-02 03:32:27 -04:00
|
|
|
|
2024-10-02 03:38:25 -04:00
|
|
|
if (response.ok) {
|
|
|
|
const messagesContainer = document.getElementById('messages');
|
|
|
|
messagesContainer.innerHTML = ''; // Clear all messages
|
|
|
|
|
2024-10-02 03:45:08 -04:00
|
|
|
if (displaySuccessMessage) {
|
|
|
|
displayAlert('success', 'Messages Cleared!');
|
|
|
|
}
|
2024-10-02 03:38:25 -04:00
|
|
|
} else {
|
|
|
|
displayAlert('error', 'Failed to reset conversation. Please try again.');
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
displayAlert('error', 'An error occurred while resetting the conversation.');
|
|
|
|
}
|
2024-10-02 03:32:27 -04:00
|
|
|
}
|
2024-10-02 03:45:08 -04:00
|
|
|
|
|
|
|
// Resets the chat on page load without displaying the success message
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
2024-10-02 04:03:47 -04:00
|
|
|
resetChat(false);
|
2024-10-02 03:45:08 -04:00
|
|
|
});
|
2024-10-02 03:32:27 -04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|