mode selection, settings added to ui
This commit is contained in:
@@ -14,18 +14,14 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="chat">
|
||||
<!-- Model selector -->
|
||||
<!-- Mode selector -->
|
||||
<div id="model-select">
|
||||
<label for="model">Model:</label>
|
||||
<select id="model">
|
||||
<option value="gpt-4o-mini">GPT-4o-mini (OpenAI)</option>
|
||||
<option value="ollama:nollama/mythomax-l2-13b:Q5_K_S">Ollama MythoMax (3090)</option>
|
||||
</select>
|
||||
<label for="mode" style="margin-left: 20px;">Mode:</label>
|
||||
<label for="mode">Mode:</label>
|
||||
<select id="mode">
|
||||
<option value="standard">Standard</option>
|
||||
<option value="cortex">Cortex</option>
|
||||
</select>
|
||||
<button id="settingsBtn" style="margin-left: auto;">⚙ Settings</button>
|
||||
<div id="theme-toggle">
|
||||
<button id="toggleThemeBtn">🌙 Dark Mode</button>
|
||||
</div>
|
||||
@@ -55,6 +51,44 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Settings Modal (outside chat container) -->
|
||||
<div id="settingsModal" class="modal">
|
||||
<div class="modal-overlay"></div>
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3>Settings</h3>
|
||||
<button id="closeModalBtn" class="close-btn">✕</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="settings-section">
|
||||
<h4>Standard Mode Backend</h4>
|
||||
<p class="settings-desc">Select which LLM backend to use for Standard Mode:</p>
|
||||
<div class="radio-group">
|
||||
<label class="radio-label">
|
||||
<input type="radio" name="backend" value="SECONDARY" checked>
|
||||
<span>SECONDARY - Ollama/Qwen (3090)</span>
|
||||
<small>Fast, local, good for general chat</small>
|
||||
</label>
|
||||
<label class="radio-label">
|
||||
<input type="radio" name="backend" value="OPENAI">
|
||||
<span>OPENAI - GPT-4o-mini</span>
|
||||
<small>Cloud-based, high quality (costs money)</small>
|
||||
</label>
|
||||
<label class="radio-label">
|
||||
<input type="radio" name="backend" value="custom">
|
||||
<span>Custom Backend</span>
|
||||
<input type="text" id="customBackend" placeholder="e.g., PRIMARY, FALLBACK" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="saveSettingsBtn" class="primary-btn">Save</button>
|
||||
<button id="cancelSettingsBtn">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const RELAY_BASE = "http://10.0.0.41:7078";
|
||||
const API_URL = `${RELAY_BASE}/v1/chat/completions`;
|
||||
@@ -128,7 +162,6 @@
|
||||
await saveSession(); // ✅ persist both user + assistant messages
|
||||
|
||||
|
||||
const model = document.getElementById("model").value;
|
||||
const mode = document.getElementById("mode").value;
|
||||
|
||||
// make sure we always include a stable user_id
|
||||
@@ -137,13 +170,24 @@
|
||||
userId = "brian"; // use whatever ID you seeded Mem0 with
|
||||
localStorage.setItem("userId", userId);
|
||||
}
|
||||
|
||||
// Get backend preference for Standard Mode
|
||||
let backend = null;
|
||||
if (mode === "standard") {
|
||||
backend = localStorage.getItem("standardModeBackend") || "SECONDARY";
|
||||
}
|
||||
|
||||
const body = {
|
||||
model: model,
|
||||
mode: mode,
|
||||
messages: history,
|
||||
sessionId: currentSession
|
||||
};
|
||||
|
||||
// Only add backend if in standard mode
|
||||
if (backend) {
|
||||
body.backend = backend;
|
||||
}
|
||||
|
||||
try {
|
||||
const resp = await fetch(API_URL, {
|
||||
method: "POST",
|
||||
@@ -194,18 +238,25 @@
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Dark mode toggle
|
||||
// Dark mode toggle - defaults to dark
|
||||
const btn = document.getElementById("toggleThemeBtn");
|
||||
|
||||
// Set dark mode by default if no preference saved
|
||||
const savedTheme = localStorage.getItem("theme");
|
||||
if (!savedTheme || savedTheme === "dark") {
|
||||
document.body.classList.add("dark");
|
||||
btn.textContent = "☀️ Light Mode";
|
||||
localStorage.setItem("theme", "dark");
|
||||
} else {
|
||||
btn.textContent = "🌙 Dark Mode";
|
||||
}
|
||||
|
||||
btn.addEventListener("click", () => {
|
||||
document.body.classList.toggle("dark");
|
||||
const isDark = document.body.classList.contains("dark");
|
||||
btn.textContent = isDark ? "☀️ Light Mode" : "🌙 Dark Mode";
|
||||
localStorage.setItem("theme", isDark ? "dark" : "light");
|
||||
});
|
||||
if (localStorage.getItem("theme") === "dark") {
|
||||
document.body.classList.add("dark");
|
||||
btn.textContent = "☀️ Light Mode";
|
||||
}
|
||||
|
||||
// Sessions
|
||||
// Populate dropdown initially
|
||||
@@ -262,6 +313,69 @@
|
||||
|
||||
|
||||
|
||||
// Settings Modal
|
||||
const settingsModal = document.getElementById("settingsModal");
|
||||
const settingsBtn = document.getElementById("settingsBtn");
|
||||
const closeModalBtn = document.getElementById("closeModalBtn");
|
||||
const saveSettingsBtn = document.getElementById("saveSettingsBtn");
|
||||
const cancelSettingsBtn = document.getElementById("cancelSettingsBtn");
|
||||
const modalOverlay = document.querySelector(".modal-overlay");
|
||||
|
||||
// Load saved backend preference
|
||||
const savedBackend = localStorage.getItem("standardModeBackend") || "SECONDARY";
|
||||
|
||||
// Set initial radio button state
|
||||
const backendRadios = document.querySelectorAll('input[name="backend"]');
|
||||
let isCustomBackend = !["SECONDARY", "OPENAI"].includes(savedBackend);
|
||||
|
||||
if (isCustomBackend) {
|
||||
document.querySelector('input[name="backend"][value="custom"]').checked = true;
|
||||
document.getElementById("customBackend").value = savedBackend;
|
||||
} else {
|
||||
document.querySelector(`input[name="backend"][value="${savedBackend}"]`).checked = true;
|
||||
}
|
||||
|
||||
// Show modal
|
||||
settingsBtn.addEventListener("click", () => {
|
||||
settingsModal.classList.add("show");
|
||||
});
|
||||
|
||||
// Hide modal functions
|
||||
const hideModal = () => {
|
||||
settingsModal.classList.remove("show");
|
||||
};
|
||||
|
||||
closeModalBtn.addEventListener("click", hideModal);
|
||||
cancelSettingsBtn.addEventListener("click", hideModal);
|
||||
modalOverlay.addEventListener("click", hideModal);
|
||||
|
||||
// ESC key to close
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape" && settingsModal.classList.contains("show")) {
|
||||
hideModal();
|
||||
}
|
||||
});
|
||||
|
||||
// Save settings
|
||||
saveSettingsBtn.addEventListener("click", () => {
|
||||
const selectedRadio = document.querySelector('input[name="backend"]:checked');
|
||||
let backendValue;
|
||||
|
||||
if (selectedRadio.value === "custom") {
|
||||
backendValue = document.getElementById("customBackend").value.trim().toUpperCase();
|
||||
if (!backendValue) {
|
||||
alert("Please enter a custom backend name");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
backendValue = selectedRadio.value;
|
||||
}
|
||||
|
||||
localStorage.setItem("standardModeBackend", backendValue);
|
||||
addMessage("system", `Backend changed to: ${backendValue}`);
|
||||
hideModal();
|
||||
});
|
||||
|
||||
// Health check
|
||||
checkHealth();
|
||||
setInterval(checkHealth, 10000);
|
||||
|
||||
Reference in New Issue
Block a user