File size: 808 Bytes
b0f6c9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d496b6e
 
b0f6c9f
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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..."
//   }]
// ]