Update README.md
Browse files
README.md
CHANGED
|
@@ -3,4 +3,37 @@ license: mit
|
|
| 3 |
base_model:
|
| 4 |
- karpathy/nanochat-d32
|
| 5 |
library_name: transformers.js
|
| 6 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
base_model:
|
| 4 |
- karpathy/nanochat-d32
|
| 5 |
library_name: transformers.js
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
### Transformers.js
|
| 9 |
+
|
| 10 |
+
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:
|
| 11 |
+
```bash
|
| 12 |
+
npm i @huggingface/transformers
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
You can then use the model like this:
|
| 16 |
+
```js
|
| 17 |
+
import { pipeline, TextStreamer } from "@huggingface/transformers";
|
| 18 |
+
|
| 19 |
+
// Create a text generation pipeline
|
| 20 |
+
const generator = await pipeline(
|
| 21 |
+
"text-generation",
|
| 22 |
+
"onnx-community/nanochat-d32-ONNX",
|
| 23 |
+
{ dtype: "q4" },
|
| 24 |
+
);
|
| 25 |
+
|
| 26 |
+
// Define the list of messages
|
| 27 |
+
const messages = [
|
| 28 |
+
{ role: "system", content: "You are a helpful assistant." },
|
| 29 |
+
{ role: "user", content: "What is the capital of France?" },
|
| 30 |
+
];
|
| 31 |
+
|
| 32 |
+
// Generate a response
|
| 33 |
+
const output = await generator(messages, {
|
| 34 |
+
max_new_tokens: 512,
|
| 35 |
+
do_sample: false,
|
| 36 |
+
streamer: new TextStreamer(generator.tokenizer, { skip_prompt: true, skip_special_tokens: true}),
|
| 37 |
+
});
|
| 38 |
+
console.log(output[0].generated_text.at(-1).content);
|
| 39 |
+
```
|