Skip to content

Commit 9106d50

Browse files
committed
Add llama-3.2-node demo
1 parent 25e32fa commit 9106d50

File tree

5 files changed

+1224
-0
lines changed

5 files changed

+1224
-0
lines changed

llama-3.2-node/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# llama-3.2-node
2+
3+
This project demonstrates how to use [Llama 3.2 1B](https://huggingface.co/onnx-community/Llama-3.2-1B-Instruct) in a Node.js environment.
4+
5+
## Instructions
6+
7+
1. Clone the repository:
8+
```sh
9+
git clone https://github.com/huggingface/transformers.js-examples.git
10+
```
11+
2. Change directory to the `llama-3.2-node` project:
12+
```sh
13+
cd cd transformers.js-examples/llama-3.2-node
14+
```
15+
3. Install the dependencies:
16+
```sh
17+
npm install
18+
```
19+
4. Run the example:
20+
```sh
21+
node index.js
22+
```

llama-3.2-node/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { pipeline } from "@huggingface/transformers";
2+
3+
// Create a text-generation pipeline
4+
const generator = await pipeline(
5+
"text-generation",
6+
"onnx-community/Llama-3.2-1B-Instruct"
7+
);
8+
9+
// Define the list of messages
10+
const messages = [
11+
{ role: "system", content: "You are a helpful assistant." },
12+
{ role: "user", content: "Tell me a funny joke." },
13+
];
14+
15+
// Generate a response
16+
const output = await generator(messages, { max_new_tokens: 128 });
17+
console.log(output[0].generated_text.at(-1).content);

0 commit comments

Comments
 (0)