More trials, better default chat.
Browse files- index.html +27 -14
index.html
CHANGED
|
@@ -318,11 +318,10 @@ If you can answer the question directly with your existing knowledge or after us
|
|
| 318 |
// Candidate models (ordered). We rotate until one loads. Prefer fully open, ungated models first.
|
| 319 |
let TRANSFORMERS_MODEL_CANDIDATES = [];
|
| 320 |
const DEFAULT_TRANSFORMERS_MODEL_CANDIDATES = [
|
| 321 |
-
//
|
| 322 |
-
'Xenova/
|
| 323 |
-
'Xenova/
|
| 324 |
-
|
| 325 |
-
'Xenova/Qwen2.5-0.5B-Instruct' // instruct style (may gate)
|
| 326 |
];
|
| 327 |
const SMALLER_MODEL_HINT = 'Xenova/distilgpt2';
|
| 328 |
const modelCandidatesInput = document.getElementById('model-candidates');
|
|
@@ -890,7 +889,7 @@ If you can answer the question directly with your existing knowledge or after us
|
|
| 890 |
toggleDiagBtn.addEventListener('click', () => diagnosticsEl.classList.toggle('show'));
|
| 891 |
|
| 892 |
// --- Dynamic Trial Models Discovery (tokenless) ---
|
| 893 |
-
async function discoverOpenSmallModels(maxModels =
|
| 894 |
const collected = new Set();
|
| 895 |
const results = [];
|
| 896 |
const SEARCH_ENDPOINTS = [
|
|
@@ -950,9 +949,11 @@ If you can answer the question directly with your existing knowledge or after us
|
|
| 950 |
}
|
| 951 |
}
|
| 952 |
// Ensure some baseline fallbacks at end if discovery too small
|
| 953 |
-
const FALLBACKS = ['Xenova/
|
| 954 |
for (const f of FALLBACKS) if (!results.includes(f)) results.push(f);
|
| 955 |
-
|
|
|
|
|
|
|
| 956 |
}
|
| 957 |
|
| 958 |
trialModelsBtn.addEventListener('click', async () => {
|
|
@@ -970,6 +971,13 @@ If you can answer the question directly with your existing knowledge or after us
|
|
| 970 |
progressList.appendChild(li);
|
| 971 |
trialResultsDiv.scrollTop = trialResultsDiv.scrollHeight;
|
| 972 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 973 |
appendDiagnostic('Trial: starting discovery...');
|
| 974 |
let discovered = [];
|
| 975 |
try {
|
|
@@ -979,20 +987,25 @@ If you can answer the question directly with your existing knowledge or after us
|
|
| 979 |
}
|
| 980 |
if (!discovered.length) {
|
| 981 |
addProgress('No models discovered dynamically. Using static fallbacks.');
|
| 982 |
-
discovered = ['Xenova/
|
| 983 |
}
|
| 984 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 985 |
appendDiagnostic('Trial: Models -> ' + discovered.join(', '));
|
| 986 |
const collected = [];
|
| 987 |
try {
|
| 988 |
-
for (const modelId of
|
| 989 |
let loadTime='-', genTime='-', snippet='', error=null;
|
| 990 |
let t0 = performance.now();
|
| 991 |
addProgress(`Loading ${modelId} ...`);
|
| 992 |
try {
|
| 993 |
-
const pipe = await pipeline('text-generation', modelId, { quantized: true });
|
| 994 |
const t1 = performance.now();
|
| 995 |
-
const out = await pipe(TRIAL_PROMPT, { max_new_tokens:
|
| 996 |
const t2 = performance.now();
|
| 997 |
loadTime = ((t1-t0)/1000).toFixed(2)+'s';
|
| 998 |
genTime = ((t2-t1)/1000).toFixed(2)+'s';
|
|
@@ -1005,7 +1018,7 @@ If you can answer the question directly with your existing knowledge or after us
|
|
| 1005 |
appendDiagnostic('Trial error '+modelId+': '+error);
|
| 1006 |
}
|
| 1007 |
collected.push({ model:modelId, loadTime, genTime, snippet, error });
|
| 1008 |
-
await
|
| 1009 |
}
|
| 1010 |
} finally {
|
| 1011 |
trialModelsBtn.disabled = false;
|
|
|
|
| 318 |
// Candidate models (ordered). We rotate until one loads. Prefer fully open, ungated models first.
|
| 319 |
let TRANSFORMERS_MODEL_CANDIDATES = [];
|
| 320 |
const DEFAULT_TRANSFORMERS_MODEL_CANDIDATES = [
|
| 321 |
+
// Force GPT2 first as requested, with a tiny fallback.
|
| 322 |
+
'Xenova/gpt2', // preferred primary model for chat
|
| 323 |
+
'Xenova/distilgpt2' // tiny fallback
|
| 324 |
+
// (Removed larger models to avoid long downloads / gated issues without token)
|
|
|
|
| 325 |
];
|
| 326 |
const SMALLER_MODEL_HINT = 'Xenova/distilgpt2';
|
| 327 |
const modelCandidatesInput = document.getElementById('model-candidates');
|
|
|
|
| 889 |
toggleDiagBtn.addEventListener('click', () => diagnosticsEl.classList.toggle('show'));
|
| 890 |
|
| 891 |
// --- Dynamic Trial Models Discovery (tokenless) ---
|
| 892 |
+
async function discoverOpenSmallModels(maxModels = 6) {
|
| 893 |
const collected = new Set();
|
| 894 |
const results = [];
|
| 895 |
const SEARCH_ENDPOINTS = [
|
|
|
|
| 949 |
}
|
| 950 |
}
|
| 951 |
// Ensure some baseline fallbacks at end if discovery too small
|
| 952 |
+
const FALLBACKS = ['Xenova/gpt2','Xenova/distilgpt2'];
|
| 953 |
for (const f of FALLBACKS) if (!results.includes(f)) results.push(f);
|
| 954 |
+
// Ensure fallbacks appear first (already pushed at end if missing; reorder)
|
| 955 |
+
const ordered = FALLBACKS.filter(f=>results.includes(f)).concat(results.filter(r=>!FALLBACKS.includes(r)));
|
| 956 |
+
return ordered.slice(0, maxModels);
|
| 957 |
}
|
| 958 |
|
| 959 |
trialModelsBtn.addEventListener('click', async () => {
|
|
|
|
| 971 |
progressList.appendChild(li);
|
| 972 |
trialResultsDiv.scrollTop = trialResultsDiv.scrollHeight;
|
| 973 |
};
|
| 974 |
+
const yieldUI = async () => new Promise(r=>requestAnimationFrame(r));
|
| 975 |
+
function withTimeout(promise, ms, label) {
|
| 976 |
+
return Promise.race([
|
| 977 |
+
promise,
|
| 978 |
+
new Promise((_, rej) => setTimeout(()=>rej(new Error(label + ' timeout after '+ms+'ms')), ms))
|
| 979 |
+
]);
|
| 980 |
+
}
|
| 981 |
appendDiagnostic('Trial: starting discovery...');
|
| 982 |
let discovered = [];
|
| 983 |
try {
|
|
|
|
| 987 |
}
|
| 988 |
if (!discovered.length) {
|
| 989 |
addProgress('No models discovered dynamically. Using static fallbacks.');
|
| 990 |
+
discovered = ['Xenova/gpt2','Xenova/distilgpt2'];
|
| 991 |
}
|
| 992 |
+
// Ensure baseline (gpt2 + distilgpt2) attempted first regardless of discovery order
|
| 993 |
+
const baseline = ['Xenova/gpt2','Xenova/distilgpt2'];
|
| 994 |
+
const ordered = baseline.concat(discovered.filter(m=>!baseline.includes(m)));
|
| 995 |
+
// Limit total trials for responsiveness
|
| 996 |
+
const MODELS = ordered.slice(0,6);
|
| 997 |
+
addProgress('Models to try: ' + MODELS.join(', '));
|
| 998 |
appendDiagnostic('Trial: Models -> ' + discovered.join(', '));
|
| 999 |
const collected = [];
|
| 1000 |
try {
|
| 1001 |
+
for (const modelId of MODELS) {
|
| 1002 |
let loadTime='-', genTime='-', snippet='', error=null;
|
| 1003 |
let t0 = performance.now();
|
| 1004 |
addProgress(`Loading ${modelId} ...`);
|
| 1005 |
try {
|
| 1006 |
+
const pipe = await withTimeout(pipeline('text-generation', modelId, { quantized: true }), 20000, 'load');
|
| 1007 |
const t1 = performance.now();
|
| 1008 |
+
const out = await withTimeout(pipe(TRIAL_PROMPT, { max_new_tokens: 30, temperature: 0.7 }), 12000, 'gen');
|
| 1009 |
const t2 = performance.now();
|
| 1010 |
loadTime = ((t1-t0)/1000).toFixed(2)+'s';
|
| 1011 |
genTime = ((t2-t1)/1000).toFixed(2)+'s';
|
|
|
|
| 1018 |
appendDiagnostic('Trial error '+modelId+': '+error);
|
| 1019 |
}
|
| 1020 |
collected.push({ model:modelId, loadTime, genTime, snippet, error });
|
| 1021 |
+
await yieldUI();
|
| 1022 |
}
|
| 1023 |
} finally {
|
| 1024 |
trialModelsBtn.disabled = false;
|