Views
No views yet
1<|im_start|>system
2You are a helpful assistant.<|im_end|>
3<|im_start|>user
4Question?<|im_end|>
5<|im_start|>assistant1<|im_start|>system
2You are a helpful assistant.<|im_end|>
3<|im_start|>user
4How to explain Internet for a medieval knight?<|im_end|>
5<|im_start|>assistant<|im_start|>assistant .pip install git+https://github.com/huggingface/transformers1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
4torch.random.manual_seed(0)
5
6model_id = "rasyosef/Llama-3.1-Minitron-4B-Chat"
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 device_map="auto",
10 torch_dtype=torch.bfloat16
11)
12
13tokenizer = AutoTokenizer.from_pretrained(model_id)
14
15messages = [
16 {"role": "system", "content": "You are a helpful AI assistant."},
17 {"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
18 {"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
19 {"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
20]
21
22pipe = pipeline(
23 "text-generation",
24 model=model,
25 tokenizer=tokenizer,
26)
27
28generation_args = {
29 "max_new_tokens": 256,
30 "return_full_text": False,
31 "temperature": 0.0,
32 "do_sample": False,
33}
34
35output = pipe(messages, **generation_args)
36print(output[0]['generated_text'])