Views
No views yet
1# Install transformers from source - only needed for versions <= v4.34
2# pip install git+https://github.com/huggingface/transformers.git
3# pip install accelerate
4
5import torch
6from transformers import pipeline
7
8pipe = pipeline("text-generation", model="olliai/Maika-Buddy-1B1-Chat", torch_dtype=torch.bfloat16, device_map="auto")
9
10# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
11list_questions = ["How do I write a letter to my friend?",
12 "Where do babies come from?"
13 ]
14for q in list_questions:
15 messages = """<|system|>
16A chat between a curious kid and an artificial intelligence assistant. The assistant gives helpful, easy-to-understand, detailed, and polite answers to the questions of the kid.</s>
17<|user|>
18{user_message}</s>
19<|assistant|>
20"""
21 prompt = messages.format(user_message=q)
22 outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.3, top_k=50, top_p=0.95)
23 print(outputs[0]["generated_text"])
24 print("="*50)
25