about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-01-05 07:42:27 -0500
committerelioat <elioat@tilde.institute>2025-01-05 07:42:27 -0500
commit6294cb0306f9aa8d039ba1b7ec4f871685b10db9 (patch)
tree95a38940cc9a9ec4bfb3a757e2e3a385c2df1fbd
parent9f0f8dc0787596f608051fe661a449eae6b192f0 (diff)
downloadtour-6294cb0306f9aa8d039ba1b7ec4f871685b10db9.tar.gz
*
-rw-r--r--html/matt-chat/index.html39
1 files changed, 32 insertions, 7 deletions
diff --git a/html/matt-chat/index.html b/html/matt-chat/index.html
index 391bb95..2bc594d 100644
--- a/html/matt-chat/index.html
+++ b/html/matt-chat/index.html
@@ -200,27 +200,38 @@
 
         let isCatMode = false; // Flag to track cat mode
 
+        const API_URL = "http://localhost:11434/v1";
+
         async function populateModelSelect() {
             const modelSelect = document.getElementById("model-select");
             modelSelect.innerHTML = ""; // Clear existing options
 
+            // Show loading indicator
+            const loadingMessage = addMessage("Loading models...", "bot");
+
+            // Declare modelIds outside the try block
+            const modelIds = [];
+
             try {
-                const response = await fetch("http://localhost:11434/v1/models"); // Adjust the endpoint as needed
+                const response = await fetch(`${API_URL}/models`);
                 if (!response.ok) {
                     throw new Error('Failed to fetch models');
                 }
-                const data = await response.json(); // Get the JSON response
+                const data = await response.json();
 
-                console.log("API Response:", data); // Log the response for debugging
+                console.log("API Response:", data);
 
-                // Check if the response contains a data array
-                if (Array.isArray(data.data)) { // Access the data array
+                if (Array.isArray(data.data)) {
                     data.data.forEach(model => {
                         const option = document.createElement("option");
-                        option.value = model.id; // Use the id from the model
-                        option.textContent = model.id; // Use the id for display (you can customize this)
+                        option.value = model.id;
+                        option.textContent = model.id; // Customize as needed
                         modelSelect.appendChild(option);
+                        
+                        // Add model ID to the array
+                        modelIds.push(model.id);
                     });
+                    console.log("Model IDs:", modelIds); // Debugging log to check model IDs
                 } else {
                     console.error("Expected an array of models, but got:", data);
                     addMessage("Error: Expected an array of models, but got an unexpected response.", "bot");
@@ -228,6 +239,17 @@
             } catch (error) {
                 console.error("Error fetching models:", error);
                 addMessage("Error fetching models. Please check the console for details.", "bot");
+            } finally {
+                // Remove loading indicator
+                loadingMessage.remove();
+                
+                // Check if modelIds is populated before displaying the success message
+                if (modelIds.length > 0) {
+                    // Display a message indicating readiness to chat with the list of models
+                    addMessage(`Models loaded successfully! Ready to chat. Available models: ${modelIds.join(', ')}`, "bot");
+                } else {
+                    addMessage("No models available to chat.", "bot");
+                }
             }
         }
 
@@ -261,6 +283,9 @@
             
             // Force scroll to bottom in case the scrollIntoView doesn't work in some browsers
             chatContainer.scrollTop = chatContainer.scrollHeight;
+
+            // Return the message element for further manipulation
+            return messageElement;
         }
 
         // Fancy format milliseconds into a more readable format