# @huggingface/jinja

> A minimalistic JavaScript implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.

Latest version **0.5.10** (published 2026-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @huggingface/jinja
pnpm add @huggingface/jinja
yarn add @huggingface/jinja
bun add @huggingface/jinja
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.5.10 |
| Published | 2026-09-04 |
| First published | 2023-12-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 390.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2515 |
| Author | Hugging Face |
| Maintainers | julien-c, pierric, coyotte508, xenova, gary149 |
| Keywords | face, hugging, huggingface, jinja, templates |

## Links

- npm: https://www.npmjs.com/package/@huggingface/jinja
- Repository: https://github.com/huggingface/huggingface.js
- Homepage: https://github.com/huggingface/huggingface.js#readme
- Issues: https://github.com/huggingface/huggingface.js/issues
- npm.io page: https://npm.io/package/@huggingface/jinja

## Recent versions

- 0.5.10 (latest) — 2026-09-04
- 0.5.9 — 2026-05-08
- 0.5.8 — 2026-04-24
- 0.5.7 — 2026-04-16
- 0.5.6 — 2026-03-09
- 0.5.5 — 2026-02-02
- 0.5.4 — 2026-01-26
- 0.5.3 — 2025-11-27
- 0.5.2 — 2025-11-25
- 0.5.1 — 2025-07-10
- 0.5.0 — 2025-05-05
- 0.4.1 — 2025-05-01
- 0.4.0 — 2025-04-29
- 0.3.4 — 2025-04-10
- 0.3.3 — 2025-01-30
- … 15 more at https://npm.io/package/@huggingface/jinja/versions

## README

# Jinja

A minimalistic JavaScript implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.

## Usage

### Load template from a model on the Hugging Face Hub

First, install the jinja and hub packages:

```sh
npm i @huggingface/jinja
npm i @huggingface/hub
```

You can then load a tokenizer from the Hugging Face Hub and render a list of chat messages, as follows:

```js
import { Template } from "@huggingface/jinja";
import { downloadFile } from "@huggingface/hub";

const config = await (
	await downloadFile({
		repo: "mistralai/Mistral-7B-Instruct-v0.1",
		path: "tokenizer_config.json",
	})
).json();

const chat = [
	{ role: "user", content: "Hello, how are you?" },
	{ role: "assistant", content: "I'm doing great. How can I help you today?" },
	{ role: "user", content: "I'd like to show off how chat templating works!" },
];

const template = new Template(config.chat_template);
const result = template.render({
	messages: chat,
	bos_token: config.bos_token,
	eos_token: config.eos_token,
});
// "<s>[INST] Hello, how are you? [/INST]I'm doing great. How can I help you today?</s> [INST] I'd like to show off how chat templating works! [/INST]"
```

### Transformers.js

First, install `@huggingface/transformers`:

```sh
npm i @huggingface/transformers
```

You can then render a list of chat messages using a tokenizer's `apply_chat_template` method.

```js
import { AutoTokenizer } from "@huggingface/transformers";

// Load tokenizer from the Hugging Face Hub
const tokenizer = await AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1");

// Define chat messages
const chat = [
	{ role: "user", content: "Hello, how are you?" },
	{ role: "assistant", content: "I'm doing great. How can I help you today?" },
	{ role: "user", content: "I'd like to show off how chat templating works!" },
];

const text = tokenizer.apply_chat_template(chat, { tokenize: false });
// "<s>[INST] Hello, how are you? [/INST]I'm doing great. How can I help you today?</s> [INST] I'd like to show off how chat templating works! [/INST]"
```

Notice how the entire chat is condensed into a single string. If you would instead like to return the tokenized version (i.e., a list of token IDs), you can use the following:

```js
const input_ids = tokenizer.apply_chat_template(chat, { tokenize: true, return_tensor: false });
// [1, 733, 16289, 28793, 22557, 28725, 910, 460, 368, 28804, 733, 28748, 16289, 28793, 28737, 28742, 28719, 2548, 1598, 28723, 1602, 541, 315, 1316, 368, 3154, 28804, 2, 28705, 733, 16289, 28793, 315, 28742, 28715, 737, 298, 1347, 805, 910, 10706, 5752, 1077, 3791, 28808, 733, 28748, 16289, 28793]
```

For more information about chat templates, check out the transformers [documentation](https://huggingface.co/docs/transformers/main/en/chat_templating).

---
_Source: https://npm.io/package/@huggingface/jinja · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
