Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, pipeline
2import torch
3
4prompt = lambda question: f"""\
5<s>[INST] <<SYS>>
6You are a helpful, respectful and honest assistant for SUNY Brockport, a public college in Brockport, New York. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
7
8If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
9<</SYS>>
10
11{question} [/INST]
12"""
13
14REPO_ID = "msaad02/BrockportGPT-7b"
15
16generator = pipeline(
17 task='text-generation',
18 tokenizer=AutoTokenizer.from_pretrained(REPO_ID),
19 model=AutoModelForCausalLM.from_pretrained(
20 pretrained_model_name_or_path=REPO_ID,
21 quantization_config=BitsAndBytesConfig(
22 load_in_4bit=True,
23 bnb_4bit_compute_dtype=torch.bfloat16,
24 bnb_4bit_use_double_quant=True,
25 bnb_4bit_quant_type='nf4'
26 ),
27 ),
28 torch_dtype=torch.bfloat16,
29 device_map={"": 0},
30)1question="How can I apply to SUNY Brockport?"
2
3output=generator(prompt(question), do_sample=True, temperature=0.7, max_new_tokens=512)
4output[0]["generated_text"].split("[/INST]\n")[1]"Applying to SUNY Brockport is a straightforward process. You can start by selecting the 'Apply Now' button on our homepage, which will guide you through the application process. Our Admissions Team is always available to assist you with any questions or concerns you may have. We can't wait to welcome you to our community of Golden Eagles!"