Views
No views yet
1# Load model directly or use qunatization technique if you have low gpu ram
2
3from transformers import AutoTokenizer, AutoModelForCausalLM
4
5tokenizer = AutoTokenizer.from_pretrained("dilip025/llama-2-7b")
6model = AutoModelForCausalLM.from_pretrained("dilip025/llama-2-7b")
7system_message = 'You are NutriLife chatbot, you are going to get questions related to food, nutrition, health, and diet by the users from Nepal. Answer them very shortly and accurately if the message is only about food, nutrition, and diet. Otherwise, ignore.'
8
9prompt = f"[INST] <<SYS>>\n{system_message}\n<</SYS>>\n\n Tell me some of the famous Nepali food recipes [/INST]"
10num_new_tokens = 200 # Change to the number of new tokens you want to generate
11
12# Count the number of tokens in the prompt
13num_prompt_tokens = len(tokenizer(prompt)['input_ids'])
14
15# Calculate the maximum length for the generation
16max_length = num_prompt_tokens + num_new_tokens
17
18gen = pipeline('text-generation', model=model, tokenizer=tokenizer, max_length=max_length)
19result = gen(prompt)
20print(result[0]['generated_text'].replace(prompt, ''))