mihailik commited on
Commit
2cf7bd1
·
1 Parent(s): c74649d

Adding model trials.

Browse files
Files changed (1) hide show
  1. index.html +65 -4
index.html CHANGED
@@ -20,9 +20,9 @@
20
  #chat-container {
21
  background-color: #fff;
22
  border-radius: 10px;
23
- box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);#
24
- width: 90%;
25
- max-width: 600px;
26
  display: flex;
27
  flex-direction: column;
28
  overflow: hidden;
@@ -79,11 +79,12 @@
79
  align-items: center;
80
  font-size: 0.85em;
81
  color: #666;
82
- text-align: center;
83
  padding: 5px 10px;
84
  border-radius: 10px;
85
  background-color: #f0f0f0;
86
  margin: 5px 0;
 
87
  }
88
 
89
  .message-bubble {
@@ -301,6 +302,7 @@ If you can answer the question directly with your existing knowledge or after us
301
  const toggleDiagBtn = document.getElementById('toggle-diagnostics');
302
  const backendSelect = document.getElementById('preferred-backend');
303
  const activeBackendLabel = document.getElementById('active-backend');
 
304
  const skipRagCheckbox = document.getElementById('skip-rag');
305
 
306
 
@@ -887,6 +889,65 @@ If you can answer the question directly with your existing knowledge or after us
887
  forceReloadBtn.addEventListener('click', () => window.location.reload());
888
  toggleDiagBtn.addEventListener('click', () => diagnosticsEl.classList.toggle('show'));
889
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
890
  // Event Listeners
891
  sendButton.addEventListener("click", onMessageSend);
892
  userInput.addEventListener("keypress", (event) => {
 
20
  #chat-container {
21
  background-color: #fff;
22
  border-radius: 10px;
23
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
24
+ width: 100vw;
25
+ max-width: none;
26
  display: flex;
27
  flex-direction: column;
28
  overflow: hidden;
 
79
  align-items: center;
80
  font-size: 0.85em;
81
  color: #666;
82
+ text-align: left;
83
  padding: 5px 10px;
84
  border-radius: 10px;
85
  background-color: #f0f0f0;
86
  margin: 5px 0;
87
+ white-space: pre-wrap; /* preserve markdown line breaks */
88
  }
89
 
90
  .message-bubble {
 
302
  const toggleDiagBtn = document.getElementById('toggle-diagnostics');
303
  const backendSelect = document.getElementById('preferred-backend');
304
  const activeBackendLabel = document.getElementById('active-backend');
305
+ const trialModelsBtn = document.getElementById('trial-models');
306
  const skipRagCheckbox = document.getElementById('skip-rag');
307
 
308
 
 
889
  forceReloadBtn.addEventListener('click', () => window.location.reload());
890
  toggleDiagBtn.addEventListener('click', () => diagnosticsEl.classList.toggle('show'));
891
 
892
+ // Trial Models: без токенів, мінімальний стабільний набір, Markdown список як системне повідомлення
893
+ trialModelsBtn.addEventListener('click', async () => {
894
+ const trialResultsDiv = document.getElementById('trial-results');
895
+ trialResultsDiv.style.display = 'block';
896
+ trialResultsDiv.innerHTML = '<b>Running trials (no tokens)...</b>';
897
+ const TRIAL_PROMPT = 'Do planes fly higher than bees?';
898
+ const MODELS_TO_TRY = [ 'Xenova/distilgpt2', 'Xenova/gpt2' ];
899
+ trialModelsBtn.disabled = true;
900
+ appendDiagnostic('Trial: Starting over ' + MODELS_TO_TRY.length + ' models (tokenless).');
901
+ const collected = [];
902
+ const progressList = document.createElement('ul');
903
+ progressList.style.fontSize = '0.7rem';
904
+ trialResultsDiv.appendChild(progressList);
905
+ const addProgress = (text) => {
906
+ const li = document.createElement('li');
907
+ li.textContent = text;
908
+ progressList.appendChild(li);
909
+ trialResultsDiv.scrollTop = trialResultsDiv.scrollHeight;
910
+ };
911
+ try {
912
+ for (let i=0;i<MODELS_TO_TRY.length;i++) {
913
+ const modelId = MODELS_TO_TRY[i];
914
+ let loadTime='-', genTime='-', snippet='', error=null;
915
+ let t0 = performance.now();
916
+ addProgress(`Loading ${modelId} ...`);
917
+ try {
918
+ const pipe = await pipeline('text-generation', modelId, { quantized: true });
919
+ const t1 = performance.now();
920
+ const out = await pipe(TRIAL_PROMPT, { max_new_tokens: 40, temperature: 0.7 });
921
+ const t2 = performance.now();
922
+ loadTime = ((t1-t0)/1000).toFixed(2)+'s';
923
+ genTime = ((t2-t1)/1000).toFixed(2)+'s';
924
+ const full = Array.isArray(out) ? (out[0]?.generated_text||'') : (out.generated_text||'');
925
+ snippet = full.trim().slice(0,400) || '(empty)';
926
+ addProgress(`${modelId} ✓ load ${loadTime} gen ${genTime}`);
927
+ } catch(e) {
928
+ error = e?.message || String(e);
929
+ addProgress(`${modelId} ✗ ${error}`);
930
+ appendDiagnostic('Trial error '+modelId+': '+error);
931
+ }
932
+ collected.push({ model:modelId, loadTime, genTime, snippet, error });
933
+ await new Promise(r=>setTimeout(r,0));
934
+ }
935
+ } finally {
936
+ trialModelsBtn.disabled = false;
937
+ }
938
+ // Формуємо Markdown
939
+ let md = '### Trial Results (No Token)\n';
940
+ for (const r of collected) {
941
+ if (r.error) {
942
+ md += `- **${r.model}**: ERROR: ${r.error}\n`;
943
+ } else {
944
+ md += `- **${r.model}** (Load ${r.loadTime} / Gen ${r.genTime})\n Response: ${r.snippet.replace(/\n+/g,' ')}\n`;
945
+ }
946
+ }
947
+ appendMessage({ role:'system', content: md });
948
+ appendDiagnostic('Trial: Markdown summary appended to chat.');
949
+ });
950
+
951
  // Event Listeners
952
  sendButton.addEventListener("click", onMessageSend);
953
  userInput.addEventListener("keypress", (event) => {