open-index/open-npm huggingface dataset:
npm package: @huggingface/jinja
Description: A minimalistic JavaScript implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.
Author: Hugging Face
Latest version: 0.5.6

# 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,
});
// "

 Hello, how are you? 
I'm doing great. How can I help you today?
 
 I'd like to show off how chat templating works! 
"
```

### 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 });
// "

 Hello, how are you? 
I'm doing great. How can I help you today?
 
 I'd like to show off how chat templating works! 
"
```

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).
npm package: @huggingface/languages
Description: List of ISO-639 languages used in the Hub
Author: Hugging Face
Latest version: 1.0.0

# 🤗 Hugging Face Languages.js

The list of all languages supported by the huggingface hub.

## Install

```console
pnpm add @huggingface/languages

npm add @huggingface/languages

yarn add @huggingface/languages
```

### Deno

```ts
// esm.sh
import { language, wikiLink, type Language } from "https://esm.sh/@huggingface/languages"
// or npm:
import { language, wikiLink, type Language } from "npm:@huggingface/languages"
```

Check out the [full documentation](https://huggingface.co/docs/huggingface.js/languages/README).
npm package: @huggingface/mcp-client
Description: Client for the Model Context Protocol
Author: Hugging Face
Latest version: 0.2.3

# @huggingface/mcp-client

Client for the Model Context Protocol (MCP).

This package provides a client implementation for interacting with MCP servers, built on top of our InferenceClient, `@huggingface/inference`.

It includes an example CLI smol Agent that can leverage MCP tools.

## Installation

This package is part of the Hugging Face JS monorepo. To install dependencies for all packages, run from the root of the repository:

```bash
pnpm install
```

## Usage (CLI Agent)

The package includes a command-line interface (CLI) agent that demonstrates how to use the MCP client.

### Prerequisites

*   **Hugging Face API Token:** You need a Hugging Face API token with appropriate permissions. Set it as an environment variable:
    ```bash
    export HF_TOKEN="hf_..."
    ```

### Running the Agent

Navigate to the package directory and run the agent script:

```bash
cd packages/mcp-client
pnpm agent
```

Alternatively, run from the root of the monorepo:

```bash
pnpm --filter @huggingface/mcp-client agent
```

The agent will load available MCP tools (by default, connecting to a filesystem server for your Desktop and a Playwright server) and prompt you for input (`>`).

### Configuration (Environment Variables)

*   `HF_TOKEN` (Optional): Your Hugging Face API token. Required if you use an Inference Provider on HF.
*   `MODEL_ID` (Optional): The model ID to use for the agent's inference. Defaults to `Qwen/Qwen2.5-72B-Instruct`.
*   `PROVIDER` (Optional): The inference provider. Defaults to `together`. See `@huggingface/inference` for available providers.
*   `ENDPOINT_URL` or `BASE_URL` (Optional): A custom base URL (local for instance) to call.

Example with custom model:

```bash
export HF_TOKEN="hf_..."
export MODEL_ID="Qwen/Qwen2.5-72B-Instruct"
pnpm agent
```

## Development

Common development tasks can be run using pnpm scripts:

*   `pnpm build`: Build the package.
*   `pnpm lint`: Lint and fix code style.
*   `pnpm format`: Format code using Prettier.
*   `pnpm test`: Run tests using Vitest.
*   `pnpm check`: Type-check the code using TypeScript.

## License

MIT
npm package: @huggingface/ollama-utils
Description: Various utilities for maintaining Ollama compatibility with models on Hugging Face hub
Author: Hugging Face
Latest version: 0.0.17

# `@huggingface/ollama-utils`

Various utilities for maintaining [Ollama compatibility with GGUF models on the Hugging Face Hub](https://huggingface.co/docs/hub/en/ollama).

For now, we are exposing chat template conversion to the Go format used by Ollama.

## Chat template converter

```ts
import { convertJinjaToGoTemplate } from "@huggingface/ollama-utils";

const MODEL_INFO_URL = "https://huggingface.co/api/models/bartowski/Llama-3.2-3B-Instruct-GGUF?expand[]=gguf";
const modelInfo = await (await fetch(MODEL_INFO_URL)).json();
console.log(modelInfo);
/**
 * {
 *   gguf: {
 *     chat_template: "here is the Jinja chat template",
 *     bos_token: "...",
 *     eos_token: "...",
 *     [...]
 *   }
 * }
 */
const convertedTemplate = convertJinjaToGoTemplate(modelInfo.gguf);
if (convertedTemplate) {
  console.log(convertedTemplate.ollama);
  /**
   * {
   *   template: "this is the converted template, compatible with Ollama",
   *   tokens: [... list of special tokens],
   *   params: {
   *     stop: [... list of stop tokens or stop words]
   *   }
   * }
   */
} else {
  console.error("Conversion is not successful");
}
```

## How can I add a custom template?

Most templates will be converted automatically. You can debug the output template using:
- This space to retrieve the converted template: https://huggingface.co/spaces/ngxson/debug_ollama_manifest
- And this space to apply the Go template into a list of messages: https://huggingface.co/spaces/ngxson/ollama_template_test

Please only add a new template when the conversion process above is not successful. Cases that are acceptable include:
- The converted template is wrong
- The Jinja template is not compatible with `@huggingface/jinja`
- The Jinja template is not "linear," meaning it can modify the content of other messages or append dynamic postfixes. For instance, the DeepSeek template removes `<think>...</think>` from previous messages in a conversation, making it non-linear. Another example is a template that adds the EOS token `
` when `add_generation_prompt=False`.

To add a new custom handler:
1. Edit the list of `CUSTOM_TEMPLATE_MAPPING` inside `chat-template.ts`
2. Add a new test case in `chat-template.spec.ts`
3. Push your change to a new PR.
npm package: @huggingface/space-header
Description: Use the Space mini_header outside Hugging Face
Author: Hugging Face
Latest version: 1.0.4

# 🤗 Hugging Face Space Header

A Typescript powered wrapper for the Space `mini_header` feature.

![space header preview](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/space-header-package/thumbnail.png)

## Install

```console
pnpm add @huggingface/space-header

npm add @huggingface/space-header

yarn add @huggingface/space-header
```

### Deno

```ts
// esm.sh
import { init } from "https://esm.sh/@huggingface/space-header"
// or npm:
import { init } from "npm:@huggingface/space-header"
```

### Initialize
```ts
import { init } from "@huggingface/space-header";

// ...

init(":user/:spaceId");
// init("enzostvs/lora-studio") for example
```
❗Important note: The `init` method must be called on the client side.

## Usage

Uses the `target` option to inject the space-header into another DOM element

```ts
const app = document.getElementById("app");

// ...

init(":user/:spaceId", {
  target: app
});
```

If you already have the space data, you can also pass it as a parameter to avoid a fetch

```ts
init(space);

// space = {
//  id: string;
//  likes: number;
//  author: string;
// }
```