Docfile commited on
Commit
67ff1a0
·
verified ·
1 Parent(s): ff4e0c9

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +66 -5
templates/index.html CHANGED
@@ -167,12 +167,20 @@
167
  <div class="bg-gray-50 border-t border-gray-200 px-4 py-2 flex-shrink-0">
168
  <div class="flex items-center justify-between text-sm">
169
  <label for="web_search_toggle" class="flex items-center space-x-2 cursor-pointer text-gray-600 hover:text-gray-800 select-none" title="Activer/Désactiver la recherche web pour le prochain message">
170
- <input type="checkbox" id="web_search_toggle" name="web_search" value="true" class="form-checkbox h-4 w-4 rounded text-blue-500 focus:ring-blue-400 focus:ring-offset-0 border-gray-300">
171
  <span class="hidden sm:inline">Recherche Web</span>
172
  <span class="sm:hidden">Web</span>
173
  </label>
 
 
 
 
 
 
 
 
174
  <div class="flex items-center space-x-2">
175
- <label for="file_upload" class="cursor-pointer text-blue-500 hover:text-blue-700 font-medium flex items-center" title="Joindre un fichier (txt, pdf, png, jpg)">
176
  <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
177
  <path stroke-linecap="round" stroke-linejoin="round" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13" />
178
  </svg>
@@ -221,6 +229,8 @@
221
  const filePreview = document.getElementById('file-preview');
222
  const sendButton = document.getElementById('send-button');
223
  const clearForm = document.getElementById('clear-form');
 
 
224
 
225
  const API_CHAT_ENDPOINT = '/api/chat';
226
  const API_HISTORY_ENDPOINT = '/api/history';
@@ -232,6 +242,9 @@
232
  }, 50);
233
  }
234
 
 
 
 
235
  function showLoading(show) {
236
  const currentlyLoading = loadingIndicator.style.display !== 'none';
237
  if (show && !currentlyLoading) {
@@ -245,6 +258,7 @@
245
  promptInput.disabled = show;
246
  fileUpload.disabled = show;
247
  clearFileButton.disabled = show;
 
248
  }
249
 
250
  function displayError(message) {
@@ -314,6 +328,28 @@
314
  }
315
  }
316
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  async function loadChatHistory() {
318
  historyLoadingIndicator.style.display = 'block';
319
  try {
@@ -395,14 +431,29 @@
395
  const prompt = promptInput.value.trim();
396
  const file = fileUpload.files[0];
397
  const useWebSearch = webSearchToggle.checked;
 
 
398
  if (!prompt && !file) {
399
  displayError("Veuillez entrer un message ou sélectionner un fichier.");
400
  promptInput.focus();
401
  return;
402
  }
403
  errorMessageDiv.style.display = 'none';
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  let userMessageText = prompt;
405
- if (file) {
406
  userMessageText = prompt ? `[${file.name}] ${prompt}` : `[${file.name}]`;
407
  }
408
  addMessageToChat('user', userMessageText);
@@ -410,11 +461,20 @@
410
  formData.append('prompt', prompt);
411
  formData.append('web_search', useWebSearch);
412
  if (file) {
413
- formData.append('file', file);
414
  }
 
 
 
415
  showLoading(true);
416
  promptInput.value = '';
417
  clearFileInput();
 
 
 
 
 
 
418
  try {
419
  const response = await fetch(API_CHAT_ENDPOINT, {
420
  method: 'POST',
@@ -431,6 +491,7 @@
431
  }
432
  } catch (error) {
433
  displayError(error.message);
 
434
  } finally {
435
  showLoading(false);
436
  promptInput.focus();
@@ -474,4 +535,4 @@
474
  });
475
  </script>
476
  </body>
477
- </html>
 
167
  <div class="bg-gray-50 border-t border-gray-200 px-4 py-2 flex-shrink-0">
168
  <div class="flex items-center justify-between text-sm">
169
  <label for="web_search_toggle" class="flex items-center space-x-2 cursor-pointer text-gray-600 hover:text-gray-800 select-none" title="Activer/Désactiver la recherche web pour le prochain message">
170
+ <input type="checkbox" id="web_search_toggle" name="web_search" value="true" class="form-checkbox h-4 w-4 rounded text-blue-600 focus:ring-blue-500 focus:ring-offset-0 border-gray-300">
171
  <span class="hidden sm:inline">Recherche Web</span>
172
  <span class="sm:hidden">Web</span>
173
  </label>
174
+
175
+ <label for="advanced_reasoning_toggle" class="flex items-center space-x-2 cursor-pointer text-purple-600 hover:text-purple-800 select-none" title="Utiliser le raisonnement avancé (Gemini 1.5 Pro - 1 fois/min)">
176
+ <input type="checkbox" id="advanced_reasoning_toggle" name="advanced_reasoning" value="true" class="form-checkbox h-4 w-4 rounded text-purple-600 focus:ring-purple-500 focus:ring-offset-0 border-gray-300">
177
+ <span class="hidden sm:inline">Raisonnement Avancé</span>
178
+ <span class="sm:hidden">Avancé</span>
179
+ <span id="advanced-cooldown-timer" class="text-xs text-gray-500 ml-1" style="display: none;"></span>
180
+ </label>
181
+
182
  <div class="flex items-center space-x-2">
183
+ <label for="file_upload" class="cursor-pointer text-blue-600 hover:text-blue-700 font-medium flex items-center" title="Joindre un fichier (txt, pdf, png, jpg)">
184
  <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
185
  <path stroke-linecap="round" stroke-linejoin="round" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13" />
186
  </svg>
 
229
  const filePreview = document.getElementById('file-preview');
230
  const sendButton = document.getElementById('send-button');
231
  const clearForm = document.getElementById('clear-form');
232
+ const advancedToggle = document.getElementById('advanced_reasoning_toggle');
233
+ const advancedCooldownTimerSpan = document.getElementById('advanced-cooldown-timer');
234
 
235
  const API_CHAT_ENDPOINT = '/api/chat';
236
  const API_HISTORY_ENDPOINT = '/api/history';
 
242
  }, 50);
243
  }
244
 
245
+ let advancedToggleCooldownEndTime = 0; // Timestamp when cooldown ends
246
+ const COOLDOWN_DURATION = 60 * 1000; // 60 seconds in milliseconds
247
+
248
  function showLoading(show) {
249
  const currentlyLoading = loadingIndicator.style.display !== 'none';
250
  if (show && !currentlyLoading) {
 
258
  promptInput.disabled = show;
259
  fileUpload.disabled = show;
260
  clearFileButton.disabled = show;
261
+ // Don't disable advanced toggle during loading, only during cooldown
262
  }
263
 
264
  function displayError(message) {
 
328
  }
329
  }
330
 
331
+ function startAdvancedCooldownTimer() {
332
+ advancedToggle.disabled = true; // Disable toggle during cooldown
333
+ advancedToggleCooldownEndTime = Date.now() + COOLDOWN_DURATION;
334
+
335
+ const updateTimer = () => {
336
+ const now = Date.now();
337
+ if (now >= advancedToggleCooldownEndTime) {
338
+ clearInterval(intervalId);
339
+ advancedCooldownTimerSpan.style.display = 'none';
340
+ advancedToggle.disabled = false;
341
+ advancedToggleCooldownEndTime = 0; // Reset cooldown end time
342
+ } else {
343
+ const remainingSeconds = Math.ceil((advancedToggleCooldownEndTime - now) / 1000);
344
+ advancedCooldownTimerSpan.textContent = `(${remainingSeconds}s)`;
345
+ advancedCooldownTimerSpan.style.display = 'inline';
346
+ }
347
+ };
348
+
349
+ const intervalId = setInterval(updateTimer, 1000);
350
+ updateTimer(); // Initial call to display immediately
351
+ }
352
+
353
  async function loadChatHistory() {
354
  historyLoadingIndicator.style.display = 'block';
355
  try {
 
431
  const prompt = promptInput.value.trim();
432
  const file = fileUpload.files[0];
433
  const useWebSearch = webSearchToggle.checked;
434
+ const useAdvanced = advancedToggle.checked;
435
+
436
  if (!prompt && !file) {
437
  displayError("Veuillez entrer un message ou sélectionner un fichier.");
438
  promptInput.focus();
439
  return;
440
  }
441
  errorMessageDiv.style.display = 'none';
442
+
443
+ // --- Cooldown Check for Advanced Reasoning ---
444
+ if (useAdvanced) {
445
+ const now = Date.now();
446
+ if (now < advancedToggleCooldownEndTime) {
447
+ const remainingSeconds = Math.ceil((advancedToggleCooldownEndTime - now) / 1000);
448
+ displayError(`Le raisonnement avancé est disponible dans ${remainingSeconds} seconde(s).`);
449
+ return; // Stop submission
450
+ }
451
+ // If check passes, cooldown will be started AFTER successful submission trigger
452
+ }
453
+ // --- End Cooldown Check ---
454
+
455
  let userMessageText = prompt;
456
+ if (file && file.name) {
457
  userMessageText = prompt ? `[${file.name}] ${prompt}` : `[${file.name}]`;
458
  }
459
  addMessageToChat('user', userMessageText);
 
461
  formData.append('prompt', prompt);
462
  formData.append('web_search', useWebSearch);
463
  if (file) {
464
+ formData.append('file', file);
465
  }
466
+ // Add the advanced reasoning flag
467
+ formData.append('advanced_reasoning', useAdvanced);
468
+
469
  showLoading(true);
470
  promptInput.value = '';
471
  clearFileInput();
472
+
473
+ // Reset toggles for next message (Web Search stays, Advanced resets and starts cooldown if used)
474
+ // webSearchToggle.checked = false; // Decide if you want this to reset
475
+ advancedToggle.checked = false; // Always reset advanced toggle
476
+ if (useAdvanced) startAdvancedCooldownTimer(); // Start cooldown *now* as we are sending the request
477
+
478
  try {
479
  const response = await fetch(API_CHAT_ENDPOINT, {
480
  method: 'POST',
 
491
  }
492
  } catch (error) {
493
  displayError(error.message);
494
+ if (useAdvanced) { /* Maybe revert cooldown if API fails? */ } // Optional: more complex error handling
495
  } finally {
496
  showLoading(false);
497
  promptInput.focus();
 
535
  });
536
  </script>
537
  </body>
538
+ </html>