2025-01-24 13:52:26 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
2025-01-24 16:05:20 +01:00
|
|
|
<title>RAG WebUI</title>
|
2025-01-24 13:52:26 +01:00
|
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
2025-01-24 14:35:41 +01:00
|
|
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> <!-- Include Marked.js -->
|
2025-01-24 13:52:26 +01:00
|
|
|
</head>
|
|
|
|
<body class="bg-gray-100 min-h-screen flex flex-col items-center justify-center p-4">
|
2025-01-24 14:02:12 +01:00
|
|
|
<div class="w-full max-w-4xl bg-white shadow-md rounded-lg p-6 relative">
|
|
|
|
<!-- Settings Button -->
|
|
|
|
<button id="settingsButton" class="absolute top-4 right-4 text-gray-600 hover:text-gray-800">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
2025-01-24 16:05:20 +01:00
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 2a10 10 0 0110 10 10 10 0 01-10 10A10 10 0 012 12a10 10 0 0110-10zm0 2a8 8 0 100 16 8 8 0 000-16zm1 4h-2v4h2V8zm0 6h-2v2h2v-2z" />
|
2025-01-24 14:02:12 +01:00
|
|
|
</svg>
|
|
|
|
</button>
|
2025-01-24 13:52:26 +01:00
|
|
|
|
2025-01-24 16:05:20 +01:00
|
|
|
<!-- Modal for Settings -->
|
2025-01-24 14:02:12 +01:00
|
|
|
<div id="settingsModal" class="hidden fixed inset-0 bg-gray-800 bg-opacity-50 flex items-center justify-center">
|
|
|
|
<div class="bg-white rounded-lg shadow-lg p-6 w-full max-w-md">
|
|
|
|
<h2 class="text-lg font-semibold text-gray-700 mb-4">Settings</h2>
|
|
|
|
<div class="flex flex-col gap-4">
|
|
|
|
<input type="text" id="bearerKeyInput" class="w-full p-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Enter Bearer Key">
|
|
|
|
<button id="saveBearerKey" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">Save Key</button>
|
|
|
|
<button id="closeSettings" class="text-gray-500 hover:text-gray-700 text-sm">Close</button>
|
|
|
|
</div>
|
|
|
|
<div id="bearerKeyStatus" class="mt-2 text-sm text-gray-600"></div>
|
2025-01-24 14:01:06 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2025-01-24 16:05:20 +01:00
|
|
|
<!-- Health Check Button -->
|
|
|
|
<button id="healthCheckButton" class="absolute top-4 left-4 text-gray-600 hover:text-gray-800">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-3-3v6m-7 4a9 9 0 1118 0H5z" />
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<!-- Modal for Health Check -->
|
|
|
|
<div id="healthModal" class="hidden fixed inset-0 bg-gray-800 bg-opacity-50 flex items-center justify-center">
|
|
|
|
<div class="bg-white rounded-lg shadow-lg p-6 w-full max-w-lg">
|
|
|
|
<h2 class="text-lg font-semibold text-gray-700 mb-4">System Health</h2>
|
|
|
|
<div id="healthInfo" class="text-sm text-gray-600"></div>
|
|
|
|
<button id="closeHealth" class="mt-4 bg-gray-500 text-white px-4 py-2 rounded hover:bg-gray-600">Close</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2025-01-24 14:02:12 +01:00
|
|
|
<!-- Main Content -->
|
|
|
|
<h1 class="text-2xl font-bold text-gray-800 mb-4">RAG WebUI</h1>
|
|
|
|
|
2025-01-24 13:52:26 +01:00
|
|
|
<!-- File Upload Section -->
|
|
|
|
<div class="mb-6">
|
|
|
|
<h2 class="text-lg font-semibold text-gray-700 mb-2">Upload Files</h2>
|
|
|
|
<form id="uploadForm" class="flex flex-col gap-4">
|
|
|
|
<input type="file" id="fileInput" multiple class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100">
|
|
|
|
<button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">Upload</button>
|
|
|
|
</form>
|
|
|
|
<div id="uploadStatus" class="mt-2 text-sm text-gray-600"></div>
|
2025-01-24 14:35:41 +01:00
|
|
|
<div id="progressContainer" class="mt-4 hidden">
|
|
|
|
<div id="progressBar" class="w-full bg-gray-200 rounded h-4">
|
|
|
|
<div class="bg-blue-500 h-4 rounded" style="width: 0%;"></div>
|
|
|
|
</div>
|
|
|
|
<p id="progressText" class="text-sm text-gray-600 mt-2"></p>
|
|
|
|
</div>
|
2025-01-24 13:52:26 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Query Section -->
|
|
|
|
<div class="mb-6">
|
|
|
|
<h2 class="text-lg font-semibold text-gray-700 mb-2">Query</h2>
|
|
|
|
<form id="queryForm" class="flex flex-col gap-4">
|
|
|
|
<textarea id="queryInput" rows="4" class="w-full p-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Enter your query here..."></textarea>
|
|
|
|
<button type="submit" class="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600">Submit Query</button>
|
|
|
|
</form>
|
|
|
|
<div id="queryResponse" class="mt-4 p-4 bg-gray-50 border rounded text-gray-700"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
2025-01-24 14:02:12 +01:00
|
|
|
// Modal Handling
|
|
|
|
const settingsButton = document.getElementById('settingsButton');
|
|
|
|
const settingsModal = document.getElementById('settingsModal');
|
|
|
|
const closeSettings = document.getElementById('closeSettings');
|
|
|
|
|
|
|
|
settingsButton.addEventListener('click', () => {
|
|
|
|
settingsModal.classList.remove('hidden');
|
|
|
|
});
|
|
|
|
|
|
|
|
closeSettings.addEventListener('click', () => {
|
|
|
|
settingsModal.classList.add('hidden');
|
|
|
|
});
|
|
|
|
|
2025-01-24 16:05:20 +01:00
|
|
|
// Health Check Modal Handling
|
|
|
|
const healthCheckButton = document.getElementById('healthCheckButton');
|
|
|
|
const healthModal = document.getElementById('healthModal');
|
|
|
|
const closeHealth = document.getElementById('closeHealth');
|
|
|
|
const healthInfo = document.getElementById('healthInfo');
|
2025-01-24 14:01:06 +01:00
|
|
|
|
2025-01-24 16:05:20 +01:00
|
|
|
healthCheckButton.addEventListener('click', async () => {
|
|
|
|
healthModal.classList.remove('hidden');
|
|
|
|
healthInfo.textContent = "Fetching system health...";
|
|
|
|
try {
|
|
|
|
const response = await fetch('/health', {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Authorization': `Bearer ${localStorage.getItem('bearerKey') || ''}`
|
|
|
|
}
|
|
|
|
});
|
2025-01-24 14:01:06 +01:00
|
|
|
|
2025-01-24 16:05:20 +01:00
|
|
|
if (response.ok) {
|
|
|
|
const data = await response.json();
|
|
|
|
healthInfo.innerHTML = `
|
|
|
|
<p><strong>Status:</strong> ${data.status}</p>
|
|
|
|
<p><strong>Working Directory:</strong> ${data.working_directory}</p>
|
|
|
|
<p><strong>Input Directory:</strong> ${data.input_directory}</p>
|
|
|
|
<p><strong>Indexed Files:</strong> ${data.indexed_files}</p>
|
|
|
|
<p><strong>Configuration:</strong></p>
|
|
|
|
<ul class="list-disc ml-6">
|
|
|
|
<li><strong>LLM Binding:</strong> ${data.configuration.llm_binding}</li>
|
|
|
|
<li><strong>LLM Host:</strong> ${data.configuration.llm_binding_host}</li>
|
|
|
|
<li><strong>LLM Model:</strong> ${data.configuration.llm_model}</li>
|
|
|
|
<li><strong>Embedding Binding:</strong> ${data.configuration.embedding_binding}</li>
|
|
|
|
<li><strong>Embedding Host:</strong> ${data.configuration.embedding_binding_host}</li>
|
|
|
|
<li><strong>Embedding Model:</strong> ${data.configuration.embedding_model}</li>
|
|
|
|
<li><strong>Max Tokens:</strong> ${data.configuration.max_tokens}</li>
|
|
|
|
</ul>
|
|
|
|
`;
|
|
|
|
} else {
|
|
|
|
const error = await response.json();
|
|
|
|
healthInfo.textContent = `Error: ${error.detail}`;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
healthInfo.textContent = `Error: ${err.message}`;
|
2025-01-24 14:01:06 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-01-24 16:05:20 +01:00
|
|
|
closeHealth.addEventListener('click', () => {
|
|
|
|
healthModal.classList.add('hidden');
|
|
|
|
});
|
|
|
|
|
2025-01-24 13:52:26 +01:00
|
|
|
// File Upload Handler
|
|
|
|
const uploadForm = document.getElementById('uploadForm');
|
|
|
|
const fileInput = document.getElementById('fileInput');
|
|
|
|
const uploadStatus = document.getElementById('uploadStatus');
|
2025-01-24 14:35:41 +01:00
|
|
|
const progressContainer = document.getElementById('progressContainer');
|
|
|
|
const progressBar = document.getElementById('progressBar').firstElementChild;
|
|
|
|
const progressText = document.getElementById('progressText');
|
2025-01-24 13:52:26 +01:00
|
|
|
|
|
|
|
uploadForm.addEventListener('submit', async (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const files = fileInput.files;
|
|
|
|
if (files.length === 0) {
|
|
|
|
uploadStatus.textContent = "Please select at least one file.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-01-24 14:35:41 +01:00
|
|
|
progressContainer.classList.remove('hidden');
|
|
|
|
uploadStatus.textContent = "Uploading files...";
|
|
|
|
let uploadedCount = 0;
|
|
|
|
|
|
|
|
for (const [index, file] of Array.from(files).entries()) {
|
|
|
|
const formData = new FormData();
|
2025-01-24 13:52:26 +01:00
|
|
|
formData.append('file', file);
|
|
|
|
|
2025-01-24 14:35:41 +01:00
|
|
|
try {
|
|
|
|
const response = await fetch('/documents/upload', {
|
|
|
|
method: 'POST',
|
|
|
|
body: formData,
|
|
|
|
headers: {
|
|
|
|
'Authorization': `Bearer ${localStorage.getItem('bearerKey') || ''}`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
uploadedCount++;
|
|
|
|
const progress = Math.round((uploadedCount / files.length) * 100);
|
|
|
|
progressBar.style.width = `${progress}%`;
|
|
|
|
progressText.textContent = `Uploading file ${index + 1} of ${files.length} (${progress}%)`;
|
|
|
|
} else {
|
|
|
|
const error = await response.json();
|
|
|
|
uploadStatus.textContent = `Error uploading file ${file.name}: ${error.detail}`;
|
|
|
|
break;
|
2025-01-24 14:01:06 +01:00
|
|
|
}
|
2025-01-24 14:35:41 +01:00
|
|
|
} catch (err) {
|
|
|
|
uploadStatus.textContent = `Error uploading file ${file.name}: ${err.message}`;
|
|
|
|
break;
|
2025-01-24 13:52:26 +01:00
|
|
|
}
|
|
|
|
}
|
2025-01-24 14:35:41 +01:00
|
|
|
|
|
|
|
if (uploadedCount === files.length) {
|
|
|
|
uploadStatus.textContent = "All files uploaded successfully!";
|
|
|
|
} else {
|
|
|
|
uploadStatus.textContent = "File upload interrupted.";
|
|
|
|
}
|
|
|
|
|
|
|
|
progressContainer.classList.add('hidden');
|
2025-01-24 13:52:26 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Query Handler
|
|
|
|
const queryForm = document.getElementById('queryForm');
|
|
|
|
const queryInput = document.getElementById('queryInput');
|
|
|
|
const queryResponse = document.getElementById('queryResponse');
|
|
|
|
|
|
|
|
queryForm.addEventListener('submit', async (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const query = queryInput.value.trim();
|
|
|
|
if (!query) {
|
|
|
|
queryResponse.textContent = "Please enter a query.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
queryResponse.textContent = "Processing...";
|
|
|
|
try {
|
|
|
|
const response = await fetch('/query', {
|
|
|
|
method: 'POST',
|
2025-01-24 14:01:06 +01:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Authorization': `Bearer ${localStorage.getItem('bearerKey') || ''}`
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ query })
|
2025-01-24 13:52:26 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
const data = await response.json();
|
2025-01-24 14:35:41 +01:00
|
|
|
queryResponse.innerHTML = marked(data.response); // Render Markdown as HTML
|
2025-01-24 13:52:26 +01:00
|
|
|
} else {
|
|
|
|
const error = await response.json();
|
|
|
|
queryResponse.textContent = `Error: ${error.detail}`;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
queryResponse.textContent = `Error: ${err.message}`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|