webgpu / index.js
MRasheq's picture
Update index.js
b0f6c9f verified
raw
history blame
808 Bytes
import { pipeline } from "@huggingface/transformers";
// Create a text-generation pipeline
const generator = await pipeline(
"text-generation",
"HuggingFaceTB/SmolLM2-360M", // You can replace this with other models like "EleutherAI/gpt-neo-125M" or "facebook/opt-125m"
{ device: "webgpu" }
);
// Generate text
const prompts = [
"Once upon a time",
"The artificial intelligence"
];
const results = await generator(prompts, {
max_length: 50,
num_return_sequences: 1,
temperature: 0.7,
top_p: 0.9
});
console.log(results);
// Will output something like:
// [
// [{
// "generated_text": "Once upon a time there was a young princess who lived in a castle..."
// }],
// [{
// "generated_text": "The artificial intelligence revolution has transformed the way we..."
// }]
// ]