umer-wasim commited on
Commit
2dfda1c
·
verified ·
1 Parent(s): 1d41554

Chat uses fine-tuned model v0.5 (0.5B, about 300 MB, knows the visitor's device)

Browse files
Files changed (2) hide show
  1. app/model-version.json +3 -3
  2. chat/chat.js +14 -8
app/model-version.json CHANGED
@@ -2,8 +2,8 @@
2
  "version": "v0.3",
3
  "note": "Model version the desktop app and phone check use (Devseis/endpoint-auditor-0.5b-*-MLC tags). Read at start-up, so installed apps follow updates.",
4
  "chat": {
5
- "version": "v0.4",
6
- "size": "1.5B",
7
- "note": "Chat model: Devseis/endpoint-auditor-1.5b-*-MLC tag. null = base Qwen2.5-1.5B-Instruct until v0.4 is published."
8
  }
9
  }
 
2
  "version": "v0.3",
3
  "note": "Model version the desktop app and phone check use (Devseis/endpoint-auditor-0.5b-*-MLC tags). Read at start-up, so installed apps follow updates.",
4
  "chat": {
5
+ "version": "v0.5",
6
+ "size": "0.5B",
7
+ "note": "Chat model: Devseis/endpoint-auditor-<size>-*-MLC tag (size 0.5B or 1.5B). null = base Qwen2.5 Instruct."
8
  }
9
  }
chat/chat.js CHANGED
@@ -24,7 +24,7 @@ function newChat() {
24
 
25
  // ---------- model ----------
26
  // The model never blocks a question: until it is ready, answers come straight from the knowledge base.
27
- // It downloads in the background after the user agrees once (about 1 GB), and starts by itself when already stored.
28
  const AI_CONSENT = 'devseis.aiConsent';
29
  // Set when the AI wrote unreadable text on this device (a faulty graphics chip or driver); holds the model version, so a new one is tried again.
30
  const AI_FAULT = 'devseis.aiFault';
@@ -32,15 +32,20 @@ const FIRST_WORDS_LIMIT = 60000, ANSWER_LIMIT = 180000;
32
  let webllmPromise = null;
33
  const loadWebllm = () => (webllmPromise ||= import(WEBLLM_URL));
34
 
 
 
 
 
35
  async function modelChoice() {
36
  if (!('gpu' in navigator)) throw new Error('This browser has no WebGPU');
37
  const adapter = await navigator.gpu.requestAdapter();
38
  if (!adapter) throw new Error('No WebGPU graphics adapter');
39
  const quant = adapter.features.has('shader-f16') ? 'q4f16_1' : 'q4f32_1';
40
  const webllm = await loadWebllm();
41
- const base = webllm.prebuiltAppConfig.model_list.find(m => m.model_id === `Qwen2.5-1.5B-Instruct-${quant}-MLC`);
 
42
  const v = state.config?.chat?.version;
43
- const custom = v ? { ...base, model: `https://huggingface.co/Devseis/endpoint-auditor-1.5b-${quant}-MLC/resolve/${v}/`, model_id: `devseis-assistant-1.5b-${v}-${quant}` } : null;
44
  const appConfig = { ...webllm.prebuiltAppConfig, model_list: custom ? [...webllm.prebuiltAppConfig.model_list, custom] : webllm.prebuiltAppConfig.model_list };
45
  return { webllm, base, custom, appConfig, v };
46
  }
@@ -64,14 +69,14 @@ function getEngine() {
64
  // Shown inside the (locked) message box, which fills up as the model arrives.
65
  const pct = `${Math.round(state.progress * 100)}%`, narrow = matchMedia('(max-width: 560px)').matches;
66
  state.progressText = state.cachedStart ? `Starting the AI… ${pct}` : narrow ? `Downloading AI… ${pct}${mb ? ` · ${Math.round(+mb[1])} MB` : ''}`
67
- : `Downloading the AI assistant… ${pct}${mb ? ` · ${Math.round(+mb[1])} of about 1,000 MB` : ''}`;
68
  aiChip();
69
  };
70
  let engine, label;
71
  if (custom) {
72
- try { engine = await webllm.CreateMLCEngine(custom.model_id, { appConfig, initProgressCallback }); label = `Devseis assistant ${v} (1.5B)`; } catch (e) { console.warn('Devseis model failed, using base', e); }
73
  }
74
- if (!engine) { engine = await webllm.CreateMLCEngine(base.model_id, { appConfig, initProgressCallback }); label = 'Qwen2.5 1.5B (base, until the Devseis model loads)'; }
75
  state.modelLabel = label; $('modelName').textContent = label; status('');
76
  return engine;
77
  })().then(e => { state.engine = e; state.loading = false; aiChip(); render(); return e; },
@@ -92,7 +97,7 @@ function aiChip() {
92
  if (state.engine) { chip.textContent = '✨ AI ready'; chip.title = state.modelLabel; chip.dataset.state = 'ready'; }
93
  else if (state.loading) { chip.textContent = `⬇ AI ${Math.round((state.progress || 0) * 100)}%`; chip.title = 'The AI assistant is getting ready'; chip.dataset.state = 'loading'; }
94
  else if (state.engine === false || state.aiFault) { chip.textContent = '📚 Knowledge base'; chip.title = state.modelLabel; chip.dataset.state = 'off'; }
95
- else { chip.textContent = '⚡ Enable AI'; chip.title = 'Download the AI assistant (about 1 GB, one time)'; chip.dataset.state = 'off'; }
96
  updateSend();
97
  if (!$('devicePanel').classList.contains('hidden')) renderDevicePanel();
98
  }
@@ -166,7 +171,7 @@ function render() {
166
  ${!m.pending && sources && !m.noSources ? `<div class="sources"><span class="muted tiny">Sources:</span>${sources}</div>` : ''}
167
  ${m.note ? `<div class="note">${esc(m.note)}</div>` : ''}
168
  ${m.quick && !m.pending && !m.writing ? (state.engine ? `<div class="quick-actions"><button type="button" class="primary-btn" data-rewrite="${i}">✨ Rewrite with AI</button></div>`
169
- : (!state.loading && state.engine !== false ? `<div class="quick-actions"><button type="button" class="small-btn" data-enable="1">⚡ Enable the AI assistant (about 1 GB, one time)</button></div>` : '')) : ''}
170
  <div class="source-slot"></div></div></div>`);
171
  });
172
  renderSidebar();
@@ -521,6 +526,7 @@ async function init() {
521
  getJson('app/model-version.json', { cache: 'no-cache' }).catch(() => ({})),
522
  ]);
523
  state.kb = new Knowledge(kb); state.device = await describeComputer(device); state.config = config;
 
524
  try { state.deviceChoice = localStorage.getItem(DEVICE_CHOICE); } catch { /* ignore */ }
525
  // Coming back from the phone check with a fresh report.
526
  if (location.hash === '#audit') {
 
24
 
25
  // ---------- model ----------
26
  // The model never blocks a question: until it is ready, answers come straight from the knowledge base.
27
+ // It downloads in the background after the user agrees once (chatModel().download), and starts by itself when already stored.
28
  const AI_CONSENT = 'devseis.aiConsent';
29
  // Set when the AI wrote unreadable text on this device (a faulty graphics chip or driver); holds the model version, so a new one is tried again.
30
  const AI_FAULT = 'devseis.aiFault';
 
32
  let webllmPromise = null;
33
  const loadWebllm = () => (webllmPromise ||= import(WEBLLM_URL));
34
 
35
+ // Chat model size from app/model-version.json (chat.size): 0.5B for phones and weak graphics chips, 1.5B before v0.5.
36
+ const CHAT_MODELS = { '0.5B': { repo: '0.5b', download: 'about 300 MB', mb: 280 }, '1.5B': { repo: '1.5b', download: 'about 850 MB', mb: 840 } };
37
+ function chatModel() { const size = CHAT_MODELS[state.config?.chat?.size] ? state.config.chat.size : '1.5B'; return { size, ...CHAT_MODELS[size] }; }
38
+
39
  async function modelChoice() {
40
  if (!('gpu' in navigator)) throw new Error('This browser has no WebGPU');
41
  const adapter = await navigator.gpu.requestAdapter();
42
  if (!adapter) throw new Error('No WebGPU graphics adapter');
43
  const quant = adapter.features.has('shader-f16') ? 'q4f16_1' : 'q4f32_1';
44
  const webllm = await loadWebllm();
45
+ const { size, repo } = chatModel();
46
+ const base = webllm.prebuiltAppConfig.model_list.find(m => m.model_id === `Qwen2.5-${size}-Instruct-${quant}-MLC`);
47
  const v = state.config?.chat?.version;
48
+ const custom = v ? { ...base, model: `https://huggingface.co/Devseis/endpoint-auditor-${repo}-${quant}-MLC/resolve/${v}/`, model_id: `devseis-assistant-${repo}-${v}-${quant}` } : null;
49
  const appConfig = { ...webllm.prebuiltAppConfig, model_list: custom ? [...webllm.prebuiltAppConfig.model_list, custom] : webllm.prebuiltAppConfig.model_list };
50
  return { webllm, base, custom, appConfig, v };
51
  }
 
69
  // Shown inside the (locked) message box, which fills up as the model arrives.
70
  const pct = `${Math.round(state.progress * 100)}%`, narrow = matchMedia('(max-width: 560px)').matches;
71
  state.progressText = state.cachedStart ? `Starting the AI… ${pct}` : narrow ? `Downloading AI… ${pct}${mb ? ` · ${Math.round(+mb[1])} MB` : ''}`
72
+ : `Downloading the AI assistant… ${pct}${mb ? ` · ${Math.round(+mb[1])} of ${chatModel().download}` : ''}`;
73
  aiChip();
74
  };
75
  let engine, label;
76
  if (custom) {
77
+ try { engine = await webllm.CreateMLCEngine(custom.model_id, { appConfig, initProgressCallback }); label = `Devseis assistant ${v} (${chatModel().size})`; } catch (e) { console.warn('Devseis model failed, using base', e); }
78
  }
79
+ if (!engine) { engine = await webllm.CreateMLCEngine(base.model_id, { appConfig, initProgressCallback }); label = `Qwen2.5 ${chatModel().size} (base, until the Devseis model loads)`; }
80
  state.modelLabel = label; $('modelName').textContent = label; status('');
81
  return engine;
82
  })().then(e => { state.engine = e; state.loading = false; aiChip(); render(); return e; },
 
97
  if (state.engine) { chip.textContent = '✨ AI ready'; chip.title = state.modelLabel; chip.dataset.state = 'ready'; }
98
  else if (state.loading) { chip.textContent = `⬇ AI ${Math.round((state.progress || 0) * 100)}%`; chip.title = 'The AI assistant is getting ready'; chip.dataset.state = 'loading'; }
99
  else if (state.engine === false || state.aiFault) { chip.textContent = '📚 Knowledge base'; chip.title = state.modelLabel; chip.dataset.state = 'off'; }
100
+ else { chip.textContent = '⚡ Enable AI'; chip.title = `Download the AI assistant (${chatModel().download}, one time)`; chip.dataset.state = 'off'; }
101
  updateSend();
102
  if (!$('devicePanel').classList.contains('hidden')) renderDevicePanel();
103
  }
 
171
  ${!m.pending && sources && !m.noSources ? `<div class="sources"><span class="muted tiny">Sources:</span>${sources}</div>` : ''}
172
  ${m.note ? `<div class="note">${esc(m.note)}</div>` : ''}
173
  ${m.quick && !m.pending && !m.writing ? (state.engine ? `<div class="quick-actions"><button type="button" class="primary-btn" data-rewrite="${i}">✨ Rewrite with AI</button></div>`
174
+ : (!state.loading && state.engine !== false ? `<div class="quick-actions"><button type="button" class="small-btn" data-enable="1">⚡ Enable the AI assistant (${chatModel().download}, one time)</button></div>` : '')) : ''}
175
  <div class="source-slot"></div></div></div>`);
176
  });
177
  renderSidebar();
 
526
  getJson('app/model-version.json', { cache: 'no-cache' }).catch(() => ({})),
527
  ]);
528
  state.kb = new Knowledge(kb); state.device = await describeComputer(device); state.config = config;
529
+ $('aiCardText').textContent = $('aiCardText').textContent.replace('about 1 GB', chatModel().download);
530
  try { state.deviceChoice = localStorage.getItem(DEVICE_CHOICE); } catch { /* ignore */ }
531
  // Coming back from the phone check with a fresh report.
532
  if (location.hash === '#audit') {