Spaces:
Sleeping
Sleeping
Update frontend/index.html
Browse files- frontend/index.html +73 -8
frontend/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Google Docs Knowledge Chatbot</title>
|
| 7 |
-
<link rel="stylesheet" href="static/styles.css">
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<div class="container">
|
|
@@ -130,9 +130,25 @@
|
|
| 130 |
|
| 131 |
if (response.ok) {
|
| 132 |
isIndexed = true;
|
| 133 |
-
|
| 134 |
-
π Documents processed: ${data.documents_processed}
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
// Enable chat
|
| 138 |
document.getElementById('question').disabled = false;
|
|
@@ -144,10 +160,37 @@
|
|
| 144 |
// Refresh document list
|
| 145 |
await listDocuments();
|
| 146 |
} else {
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
}
|
| 149 |
} catch (error) {
|
| 150 |
-
statusDiv.innerHTML = `<span class="error">β Error: ${error.message}
|
| 151 |
} finally {
|
| 152 |
indexBtn.disabled = false;
|
| 153 |
indexBtn.textContent = 'π₯ Index All Documents';
|
|
@@ -259,10 +302,32 @@
|
|
| 259 |
}
|
| 260 |
}
|
| 261 |
} else {
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
}
|
| 264 |
} catch (error) {
|
| 265 |
-
addMessage(`Error: ${error.message}
|
| 266 |
} finally {
|
| 267 |
sendBtn.disabled = false;
|
| 268 |
sendBtn.textContent = 'Send';
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Google Docs Knowledge Chatbot</title>
|
| 7 |
+
<link rel="stylesheet" href="/static/styles.css">
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<div class="container">
|
|
|
|
| 130 |
|
| 131 |
if (response.ok) {
|
| 132 |
isIndexed = true;
|
| 133 |
+
let statusHtml = `<span class="success">β
${data.message}<br>
|
| 134 |
+
π Documents processed: ${data.documents_processed}`;
|
| 135 |
+
|
| 136 |
+
if (data.total_documents) {
|
| 137 |
+
statusHtml += ` / ${data.total_documents}`;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
statusHtml += `<br>π¦ Total chunks indexed: ${data.chunks_indexed}</span>`;
|
| 141 |
+
|
| 142 |
+
// Show warnings if any documents failed
|
| 143 |
+
if (data.warnings && data.warnings.failed_documents) {
|
| 144 |
+
statusHtml += '<div class="warning-box"><strong>β οΈ Warnings:</strong><ul>';
|
| 145 |
+
data.warnings.failed_documents.forEach(doc => {
|
| 146 |
+
statusHtml += `<li><strong>${doc.name}:</strong> ${doc.error}</li>`;
|
| 147 |
+
});
|
| 148 |
+
statusHtml += '</ul></div>';
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
statusDiv.innerHTML = statusHtml;
|
| 152 |
|
| 153 |
// Enable chat
|
| 154 |
document.getElementById('question').disabled = false;
|
|
|
|
| 160 |
// Refresh document list
|
| 161 |
await listDocuments();
|
| 162 |
} else {
|
| 163 |
+
// Handle detailed error responses
|
| 164 |
+
let errorHtml = '<span class="error">';
|
| 165 |
+
|
| 166 |
+
if (data.detail && typeof data.detail === 'object') {
|
| 167 |
+
errorHtml += `β <strong>${data.detail.error || 'Error'}</strong><br>`;
|
| 168 |
+
errorHtml += `${data.detail.message}<br>`;
|
| 169 |
+
|
| 170 |
+
if (data.detail.steps) {
|
| 171 |
+
errorHtml += '<br><strong>Steps to fix:</strong><ul>';
|
| 172 |
+
data.detail.steps.forEach(step => {
|
| 173 |
+
errorHtml += `<li>${step}</li>`;
|
| 174 |
+
});
|
| 175 |
+
errorHtml += '</ul>';
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
if (data.detail.failed_documents) {
|
| 179 |
+
errorHtml += '<br><strong>Failed documents:</strong><ul>';
|
| 180 |
+
data.detail.failed_documents.forEach(doc => {
|
| 181 |
+
errorHtml += `<li>${doc.name}: ${doc.error}</li>`;
|
| 182 |
+
});
|
| 183 |
+
errorHtml += '</ul>';
|
| 184 |
+
}
|
| 185 |
+
} else {
|
| 186 |
+
errorHtml += `β Error: ${data.detail || 'Unknown error'}`;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
errorHtml += '</span>';
|
| 190 |
+
statusDiv.innerHTML = errorHtml;
|
| 191 |
}
|
| 192 |
} catch (error) {
|
| 193 |
+
statusDiv.innerHTML = `<span class="error">β Network Error: ${error.message}<br>Please check your connection and try again.</span>`;
|
| 194 |
} finally {
|
| 195 |
indexBtn.disabled = false;
|
| 196 |
indexBtn.textContent = 'π₯ Index All Documents';
|
|
|
|
| 302 |
}
|
| 303 |
}
|
| 304 |
} else {
|
| 305 |
+
// Handle detailed error responses
|
| 306 |
+
let errorMsg = 'Error: ';
|
| 307 |
+
|
| 308 |
+
if (data.detail && typeof data.detail === 'object') {
|
| 309 |
+
errorMsg += `<strong>${data.detail.error || 'Unknown Error'}</strong><br>${data.detail.message}`;
|
| 310 |
+
|
| 311 |
+
if (data.detail.steps) {
|
| 312 |
+
errorMsg += '<br><br><strong>Try this:</strong><ul>';
|
| 313 |
+
data.detail.steps.forEach(step => {
|
| 314 |
+
errorMsg += `<li>${step}</li>`;
|
| 315 |
+
});
|
| 316 |
+
errorMsg += '</ul>';
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
// Special handling for rate limits
|
| 320 |
+
if (data.detail.retry_after) {
|
| 321 |
+
errorMsg += `<br><em>Please retry after: ${data.detail.retry_after}</em>`;
|
| 322 |
+
}
|
| 323 |
+
} else {
|
| 324 |
+
errorMsg += data.detail || 'Unknown error occurred';
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
addMessage(errorMsg, 'bot');
|
| 328 |
}
|
| 329 |
} catch (error) {
|
| 330 |
+
addMessage(`Network Error: ${error.message}<br>Please check your connection and try again.`, 'bot');
|
| 331 |
} finally {
|
| 332 |
sendBtn.disabled = false;
|
| 333 |
sendBtn.textContent = 'Send';
|