about summary refs log tree commit diff stats
path: root/html/matt-chat
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-01-05 09:48:47 -0500
committerelioat <elioat@tilde.institute>2025-01-05 09:48:47 -0500
commit6b7b331751ad0537982de4338882bfee89ec4380 (patch)
tree8e55ac816f2a6577c730dc804dafae6af5926553 /html/matt-chat
parent936d3a40331ec0b744e078483ad49fcee67a1308 (diff)
downloadtour-6b7b331751ad0537982de4338882bfee89ec4380.tar.gz
*
Diffstat (limited to 'html/matt-chat')
-rw-r--r--html/matt-chat/index.html31
1 files changed, 7 insertions, 24 deletions
diff --git a/html/matt-chat/index.html b/html/matt-chat/index.html
index f8c44e6..25c61aa 100644
--- a/html/matt-chat/index.html
+++ b/html/matt-chat/index.html
@@ -750,18 +750,15 @@
             'lcars': 'Boldly going'
         };
 
-        // Function to handle errors
         function handleError(message) {
             console.error(message);
             addMessage(message, "bot");
         }
 
-        // Function to show loading message
         function showLoadingMessage() {
             return addMessage("Loading models...", "bot");
         }
 
-        // Function to populate model select dropdown
         async function populateModelSelect() {
             const modelSelect = document.getElementById("model-select");
             modelSelect.innerHTML = ""; // Clear existing options
@@ -780,7 +777,7 @@
                     data.data.forEach(model => {
                         const option = document.createElement("option");
                         option.value = model.id;
-                        option.textContent = model.id; // Customize as needed
+                        option.textContent = model.id;
                         modelSelect.appendChild(option);
                         modelIds.push(model.id);
                     });
@@ -820,11 +817,8 @@
             messageElement.classList.add("message", sender === "user" ? "user-message" : "bot-message");
             messageElement.textContent = message;
             chatContainer.appendChild(messageElement);
-            
-            // Scroll to the new message with a smooth animation
             messageElement.scrollIntoView({ behavior: "smooth", block: "end" });
             chatContainer.scrollTop = chatContainer.scrollHeight; // Make sure the chat is scrolled to the bottom
-
             return messageElement; // Return the message element so it is easier to use
         }
 
@@ -867,7 +861,6 @@
             addMessage(`Cat mode is now ${isCatMode ? "enabled" : "disabled"}.`, "bot"); // Inform the user
         }
 
-        // Function to handle sending the message
         async function sendMessage() {
             const userInput = document.getElementById("user-input");
             const userMessage = userInput.value.trim();
@@ -968,7 +961,7 @@
                 }
 
                 const data = await response.json();
-                console.log("API Response:", data); // Log the response for debugging
+                console.log("API Response:", data);
 
                 if (data.choices && data.choices.length > 0) {
                     const botResponse = data.choices[0].message.content;
@@ -996,7 +989,6 @@
                     addMessage("Sorry, I didn't get a response from the assistant.", "bot");
                 }
 
-                // Optional: Limit the conversation history to the last 10 messages
                 if (conversationHistory.current.length > 10) {
                     conversationHistory.current.shift(); // Remove the oldest message
                 }
@@ -1009,7 +1001,6 @@
             }
         }
 
-        // Basic animation for the loading indicator
         function animateLoadingIndicator(indicator) {
             let dots = 0;
             return setInterval(() => {
@@ -1020,10 +1011,8 @@
             }, 500);
         }
 
-        // Event listener for the "Send" button
         document.getElementById("send-button").addEventListener("click", sendMessage);
 
-        // Use Enter to send the message, too
         document.getElementById("user-input").addEventListener("keypress", function (e) {
             if (e.key === "Enter") {
                 e.preventDefault(); // Prevent line break
@@ -1136,18 +1125,18 @@ Available commands:\n
                 messages.push(...conversationHistory.current);
             }
             
-            // We'll add the new message to history here, before we check for summarization
+            // Add the new message to history before we check for summarization
             const newMessage = { role: "user", content: userMessage };
             conversationHistory.current.push(newMessage);
             messages.push(newMessage);
             
-            // Check if we need to summarize
+            // Do we need to summarize?
             const totalTokens = getContextSize(messages);
             if (totalTokens > config.summarizeThreshold) {
                 // Move current messages to full history, except for the newest message
                 conversationHistory.full.push(...conversationHistory.current.slice(0, -1));
                 
-                // Create a more natural summarization prompt
+                // Supposedly this is a more natural summarization prompt...
                 const summary = await summarizeConversation([
                     {
                         role: "system",
@@ -1173,7 +1162,7 @@ Available commands:\n
             return messages;
         }
 
-        // Add a function to clean up old messages periodically
+        // Clean up old messages periodically
         function pruneConversationHistory() {
             if (conversationHistory.full.length > 100) {
                 // Keep only the last 100 messages in full history
@@ -1184,7 +1173,6 @@ Available commands:\n
         // Call this after successful responses
         setInterval(pruneConversationHistory, 60000); // Clean up every minute
 
-        // Add these functions to help debug and manage context
         function viewCurrentContext() {
             const context = {
                 summary: conversationHistory.summary,
@@ -1196,13 +1184,11 @@ Available commands:\n
             return context;
         }
 
-        // Add this helper function
         function scrollToBottom() {
             const chatContainer = document.getElementById("chat-container");
             chatContainer.scrollTop = chatContainer.scrollHeight;
         }
 
-        // Add this function to handle theme switching
         function switchTheme(themeName) {
             // Remove all theme classes
             Object.keys(AVAILABLE_THEMES).forEach(theme => {
@@ -1235,10 +1221,7 @@ Available commands:\n
                 }
             }
             
-            // Save to localStorage
-            localStorage.setItem('selectedTheme', themeName);
-            
-            // Notify user
+            localStorage.setItem('selectedTheme', themeName);            
             addMessage(`Theme switched to: ${AVAILABLE_THEMES[themeName]}`, "bot");
         }
     </script>