LocalWebAgent / js /config.js
ereniko's picture
v0.10.0: installable as a Progressive Web App
92ed407 unverified
Raw History Blame Contribute Delete
8.88 kB
// Central configuration. Everything that pins a version or a location lives here.
export const APP_VERSION = "0.10.0";
// --- Local language models (loaded from the Hugging Face Hub, cached in Cache Storage) ---
// Each runs on WebGPU through transformers.js. `chunks` is how many external weight files
// (<file>_<dtype>.onnx_data, _data_1, ...) the ONNX graph uses; 0 means the weights are inside
// the .onnx file itself. `bytes` is the approximate download, `contextMax` the model's window.
// Multimodal repos can be used text-only with:
// file: the ONNX graph's base name (default "model"),
// textConfig: load config.json's text_config as the model config,
// chatTemplateFile: the chat template lives in chat_template.jinja,
// emptyInputs: required graph inputs to feed as empty tensors ({name: [type, dims]}).
// `avatar` is the maker's Hugging Face avatar in vendor/avatars/.
// `q4` describes the build with 4-bit weights and fp32 math, used when the browser's WebGPU
// lacks f16 shaders (common with Chrome on Linux): its download size, and the same file
// layout with "q4" instead of "q4f16". null when there is no usable q4 build.
export const MODEL_DEVICE = "webgpu";
export const LOCAL_MODELS = [
{
id: "lfm3-1.7b", avatar: "liquidai", label: "LFM3 1.7B", repo: "LiquidAI/LFM3-1.7B-ONNX", dtype: "q4f16", chunks: 1,
q4: { bytes: 1_650_000_000 },
bytes: 1_400_000_000, contextMax: 262_144, thinking: true, by: "Liquid AI", license: "LFM Open License",
note: "The default. Fast hybrid model, good at tool use.",
},
{
id: "lfm3-omni-2b", avatar: "liquidai", label: "LFM3 Omni 2B", repo: "LiquidAI/LFM3-Omni-2B-ONNX", dtype: "q4f16", chunks: 1,
file: "decoder", textConfig: true, chatTemplateFile: true,
emptyInputs: {
image_features: ["float32", [0, 2048]], video_features: ["float32", [0, 2048]],
audio_features: ["float32", [0, 2048]], audio_out_codes: ["int64", [0, 12]],
},
q4: { bytes: 1_710_000_000 },
bytes: 1_432_000_000, contextMax: 128_000, thinking: true, by: "Liquid AI", license: "LFM Open License",
note: "The language part of Liquid AI's omni model: bigger than LFM3 1.7B, so stronger but slower. Text only here; its image and audio parts aren't downloaded.",
},
{
id: "qwen3.5-0.8b", avatar: "qwen", label: "Qwen3.5 0.8B", repo: "onnx-community/Qwen3.5-0.8B-Text-ONNX", dtype: "q4f16", chunks: 1,
q4: { bytes: 570_000_000 },
bytes: 489_000_000, contextMax: 262_144, thinking: true, by: "Qwen", license: "Apache-2.0",
note: "Smallest download and GPU memory use. Best chance on weak GPUs and phones; less capable.",
},
{
id: "qwen3.5-2b", avatar: "qwen", label: "Qwen3.5 2B", repo: "onnx-community/Qwen3.5-2B-ONNX", dtype: "q4f16",
graphs: [{ file: "embed_tokens", chunks: 1 }, { file: "decoder_model_merged", chunks: 1 }], fullPrefill: true,
q4: { bytes: 1_550_000_000 },
bytes: 1_396_000_000, contextMax: 262_144, thinking: true, by: "Qwen", license: "Apache-2.0",
note: "A good step up from the 0.8B at a similar size to LFM3. Text only here; its image part isn't downloaded.",
},
{
id: "qwen3-1.7b", avatar: "qwen", label: "Qwen3 1.7B", repo: "onnx-community/Qwen3-1.7B-ONNX", dtype: "q4f16", chunks: 0,
q4: null,
bytes: 1_426_000_000, contextMax: 40_960, thinking: true, by: "Qwen", license: "Apache-2.0",
note: "Previous Qwen generation, strong reasoning.",
},
{
id: "granite-4.0-1b", avatar: "ibm", label: "Granite 4.0 1B", repo: "onnx-community/granite-4.0-1b-ONNX-web", dtype: "q4f16", chunks: 1,
q4: { bytes: 1_790_000_000 },
bytes: 1_247_000_000, contextMax: 131_072, thinking: false, by: "IBM", license: "Apache-2.0",
note: "Hybrid model built for tool calling. No reasoning mode.",
},
{
id: "smollm3-3b", avatar: "huggingface", label: "SmolLM3 3B", repo: "HuggingFaceTB/SmolLM3-3B-ONNX", dtype: "q4f16", chunks: 1,
q4: { bytes: 2_860_000_000 },
bytes: 2_142_000_000, contextMax: 65_536, thinking: true, by: "Hugging Face", license: "Apache-2.0",
note: "Fully open model with a reasoning mode and tool calling.",
},
{
id: "llama-3.2-3b", avatar: "meta", label: "Llama 3.2 3B", repo: "onnx-community/Llama-3.2-3B-Instruct-ONNX", dtype: "q4f16", chunks: 2,
q4: { bytes: 3_430_000_000 },
bytes: 2_425_000_000, contextMax: 131_072, thinking: false, by: "Meta", license: "Llama 3.2 Community License",
note: "Meta's small instruct model. Calls tools with plain JSON; no reasoning mode.",
},
{
id: "qwen3.5-4b", avatar: "qwen", label: "Qwen3.5 4B", repo: "onnx-community/Qwen3.5-4B-ONNX", dtype: "q4f16",
graphs: [{ file: "embed_tokens", chunks: 1 }, { file: "decoder_model_merged", chunks: 2 }], fullPrefill: true,
q4: { bytes: 3_130_000_000 },
bytes: 2_820_000_000, contextMax: 262_144, thinking: true, by: "Qwen", license: "Apache-2.0",
note: "Most capable Qwen here, but slow. Needs a desktop GPU with about 4 GB of memory. Text only.",
},
{
id: "jan-nano", avatar: "menlo", label: "Jan-nano 4B", repo: "onnx-community/Jan-nano-ONNX", dtype: "q4f16", chunks: 2,
noGenerationConfig: true,
q4: null,
bytes: 2_850_000_000, contextMax: 40_960, thinking: false, by: "Menlo Research", license: "Apache-2.0",
note: "Qwen3 4B tuned by the Jan team for agentic tool use and search; answers without a reasoning phase. Needs a desktop GPU with about 4 GB of memory.",
},
];
export const DEFAULT_MODEL_ID = LOCAL_MODELS[0].id;
// Whether this browser's WebGPU has f16 shaders; set once at startup by main.js.
let f16 = true;
export const setShaderF16 = (supported) => { f16 = !!supported; };
export const shaderF16 = () => f16;
/** Can this model run here at all (some need f16 shaders)? */
export const modelRunsHere = (m) => f16 || !!m.q4;
/** The build of a model this browser uses: q4f16 normally, q4 without f16 shaders. */
export function effectiveModel(m) {
if (f16 || !m.q4 || m.dtype === "q4") return m;
return { ...m, dtype: "q4", bytes: m.q4.bytes, variant: "q4" };
}
export const findModel = (id) => LOCAL_MODELS.find((m) => m.id === id) ?? LOCAL_MODELS[0];
/**
* The ONNX graphs a model loads, each with its external-data chunk count. Most models are
* one graph ("model", or `file`); text-only use of a vision-language repo loads two
* (embed_tokens + decoder_model_merged), which transformers.js does on its own when a
* *ForCausalLM class is loaded from a *ForConditionalGeneration repo.
*/
export const graphsOf = (m) => m.graphs ?? [{ file: m.file ?? "model", chunks: m.chunks ?? 0 }];
const dataNames = (base, chunks) => Array.from({ length: chunks }, (_, i) => `${base}.onnx_data${i === 0 ? "" : "_" + i}`);
export const dataFileNames = (m) => graphsOf(m).flatMap((g) => dataNames(`${g.file}_${m.dtype}`, g.chunks));
// Files a model needs; used to check the offline cache and by the downloader.
export const modelFiles = (m) => [
"config.json", ...(m.noGenerationConfig ? [] : ["generation_config.json"]), "tokenizer.json", "tokenizer_config.json",
...(m.chatTemplateFile ? ["chat_template.jinja"] : []),
...graphsOf(m).flatMap((g) => [`onnx/${g.file}_${m.dtype}.onnx`, ...dataNames(`${g.file}_${m.dtype}`, g.chunks).map((f) => "onnx/" + f)]),
];
export const hubUrl = (m, file) => `https://huggingface.co/${m.repo}/resolve/main/${file}`;
// --- Sign in with Hugging Face ---
// Client ID of the Hugging Face OAuth app ("Connected app") used for "Sign in with Hugging
// Face". It is public (the flow uses PKCE, no secret). Leave empty to fall back to the ID
// Hugging Face injects into Spaces that set hf_oauth: true; with neither, only access
// tokens work.
export const HF_OAUTH_CLIENT_ID = "0dd5195d-0984-42b4-8aa0-d8c87d236bd5";
// --- CheerpX (WebVM engine). Proprietary: loaded from Leaning Technologies' CDN,
// never redistributed by this Space. The visitor's browser caches it for offline use.
export const CX_VERSION = "1.4.0";
export const CX_BASE = `https://cxrtnc.leaningtech.com/${CX_VERSION}/`;
export const CX_FILES = [
"cx.esm.js", "cx_esm.js", "cheerpOS.js", "cxbridge.js", "workerclock.js", "fail.wasm",
"cxcore.js", "cxcore.wasm", "cxcore-no-return-call.js", "cxcore-no-return-call.wasm",
];
// --- Linux disk image (chunked, see image/chunk.py). Defaults to ./disk/ in this Space.
export const DISK_BASE = new URL("./disk/", location.href).href;
// Virtual same-origin URL the service worker serves byte ranges for.
export const DISK_VIRTUAL_URL = new URL("./__vm__/disk.ext2", location.href).href;
// --- Cache names (must match sw.js) ---
export const CACHE_CX = "lwa-cheerpx-" + CX_VERSION;
export const CACHE_DISK = "lwa-disk";
export const CACHE_MODEL = "transformers-cache"; // transformers.js default
// --- Agent defaults (in their own module so Node tests can import them) ---
export { DEFAULTS } from "./config-defaults.js";