huggingface/huggingface.js
|
|
Hugging Face JS libraries
This is a collection of JS libraries to interact with the Hugging Face API, with TS types included.
- @huggingface/inference: Use all supported (serverless) Inference Providers or switch to Inference Endpoints (dedicated) to make calls to 100,000+ Machine Learning models
- @huggingface/hub: Interact with huggingface.co to create or delete repos and commit / download files
- @huggingface/mcp-client: A Model Context Protocol (MCP) client, and a tiny Agent library, built on top of InferenceClient.
- @huggingface/gguf: A GGUF parser that works on remotely hosted files.
- @huggingface/dduf: Similar package for DDUF (DDUF Diffusers Unified Format)
- @huggingface/tasks: The definition files and source-of-truth for the Hub’s main primitives like pipeline tasks, model libraries, etc.
- @huggingface/jinja: A minimalistic JS implementation of the Jinja templating engine, to be used for ML chat templates.
- @huggingface/space-header: Use the Space
mini_header
outside Hugging Face - @huggingface/ollama-utils: Various utilities for maintaining Ollama compatibility with models on the Hugging Face Hub.
We use modern features to avoid polyfills and dependencies, so the libraries will only work on modern browsers / Node.js >= 18 / Bun / Deno.
The libraries are still very young, please help us by opening issues!
Installation
From NPM
To install via NPM, you can download the libraries as needed:
|
|
Then import the libraries in your code:
|
|
From CDN or Static hosting
You can run our packages with vanilla JS, without any bundler, by using a CDN or static hosting. Using ES modules, i.e. <script type="module">
, you can import the libraries in your code:
|
|
Deno
|
|
Usage examples
Get your HF access token in your account settings.
@huggingface/inference examples
|
|
@huggingface/hub examples
|
|
@huggingface/mcp-client example
|
|
There are more features of course, check each library’s README!
Formatting & testing
|
|
Building
|
|
This will generate ESM and CJS javascript files in packages/*/dist
, eg packages/inference/dist/index.mjs
.