dexter2389 commited on
Commit
cd239ec
·
1 Parent(s): 64b34d9

Update frontend and logic to select the model

Browse files
Files changed (2) hide show
  1. app.py +5 -1
  2. frontend.html +67 -1
app.py CHANGED
@@ -62,7 +62,11 @@ def chat(payload: ChatRequest, request: Request):
62
 
63
  ai_response = (
64
  payload.model.value(
65
- [{"role": "user", "content": f"{payload.message}"}], do_sample=False
 
 
 
 
66
  )[0]
67
  .get("generated_text", [{}, {}])[1]
68
  .get("content", "")
 
62
 
63
  ai_response = (
64
  payload.model.value(
65
+ [{"role": "user", "content": f"{payload.message}"}],
66
+ do_sample=False,
67
+ temperature=0.8,
68
+ top_p=0.95,
69
+ max_new_tokens=1024,
70
  )[0]
71
  .get("generated_text", [{}, {}])[1]
72
  .get("content", "")
frontend.html CHANGED
@@ -45,6 +45,34 @@
45
  </div>
46
  </header>
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  <!-- Chat container -->
49
  <div id="chat-container" class="flex-1 overflow-y-auto py-4 px-4 md:px-0">
50
  <div class="max-w-screen-md mx-auto">
@@ -265,7 +293,42 @@
265
  const loadingIndicator = document.getElementById('loading');
266
  const suggestionButtons = document.querySelectorAll('.max-w-screen-md.mx-auto.px-4.md\\:px-0.mb-6 button');
267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
 
 
 
269
 
270
  // Function to add a message to the chat
271
  function formatMessage(text) {
@@ -413,7 +476,10 @@
413
  headers: {
414
  'Content-Type': 'application/json',
415
  },
416
- body: JSON.stringify({ message }),
 
 
 
417
  });
418
 
419
  if (!response.ok) {
 
45
  </div>
46
  </header>
47
 
48
+ <!-- Model selector -->
49
+ <div class="border-b border-gray-200 py-3 px-4">
50
+ <div class="max-w-screen-xl mx-auto flex items-center">
51
+ <div class="relative" id="model-selector-container">
52
+ <button id="model-dropdown-button"
53
+ class="flex items-center justify-between w-64 px-4 py-2 bg-white border border-gray-300 rounded-md shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500">
54
+ <span id="selected-model-text">Select a model</span>
55
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none"
56
+ stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
57
+ class="lucide lucide-chevron-down">
58
+ <path d="m6 9 6 6 6-6" />
59
+ </svg>
60
+ </button>
61
+ <div id="model-dropdown"
62
+ class="absolute z-10 w-full mt-1 bg-white border border-gray-300 rounded-md shadow-lg hidden">
63
+ <ul class="py-1">
64
+ <li class="model-option px-4 py-2 hover:bg-gray-100 cursor-pointer" data-value="TinyLlama">
65
+ TinyLlama</li>
66
+ <li class="model-option px-4 py-2 hover:bg-gray-100 cursor-pointer" data-value="SmolLLM2">
67
+ SmolLLM2</li>
68
+ <li class="model-option px-4 py-2 hover:bg-gray-100 cursor-pointer" data-value="SmolVLM">
69
+ SmolVLM</li>
70
+ </ul>
71
+ </div>
72
+ </div>
73
+ </div>
74
+ </div>
75
+
76
  <!-- Chat container -->
77
  <div id="chat-container" class="flex-1 overflow-y-auto py-4 px-4 md:px-0">
78
  <div class="max-w-screen-md mx-auto">
 
293
  const loadingIndicator = document.getElementById('loading');
294
  const suggestionButtons = document.querySelectorAll('.max-w-screen-md.mx-auto.px-4.md\\:px-0.mb-6 button');
295
 
296
+ // Model selector elements
297
+ const modelDropdownButton = document.getElementById('model-dropdown-button');
298
+ const modelDropdown = document.getElementById('model-dropdown');
299
+ const modelOptions = document.querySelectorAll('.model-option');
300
+ const selectedModelText = document.getElementById('selected-model-text');
301
+
302
+ // Default model
303
+ let selectedModel = 'SmolLLM2';
304
+
305
+ // Toggle dropdown
306
+ modelDropdownButton.addEventListener('click', () => {
307
+ modelDropdown.classList.toggle('hidden');
308
+ });
309
+
310
+ // Close dropdown when clicking outside
311
+ document.addEventListener('click', (e) => {
312
+ if (!modelDropdownButton.contains(e.target) && !modelDropdown.contains(e.target)) {
313
+ modelDropdown.classList.add('hidden');
314
+ }
315
+ });
316
+
317
+ // Handle model selection
318
+ modelOptions.forEach(option => {
319
+ option.addEventListener('click', () => {
320
+ selectedModel = option.getAttribute('data-value');
321
+ selectedModelText.textContent = option.textContent;
322
+ modelDropdown.classList.add('hidden');
323
+
324
+ // Add visual indication of selected model
325
+ modelOptions.forEach(opt => opt.classList.remove('bg-blue-50', 'text-blue-700'));
326
+ option.classList.add('bg-blue-50', 'text-blue-700');
327
+ });
328
+ });
329
 
330
+ // Set default selected model
331
+ modelOptions[0].click();
332
 
333
  // Function to add a message to the chat
334
  function formatMessage(text) {
 
476
  headers: {
477
  'Content-Type': 'application/json',
478
  },
479
+ body: JSON.stringify({
480
+ message: message,
481
+ model: selectedModel
482
+ }),
483
  });
484
 
485
  if (!response.ok) {