Ajey95 commited on
Commit
7e52c8f
Β·
1 Parent(s): c501c05

Fix: tools addition

Browse files
Files changed (1) hide show
  1. templates/index.html +79 -3
templates/index.html CHANGED
@@ -389,8 +389,84 @@
389
  </div>
390
 
391
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392
  // Global variables
393
- let isProcessing = false;
394
 
395
  // In templates/index.html, inside the <script> tag
396
 
@@ -583,8 +659,8 @@
583
 
584
  // Get new quote every 5 minutes
585
  setInterval(getNewQuote, 5 * 60 * 1000);
586
- });
587
- </script>
588
  </body>
589
  </html>
590
 
 
389
  </div>
390
 
391
  <script>
392
+
393
+ let isProcessing = false;
394
+
395
+ async function sendMessage() {
396
+ const input = document.getElementById('messageInput');
397
+ const message = input.value.trim();
398
+ if (!message || isProcessing) return;
399
+
400
+ addMessage(message, 'user');
401
+ input.value = '';
402
+ showLoading(true);
403
+
404
+ try {
405
+ const response = await fetch('/chat', {
406
+ method: 'POST',
407
+ headers: { 'Content-Type': 'application/json' },
408
+ body: JSON.stringify({ query: message })
409
+ });
410
+ const data = await response.json();
411
+ showLoading(false);
412
+ if (data.success) {
413
+ addMessage(data.message, 'bot', data.agent_used);
414
+ } else {
415
+ addMessage(`❌ Error: ${data.error || 'Something went wrong'}`, 'bot', 'error');
416
+ }
417
+ } catch (error) {
418
+ showLoading(false);
419
+ addMessage(`❌ Connection error: ${error.message}`, 'bot', 'error');
420
+ }
421
+ }
422
+
423
+ function addMessage(text, sender, agentType = '') {
424
+ const messagesContainer = document.getElementById('chatMessages');
425
+ const messageDiv = document.createElement('div');
426
+ messageDiv.className = `message ${sender}`;
427
+ const agentIcons = { 'academic': 'πŸ“š Academic Agent', 'drug_info': 'πŸ’Š Drug Info Agent', 'quiz_generation': '❓ Quiz Master' };
428
+ const agentBadge = sender === 'bot' ? `<div class="agent-badge">${agentIcons[agentType] || 'πŸ€– AI Assistant'}</div>` : '';
429
+ const formattedText = marked.parse(text || 'Sorry, I received an empty response.');
430
+ messageDiv.innerHTML = `<div class="message-bubble">${agentBadge}${formattedText}</div>`;
431
+ messagesContainer.appendChild(messageDiv);
432
+ messagesContainer.scrollTop = messagesContainer.scrollHeight;
433
+ }
434
+
435
+ function showLoading(show) {
436
+ document.getElementById('sendBtn').disabled = show;
437
+ const existingLoading = document.getElementById('loading-indicator');
438
+ if (existingLoading) existingLoading.remove();
439
+
440
+ if (show) {
441
+ const messagesContainer = document.getElementById('chatMessages');
442
+ const loadingDiv = document.createElement('div');
443
+ loadingDiv.className = 'message bot';
444
+ loadingDiv.id = 'loading-indicator';
445
+ loadingDiv.innerHTML = `<div class="message-bubble"><div class="typing-indicator"><span></span><span></span><span></span></div></div>`;
446
+ messagesContainer.appendChild(loadingDiv);
447
+ messagesContainer.scrollTop = messagesContainer.scrollHeight;
448
+ }
449
+ }
450
+
451
+ function handleKeyPress(event) {
452
+ if (event.key === 'Enter' && !event.shiftKey) {
453
+ event.preventDefault();
454
+ sendMessage();
455
+ }
456
+ }
457
+
458
+ function populateInput(templateText) {
459
+ const input = document.getElementById('messageInput');
460
+ input.value = templateText;
461
+ input.focus();
462
+ }
463
+
464
+ document.addEventListener('DOMContentLoaded', () => {
465
+ document.getElementById('messageInput').focus();
466
+ });
467
+ </script>
468
  // Global variables
469
+ {% comment %} let isProcessing = false;
470
 
471
  // In templates/index.html, inside the <script> tag
472
 
 
659
 
660
  // Get new quote every 5 minutes
661
  setInterval(getNewQuote, 5 * 60 * 1000);
662
+ }); {% endcomment %}
663
+
664
  </body>
665
  </html>
666