npm.io
0.1.0 • Published 1 month ago

@fanalis/models

Licence
MIT
Version
0.1.0
Deps
1
Size
30 kB
Vulns
0
Weekly
0

@fanalis/models

ml model loader + registry + hardware tier detection.

what's here

  • loader.tscreateLoader({noDownloads, log})ModelLoader. handles download (with AbortSignal.timeout + 2× declared size cap), sha256 verify, on-disk cache, concurrent-call dedup via inflight promise map.
  • registry.tsMODEL_REGISTRY: Record<ModelEntry> — pin source repo + revision + size + license + optional sha256. v1 only registers entries that actually resolve on huggingface; vapor models are commented out at the bottom.
  • tier-detect.tsdetectHardware()HardwareProfile (cpu cores, mem GB, gpu kind, apple silicon family). picks suggested + ceiling tier.
  • cache.ts — XDG-aware cache paths ($XDG_CACHE_HOME/fanalis/{models,work,reports} or ~/Library/Caches/fanalis/* / ~/.cache/fanalis/* per platform).
  • reports.ts — atomic report persistence: <id>.json + <id>.meta.json + latest.json + index.json. prefix-id resolution. prune to FANALIS_MAX_REPORTS (default 200).

what's actually registered

3 entries in v1:

  • clip-vit-b32Xenova/clip-vit-base-patch32 (real, downloadable). image+text encoders for value-prop coherence checks. used by visual + conversion pillars at T≥4.
  • qwen-1_5b-ollamaqwen2.5:1.5b via local ollama. narrative orchestrator at T≥3.
  • qwen-7b-ollamaqwen2.5:7b via local ollama. narrative at T≥4.

models intentionally NOT registered (commented as post-v1 targets): laion-aesthetics, nima, uiclip, deepgaze, yolov8-ui, distilbert-cialdini, distilbert-cognitive, distilbert-secret-ner, amalfi-xgboost, llava-critic. each lists the missing primitive (no public ONNX export, training pipeline pending, etc.) so it doesn't drift to "claimed but not implemented".

checksum behaviour

if a registry entry has a pinned sha256, the loader verifies it. if not, the loader downloads + reports the computed sha so the maintainer can pin retroactively (Model X downloaded UNVERIFIED. To pin, add to registry: sha256: "..."). cache hits without a pin also log the unverified-load warning.

the 2× size cap catches grossly-oversized payloads, but a malicious mirror serving exactly the right size still passes without a pinned hash. registry pinning is the load-bearing primitive.

onnx runtime

loadONNX(modelId) lazy-imports onnxruntime-node and prefers coreml on apple silicon, cuda when CUDA_VISIBLE_DEVICES is set, cpu otherwise. session is cached per-modelId across the run. release() closes + drops the cache entry.

caveats

  • noDownloads: true makes any missing model throw MissingModelError instead of fetching. CLI surfaces this when the user passes --no-downloads.
  • loadTokenizer(modelId) requires the entry to be source.type: "hf". raises if you try it on an ollama entry.
  • ollama entries don't get downloaded by loader.ts — they live in the ollama daemon's cache. ensure() returns the model name (e.g. qwen2.5:1.5b) as the "path".