{"_id":"@akku-dev/wllama","name":"@akku-dev/wllama","dist-tags":{"latest":"3.5.1"},"versions":{"3.5.1":{"name":"@akku-dev/wllama","version":"3.5.1","description":"WebAssembly binding for llama.cpp - Enabling on-browser LLM inference","main":"index.js","type":"module","directories":{"example":"examples"},"scripts":{"serve":"node ./scripts/http_server.js","serve:mt":"MULTITHREAD=1 node ./scripts/http_server.js","clean":"rm -rf ./esm && rm -rf ./docs && rm -rf ./wasm","build:worker":"./scripts/build_worker.sh","build:glue":"node ./cpp/generate_glue_prototype.js","build:wasm":"./scripts/build_wasm.sh && npm run build:glue","build:test":"WLLAMA_TEST_BACKEND=1 npm run build:wasm","build:tsup":"tsup src/index.ts --format cjs,esm --clean","build:minified":"terser esm/index.js -o esm/index.min.js --compress --mangle --source-map","build:typedef":"tsc --emitDeclarationOnly --declaration -p tsconfig.build.json","build":"npm run clean && npm run build:worker && npm run build:tsup && npm run build:minified && npm run build:typedef && ./scripts/post_build.sh && npm run docs","docs":"typedoc --tsconfig tsconfig.build.json src/index.ts","upload":"npm run format && npm run build && node scripts/check_package_size.js && npm publish --access public && (cd compat && npm publish --access public)","format":"prettier --write .","test":"vitest","test:auto":"AUTO=1 vitest","test:firefox":"BROWSER=firefox vitest","test:safari":"BROWSER=safari vitest","test:wgpu":"WEBGPU=1 vitest"},"repository":{"type":"git","url":"git+https://github.com/ngxson/wllama.git"},"keywords":["wasm","webassembly","llama","llm","ai","rag","embeddings","generation"],"author":{"name":"Xuan Son NGUYEN","email":"contact@ngxson.com"},"license":"MIT","bugs":{"url":"https://github.com/ngxson/wllama/issues"},"homepage":"https://github.com/ngxson/wllama#readme","devDependencies":{"@playwright/test":"^1.60.0","@vitest/browser":"^2.1.6","express":"^4.18.3","mime-types":"^2.1.35","playwright":"^1.59.1","prettier":"^3.3.3","terser":"^5.39.0","tsup":"^8.4.0","typedoc":"^0.27.2","typescript":"^5.4.2","webdriverio":"^9.4.1"},"prettier":{"trailingComma":"es5","tabWidth":2,"semi":true,"singleQuote":true,"bracketSameLine":false},"_id":"@akku-dev/wllama@3.5.1","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-iXljK4ij31nA7c5jDHeTBG4uaq3XttBqDw2Z7l7aBKvMBk+tx0tquSdZAEc/W6wBib2V9Vpc5DRh92U5DBF7YA==","shasum":"eae25c82e79334bcc2f46774623cbd57f20d0121","tarball":"https://registry.npmjs.org/@akku-dev/wllama/-/wllama-3.5.1.tgz","fileCount":86,"unpackedSize":18298440,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHeHX4PyzXNkyxqDpkpPMerb4mk012zXvyevYWCBTwHxAiBx3BxfGAmn/cWMA2z7x28NvpBwbIfzkFf65zhDwzfocw=="}]},"_npmUser":{"name":"akku1139","email":"akkun11.open@gmail.com"},"maintainers":[{"name":"akku1139","email":"akkun11.open@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/wllama_3.5.1_1784595416857_0.6851200073345036"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-21T00:56:56.687Z","3.5.1":"2026-07-21T00:56:57.152Z","modified":"2026-07-21T00:56:58.235Z"},"maintainers":[{"name":"akku1139","email":"akkun11.open@gmail.com"}],"description":"WebAssembly binding for llama.cpp - Enabling on-browser LLM inference","homepage":"https://github.com/ngxson/wllama#readme","keywords":["wasm","webassembly","llama","llm","ai","rag","embeddings","generation"],"repository":{"type":"git","url":"git+https://github.com/ngxson/wllama.git"},"author":{"name":"Xuan Son NGUYEN","email":"contact@ngxson.com"},"bugs":{"url":"https://github.com/ngxson/wllama/issues"},"license":"MIT","readme":"# wllama - Wasm binding for llama.cpp\n\n![](./README_banner.png)\n\nWebAssembly binding for [llama.cpp](https://github.com/ggerganov/llama.cpp)\n\n👉 [Try the demo app](https://huggingface.co/spaces/ngxson/wllama)\n\n👉 See the [blog post](https://reeselevine.github.io/llamas-on-the-web/) introducing WebGPU support in llama.cpp and wllama\n\n📄 [Documentation](https://github.ngxson.com/wllama/docs/)\n\nFor changelog, please visit [releases page](https://github.com/ngxson/wllama/releases)\n\n> [!IMPORTANT]\n>\n> **🔥🔥 V3 is out, with WebGPU, multimodal and tool calling support. Read the [V3 release guide](./guides/intro-v3.md)**\n>\n> For compatibility issues, please refer to [@wllama/wllama-compat](./compat/README.md)\n\n![](./assets/screenshot_0.png)\n\n## Features\n\n- 🔌 OpenAI-compatible API (fully-typed built-in)\n- 🚀 WebGPU support\n- 🔥 Multimodal support (image and audio file input)\n- 🔥 Tool calling support\n- Can run inference directly on browser (using [WebAssembly SIMD](https://emscripten.org/docs/porting/simd.html)), no backend or GPU is needed!\n- No runtime dependency (see [package.json](./package.json))\n- Ability to split the model into smaller files and load them in parallel (same as `split` and `cat`)\n- Auto switch between single-thread and multi-thread build based on browser support\n- Inference is done inside a worker, does not block UI render\n- Pre-built npm package [@wllama/wllama](https://www.npmjs.com/package/@wllama/wllama)\n\nLimitations:\n- To enable multi-thread, you must add `Cross-Origin-Embedder-Policy` and `Cross-Origin-Opener-Policy` headers. See [this discussion](https://github.com/ffmpegwasm/ffmpeg.wasm/issues/106#issuecomment-913450724) for more details.\n- Max file size is 2GB, due to [size restriction of ArrayBuffer](https://stackoverflow.com/questions/17823225/do-arraybuffers-have-a-maximum-length). If your model is bigger than 2GB, please follow the **Split model** section below.\n\n## Code demo and documentation\n\nDemo:\n- Basic usages with completions and embeddings: https://github.ngxson.com/wllama/examples/basic/ ([source code](./examples/basic/index.html))\n- Embedding and cosine distance: https://github.ngxson.com/wllama/examples/embeddings/ ([source code](./examples/embeddings/index.html))\n- Multimodal (vision) completion: https://github.ngxson.com/wllama/examples/multimodal/ ([source code](./examples/multimodal/index.html))\n- Tool calling: https://github.ngxson.com/wllama/examples/tools/ ([source code](./examples/tools/index.html))\n\n## How to use\n\n### Use Wllama inside React Typescript project\n\nInstall it:\n\n```bash\nnpm i @wllama/wllama\n```\n\nThen, import the module:\n\n```ts\nimport { Wllama } from '@wllama/wllama';\nlet wllamaInstance = new Wllama(WLLAMA_CONFIG_PATHS, ...);\n// (the rest is the same with earlier example)\n```\n\nFor complete code example, see [examples/main/src/utils/wllama.context.tsx](./examples/main/src/utils/wllama.context.tsx)\n\nNOTE: this example only covers completions usage. For embeddings, please see [examples/embeddings/index.html](./examples/embeddings/index.html)\n\n### WebGPU support\n\nWebGPU support is introduced via [PR #215](https://github.com/ngxson/wllama/pull/215).\n\nUpon updating to V3.1, WebGPU will be enabled automatically. By default, all layers will be offloaded to GPU. If the model is too big to fit into VRAM, you can manually adjust the number of layers via the `n_gpu_layers` parameter of `LoadModelParams`. Example:\n\n```js\n// (optionally) will allow running WebGPU on Firefox via compat mode; performance will be significantly degraded\nwllama.setCompat('default', 'firefox_safari');\n\nawait wllama.loadModel(files, {\n  n_gpu_layers: 4, // meaning 4 layers are offloaded to GPU; set to 0 to disable GPU inference\n});\n```\n\n### Prepare your model\n\n- It is recommended to split the model into **chunks of maximum 512MB**. This will result in slightly faster download speed (because multiple splits can be downloaded in parallel), and also prevent some out-of-memory issues. **See the \"Split model\" section below for more details.**\n- It is recommended to use quantized Q4, Q5 or Q6 for balance among performance, file size and quality. Using IQ (with imatrix) is **not** recommended, may result in slow inference and low quality.\n\n### Simple usage with ES6 module\n\nFor complete code, see [examples/basic/index.html](./examples/basic/index.html)\n\n```javascript\nimport { Wllama } from './esm/index.js';\n\n(async () => {\n  const CONFIG_PATHS = {\n    default: './esm/wasm/wllama.wasm',\n  };\n  // Automatically switch between single-thread and multi-thread version based on browser support\n  // If you want to enforce single-thread, add { \"n_threads\": 1 } to LoadModelConfig\n  const wllama = new Wllama(CONFIG_PATHS);\n  // Define a function for tracking the model download progress\n  const progressCallback =  ({ loaded, total }) => {\n    // Calculate the progress as a percentage\n    const progressPercentage = Math.round((loaded / total) * 100);\n    // Log the progress in a user-friendly format\n    console.log(`Downloading... ${progressPercentage}%`);\n  };\n  // Load GGUF from Hugging Face hub\n  // (alternatively, you can use loadModelFromUrl if the model is not from HF hub)\n  await wllama.loadModelFromHF(\n    { repo: 'ggml-org/models', file: 'tinyllamas/stories260K.gguf' },\n    { progressCallback }\n  );\n  const response = await wllama.createChatCompletion({\n    messages: [{ role: 'user', content: elemInput.value }],\n    max_tokens: 50,\n    temperature: 0.5,\n    top_k: 40,\n    top_p: 0.9,\n  });\n  console.log(response.choices[0].message.content);\n})();\n```\n\nAlternatively, you can use the `*.wasm` files from CDN:\n\n```js\nimport WasmFromCDN from '@wllama/wllama/esm/wasm-from-cdn.js';\nconst wllama = new Wllama(WasmFromCDN);\n// NOTE: this is not recommended, only use when you can't embed wasm files in your project\n```\n\n### Split model\n\nCases where we want to split the model:\n- Due to [size restriction of ArrayBuffer](https://stackoverflow.com/questions/17823225/do-arraybuffers-have-a-maximum-length), the size limitation of a file is 2GB. If your model is bigger than 2GB, you can split the model into small files.\n- Even with a small model, splitting into chunks allows the browser to download multiple chunks in parallel, thus making the download process a bit faster.\n\nWe use `llama-gguf-split` to split a big gguf file into smaller files. You can download the pre-built binary via [llama.cpp release page](https://github.com/ggerganov/llama.cpp/releases):\n\n```bash\n# Split the model into chunks of 512 Megabytes\n./llama-gguf-split --split-max-size 512M ./my_model.gguf ./my_model\n```\n\nThis will output files ending with `-00001-of-00003.gguf`, `-00002-of-00003.gguf`, and so on.\n\nYou can then pass to `loadModelFromUrl` or `loadModelFromHF` the URL of the first file and it will automatically load all the chunks:\n\n```js\nconst wllama = new Wllama(CONFIG_PATHS, {\n  parallelDownloads: 5, // optional: maximum files to download in parallel (default: 3)\n});\nawait wllama.loadModelFromHF({\n  repo: 'ngxson/tinyllama_split_test',\n  file: 'stories15M-q8_0-00001-of-00003.gguf',\n});\n```\n\n### Custom logger (suppress debug messages)\n\nWhen initializing Wllama, you can pass a custom logger to Wllama.\n\nExample 1: Suppress debug message\n\n```js\nimport { Wllama, LoggerWithoutDebug } from '@wllama/wllama';\n\nconst wllama = new Wllama(pathConfig, {\n  // LoggerWithoutDebug is predefined inside wllama\n  logger: LoggerWithoutDebug,\n});\n```\n\nExample 2: Add emoji prefix to log messages\n\n```js\nconst wllama = new Wllama(pathConfig, {\n  logger: {\n    debug: (...args) => console.debug('🔧', ...args),\n    log: (...args) => console.log('ℹ️', ...args),\n    warn: (...args) => console.warn('⚠️', ...args),\n    error: (...args) => console.error('☠️', ...args),\n  },\n});\n```\n\n## How to compile the binary yourself\n\nThis repository already come with pre-built binary from llama.cpp source code. However, in some cases you may want to compile it yourself:\n- You don't trust the pre-built one.\n- You want to try out latest - bleeding-edge changes from upstream llama.cpp source code.\n\nYou can use the commands below to compile it yourself:\n\n```shell\n# /!\\ IMPORTANT: Require having docker compose installed\n\n# Clone the repository with submodule\ngit clone --recurse-submodules https://github.com/ngxson/wllama.git\ncd wllama\n\n# Optionally, you can run this command to update llama.cpp to latest upstream version (bleeding-edge, use with your own risk!)\n# git submodule update --remote --merge\n\n# Install the required modules\nnpm i\n\n# Firstly, build llama.cpp into wasm\nnpm run build:wasm\n# Then, build ES module\nnpm run build\n```\n\n## TODO\n\n- Add support for LoRA adapter\n- Support multi-sequences: knowing the resource limitation when using WASM, I don't think having multi-sequences is a good idea\n\n## Acknowledgments\n\nWllama was created and is maintained by [Xuan-Son Nguyen](https://ngxson.com/). The WebGPU backend for llama.cpp is maintained by [Reese Levine](https://reeselevine.github.io/). We thank all other contributors to both wllama and llama.cpp, whose work made this project possible.","readmeFilename":"README.md","_rev":"1-15d65b25112c1d5967b3d7636441ac34"}