Transformers js

From metaspartan/cybara · View interactive version

Transformers js is an AI agent skill from the GitHub repository metaspartan/cybara. Build and validate local browser or Bun inference with Hugging Face Transformers.js, WebGPU or WASM backends, quantization, caching, and cleanup.

How to use this skill

Skill file

Transformers.js

Use @huggingface/transformers for JavaScript or TypeScript inference in Bun, Node-compatible runtimes, and browsers.

Setup

bun add @huggingface/transformers
import { pipeline } from "@huggingface/transformers";

const classifier = await pipeline("text-classification");
try {
  const result = await classifier("Cybara runs this model locally.");
  console.log(result);
} finally {
  await classifier.dispose();
}

Workflow

  1. Choose a model whose card lists Transformers.js or ONNX compatibility for the required task.
  2. Pin the model ID and revision when reproducibility matters.
  3. Start with CPU/WASM compatibility, then enable WebGPU only after feature detection.
  4. Select dtype or quantization from measured memory, latency, and quality requirements.
  5. Configure the cache explicitly for desktop or server runtimes.
  6. Warm the model before benchmarking and separate download time from inference latency.
  7. Dispose pipelines and tensors when the workflow ends.
  8. Test unavailable WebGPU, interrupted downloads, offline cache reuse, and malformed inputs.

Do not load untrusted custom model code. For browser applications, keep model downloads visible to the user and avoid blocking the main thread during initialization or long inference.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.