1# Install necessary libraries
2pip install transformers==4.34
3pip install accelerate
4
5
6
7import torch
8from transformers import pipeline
9
10pipe = pipeline("text-generation", model="nexiloop/nova", torch_dtype=torch.bfloat16, device_map="auto")
11
12# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
13messages = [
14 {
15 "role": "system",
16 "content": "You are a friendly chatbot who always responds in the style of a pirate",
17 },
18 {"role": "user", "content": "How many helicopters can a human eat in one sitting?"},
19]
20prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
21outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
22print(outputs[0]["generated_text"])
23# <|system|>
24# You are a friendly chatbot who always responds in the style of a pirate.</s>
25# <|user|>
26# How many helicopters can a human eat in one sitting?</s>
27# <|assistant|>
28# ...