web-llm-runner 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1554,14 +1554,14 @@ const prebuiltAppConfig = {
1554
1554
  // Transformers.js (ONNX) confirmed models from llm_runner_poc
1555
1555
  {
1556
1556
  model: "https://huggingface.co/Xenova/LaMini-Flan-T5-248M",
1557
- model_id: "LaMini-Flan-T5-248M",
1557
+ model_id: "LaMini-Flan-T5 (~248MB) — Instruction Tuned",
1558
1558
  onnx_id: "Xenova/LaMini-Flan-T5-248M",
1559
1559
  model_lib: "",
1560
1560
  low_resource_required: true,
1561
1561
  },
1562
1562
  {
1563
1563
  model: "https://huggingface.co/Xenova/flan-t5-small",
1564
- model_id: "flan-t5-small",
1564
+ model_id: "Flan-T5 Small (~300MB) — Instruction Tuned",
1565
1565
  onnx_id: "Xenova/flan-t5-small",
1566
1566
  model_lib: "",
1567
1567
  low_resource_required: true,
@@ -36727,7 +36727,14 @@ class ONNXEngine {
36727
36727
  this.initProgressCallback({
36728
36728
  progress: 0,
36729
36729
  timeElapsed: 0,
36730
- text: `Initializing ONNX fallback for ${repoId}...`
36730
+ text: `Initializing ONNX engine for ${repoId}...`
36731
+ });
36732
+ }
36733
+ if (this.initProgressCallback) {
36734
+ this.initProgressCallback({
36735
+ progress: 0.05,
36736
+ timeElapsed: 0,
36737
+ text: `Loading model configuration and tokenizer...`
36731
36738
  });
36732
36739
  }
36733
36740
  try {
@@ -37992,18 +37999,34 @@ class WebLLM {
37992
37999
  detectDevice() {
37993
38000
  if (typeof navigator === "undefined")
37994
38001
  return;
37995
- const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
38002
+ // Check for explicit override in config (the user can "tell" the module)
38003
+ if (this.config.is_low_resource !== undefined) {
38004
+ this.isLowResourceDevice = !!this.config.is_low_resource;
38005
+ console.log(`[WebLLM] Using explicit is_low_resource: ${this.isLowResourceDevice}`);
38006
+ return;
38007
+ }
38008
+ const isMobileUA = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
38009
+ // Special check for iPad/modern tablets that report as desktop but have touch points
38010
+ const isTablet = navigator.maxTouchPoints > 1 && !window.MSStream;
38011
+ const isMobile = isMobileUA || isTablet;
37996
38012
  const hasWebGPU = !!navigator.gpu;
37997
38013
  // If it's mobile OR if WebGPU is missing, we consider it a low-resource/fallback device
37998
38014
  this.isLowResourceDevice = isMobile || !hasWebGPU;
37999
38015
  console.log(`[WebLLM] Device detection: isMobile=${isMobile}, hasWebGPU=${hasWebGPU} -> isLowResourceDevice=${this.isLowResourceDevice}`);
38000
38016
  }
38017
+ get is_low_resource() {
38018
+ return this.isLowResourceDevice;
38019
+ }
38001
38020
  // manage_model endpoints
38002
38021
  get models_available() {
38003
38022
  let list = prebuiltAppConfig.model_list;
38004
38023
  if (this.isLowResourceDevice) {
38005
- // Filter for low resource models (mostly ONNX/lightweight ones)
38006
- list = list.filter(m => m.low_resource_required === true);
38024
+ // Filter for specific approved mobile models
38025
+ const approvedIds = [
38026
+ "LaMini-Flan-T5 (~248MB) — Instruction Tuned",
38027
+ "Flan-T5 Small (~300MB) — Instruction Tuned"
38028
+ ];
38029
+ list = list.filter(m => approvedIds.includes(m.model_id));
38007
38030
  }
38008
38031
  return list.map((m) => m.model_id);
38009
38032
  }
@@ -38011,6 +38034,11 @@ class WebLLM {
38011
38034
  return await hasModelInCache(model_id);
38012
38035
  }
38013
38036
  async download_model(model_id, progressCallback) {
38037
+ // Initial feedback
38038
+ const initText = "Initializing model engine...";
38039
+ this.downloadProgress[model_id] = initText;
38040
+ if (progressCallback)
38041
+ progressCallback(initText);
38014
38042
  this.engine = await CreateMLCEngine(model_id, {
38015
38043
  ...this.config,
38016
38044
  initProgressCallback: (progress) => {