Xenova HF staff commited on
Commit
8921c88
1 Parent(s): 8e5a592

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +44 -0
README.md CHANGED
@@ -4,4 +4,48 @@ library_name: transformers.js
4
 
5
  https://huggingface.co/meta-llama/Llama-3.2-1B-Instruct with ONNX weights to be compatible with Transformers.js.
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
 
4
 
5
  https://huggingface.co/meta-llama/Llama-3.2-1B-Instruct with ONNX weights to be compatible with Transformers.js.
6
 
7
+ ## Usage (Transformers.js)
8
+
9
+ If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
10
+ ```bash
11
+ npm i @huggingface/transformers
12
+ ```
13
+
14
+ **Example:** Text generation with `onnx-community/Llama-3.2-1B-Instruct`.
15
+
16
+ ```js
17
+ import { pipeline } from "@huggingface/transformers";
18
+
19
+ // Create a text generation pipeline
20
+ const generator = await pipeline("text-generation", "onnx-community/Llama-3.2-1B-Instruct");
21
+
22
+ // Define the list of messages
23
+ const messages = [
24
+ { role: "system", content: "You are a helpful assistant." },
25
+ { role: "user", content: "Tell me a joke." },
26
+ ];
27
+
28
+ // Generate a response
29
+ const output = await generator(messages, { max_new_tokens: 128 });
30
+ console.log(output[0].generated_text.at(-1).content);
31
+ ```
32
+
33
+ <details>
34
+
35
+ <summary>Example output</summary>
36
+
37
+ ```
38
+ Here's a joke for you:
39
+
40
+ What do you call a fake noodle?
41
+
42
+ An impasta!
43
+
44
+ I hope that made you laugh! Do you want to hear another one?
45
+ ```
46
+ </details>
47
+
48
+
49
+ ---
50
+
51
  Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).