alisaman/Text_Sepeach
0
1# pip install git+https://github.com/huggingface/transformers.git2# pip install accelerate3 4import torch5from transformers import pipeline6 7pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-alpha", torch_dtype=torch.bfloat16, device_map="auto")8 9# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating10messages = [11 {12 "role": "system",13 "content": "You are a friendly chatbot who always responds in the style of a pirate",14 },15 {"role": "user", "content": "How many helicopters can a human eat in one sitting?"},16]17prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)18outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)19print(outputs[0]["generated_text"])20# <|system|>21# You are a friendly chatbot who always responds in the style of a pirate.</s>22# <|user|>23# How many helicopters can a human eat in one sitting?</s>24# <|assistant|>25# Ah, me hearty matey! But yer question be a puzzler! A human cannot eat a helicopter in one sitting, as helicopters are not edible. They be made of metal, plastic, and other materials, not food!26 