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

A bit better feedback to the trials?

Browse files
Files changed (1) hide show
  1. index.html +84 -10
index.html CHANGED
@@ -889,16 +889,78 @@ If you can answer the question directly with your existing knowledge or after us
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);
@@ -908,9 +970,22 @@ If you can answer the question directly with your existing knowledge or after us
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} ...`);
@@ -935,8 +1010,7 @@ If you can answer the question directly with your existing knowledge or after us
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`;
@@ -945,7 +1019,7 @@ If you can answer the question directly with your existing knowledge or after us
945
  }
946
  }
947
  appendMessage({ role:'system', content: md });
948
- appendDiagnostic('Trial: Markdown summary appended to chat.');
949
  });
950
 
951
  // Event Listeners
 
889
  forceReloadBtn.addEventListener('click', () => window.location.reload());
890
  toggleDiagBtn.addEventListener('click', () => diagnosticsEl.classList.toggle('show'));
891
 
892
+ // --- Dynamic Trial Models Discovery (tokenless) ---
893
+ async function discoverOpenSmallModels(maxModels = 10) {
894
+ const collected = new Set();
895
+ const results = [];
896
+ const SEARCH_ENDPOINTS = [
897
+ // Popular small-ish text gen models by downloads
898
+ `${env.remoteURL}/api/models?pipeline_tag=text-generation&sort=downloads&direction=-1&limit=50`,
899
+ // Fallback: general search for tiny / distil / mini / small
900
+ `${env.remoteURL}/api/models?search=distil&limit=25`,
901
+ `${env.remoteURL}/api/models?search=tinyllama&limit=25`,
902
+ `${env.remoteURL}/api/models?search=phi-2&limit=25`,
903
+ `${env.remoteURL}/api/models?search=qwen2.5-0.5b&limit=25`,
904
+ `${env.remoteURL}/api/models?search=smol&limit=25`
905
+ ];
906
+ const nameAllowPatterns = [
907
+ /distilgpt/i,
908
+ /gpt2$/i,
909
+ /tinyllama/i,
910
+ /phi[-_]?1|phi[-_]?2/i,
911
+ /qwen2?\.5?[-_]?0\.5b/i,
912
+ /smol/i,
913
+ /mini[-_]?llama/i
914
+ ];
915
+ function nameLooksSmall(id) {
916
+ return nameAllowPatterns.some(rx => rx.test(id));
917
+ }
918
+ function quickHeuristicIsSmall(modelInfo) {
919
+ // Basic gates first.
920
+ if (modelInfo.private || modelInfo.gated || modelInfo.disabled) return false;
921
+ const id = modelInfo.id || '';
922
+ if (nameLooksSmall(id)) return true;
923
+ // Try tags heuristics.
924
+ const tags = modelInfo.tags || [];
925
+ if (tags.some(t => /tiny|micro|mini|small|distil/.test(t))) return true;
926
+ return false;
927
+ }
928
+ async function fetchJSON(url) {
929
+ try {
930
+ const r = await fetch(url, { headers: { 'Accept': 'application/json' } });
931
+ if (!r.ok) throw new Error(r.status + ' ' + r.statusText);
932
+ return await r.json();
933
+ } catch (e) {
934
+ appendDiagnostic('Discovery fetch fail: ' + url + ' :: ' + e.message);
935
+ return null;
936
+ }
937
+ }
938
+ for (const url of SEARCH_ENDPOINTS) {
939
+ if (results.length >= maxModels) break;
940
+ const data = await fetchJSON(url);
941
+ if (!Array.isArray(data)) continue;
942
+ for (const m of data) {
943
+ if (results.length >= maxModels) break;
944
+ const id = m.modelId || m.id; // API inconsistent keys
945
+ if (!id || collected.has(id)) continue;
946
+ if (!quickHeuristicIsSmall({ ...m, id })) continue;
947
+ if (m.pipeline_tag && m.pipeline_tag !== 'text-generation') continue; // prefer text-generation
948
+ collected.add(id);
949
+ results.push(id);
950
+ }
951
+ }
952
+ // Ensure some baseline fallbacks at end if discovery too small
953
+ const FALLBACKS = ['Xenova/distilgpt2','Xenova/gpt2'];
954
+ for (const f of FALLBACKS) if (!results.includes(f)) results.push(f);
955
+ return results.slice(0, maxModels);
956
+ }
957
+
958
  trialModelsBtn.addEventListener('click', async () => {
959
  const trialResultsDiv = document.getElementById('trial-results');
960
  trialResultsDiv.style.display = 'block';
961
+ trialResultsDiv.innerHTML = '<b>Discovering open small models (no token)...</b>';
962
  const TRIAL_PROMPT = 'Do planes fly higher than bees?';
 
963
  trialModelsBtn.disabled = true;
 
 
964
  const progressList = document.createElement('ul');
965
  progressList.style.fontSize = '0.7rem';
966
  trialResultsDiv.appendChild(progressList);
 
970
  progressList.appendChild(li);
971
  trialResultsDiv.scrollTop = trialResultsDiv.scrollHeight;
972
  };
973
+ appendDiagnostic('Trial: starting discovery...');
974
+ let discovered = [];
975
+ try {
976
+ discovered = await discoverOpenSmallModels(10);
977
+ } catch(e) {
978
+ appendDiagnostic('Discovery error: ' + e.message);
979
+ }
980
+ if (!discovered.length) {
981
+ addProgress('No models discovered dynamically. Using static fallbacks.');
982
+ discovered = ['Xenova/distilgpt2','Xenova/gpt2'];
983
+ }
984
+ addProgress('Models to try: ' + discovered.join(', '));
985
+ appendDiagnostic('Trial: Models -> ' + discovered.join(', '));
986
+ const collected = [];
987
  try {
988
+ for (const modelId of discovered) {
 
989
  let loadTime='-', genTime='-', snippet='', error=null;
990
  let t0 = performance.now();
991
  addProgress(`Loading ${modelId} ...`);
 
1010
  } finally {
1011
  trialModelsBtn.disabled = false;
1012
  }
1013
+ let md = '### Trial Results (Dynamic, No Token)\n';
 
1014
  for (const r of collected) {
1015
  if (r.error) {
1016
  md += `- **${r.model}**: ERROR: ${r.error}\n`;
 
1019
  }
1020
  }
1021
  appendMessage({ role:'system', content: md });
1022
+ appendDiagnostic('Trial: dynamic markdown summary appended to chat.');
1023
  });
1024
 
1025
  // Event Listeners