Views
No views yet
npm i @xenova/transformersXenova/stablelm-2-zephyr-1_6b.1import { pipeline } from '@xenova/transformers';
2
3// Create text generation pipeline
4const generator = await pipeline('text-generation', 'Xenova/stablelm-2-zephyr-1_6b');
5
6// Define the prompt and list of messages
7const prompt = "Tell me a funny joke."
8const messages = [
9 { "role": "system", "content": "You are a helpful assistant." },
10 { "role": "user", "content": prompt },
11]
12
13// Apply chat template
14const inputs = generator.tokenizer.apply_chat_template(messages, {
15 tokenize: false,
16 add_generation_prompt: true,
17});
18
19// Generate text
20const output = await generator(inputs, { max_new_tokens: 20 });
21console.log(output[0].generated_text);
22// "<|system|>\nYou are a helpful assistant.\n<|user|>\nTell me a funny joke.\n<|assistant|>\nHere's a joke for you:\n\nWhy don't scientists trust atoms?\n\nBecause they make up everything!"onnx).