|
--- |
|
license: apache-2.0 |
|
base_model: |
|
- HuggingFaceTB/SmolLM2-360M-Instruct |
|
pipeline_tag: text-generation |
|
tags: |
|
- transformers.js |
|
--- |
|
|
|
## Usage (Transformers.js) |
|
|
|
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: |
|
```bash |
|
npm i @huggingface/transformers |
|
``` |
|
|
|
You can then generate text as follows: |
|
```js |
|
import { pipeline } from '@huggingface/transformers'; |
|
|
|
// Create a text generation pipeline |
|
const generator = await pipeline('text-generation', 'eduardoworrel/SmolLM2-360M-Instruct', { |
|
device: 'webgpu', // <- Run on WebGPU |
|
}); |
|
|
|
// Define the list of messages |
|
const messages = [ |
|
{ role: "system", content: "You are a helpful assistant." }, |
|
{ role: "user", content: "What is the capital of Brazil?" }, |
|
]; |
|
|
|
// Generate a response |
|
const output = await generator(messages, { max_new_tokens: 128 }); |
|
console.log(output[0].generated_text.at(-1).content); |
|
``` |