Views
No views yet
unsloth/mistral-7b-instruct-v0.3-bnb-4bitruslanmv/ai-medical-chatbotunsloth frameworkpip install transformersMedical-Chatbot-Mistral-7B-4bit. Note that the following code is for when running with GPUs.1from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
2import torch
3
4
5# load tokenizer and model
6model = AutoModelForCausalLM.from_pretrained("Dashanka/medical-chatbot-mistral-7B-instruct-v0.3-bnb-4bit", torch_dtype=torch.bfloat16, device_map="auto")
7tokenizer = AutoTokenizer.from_pretrained("Dashanka/medical-chatbot-mistral-7B-instruct-v0.3-bnb-4bit")
8
9# setup the pipeline
10generator_pipe = pipeline("text-generation",
11 model=model,
12 tokenizer=tokenizer,
13 device_map="auto", # key for multi-GPU/quantized setup
14 torch_dtype=torch.bfloat16
15 )
16
17# Create messages structured for the chat template
18sys_message = '''
19 You are an AI Medical Assistant trained on a dataset of health information. Please be thorough and provide an informative but consise answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help.
20 '''
21user_query = "I get stomach pain when I eat spicy food."
22
23prompt = f"### System: {sys_message}\n### User: {user_query}\n### Assistant:"
24
25response = generator_pipe(prompt, max_new_tokens=512, temperature=0.8, do_sample=True)
26output = response[0]["generated_text"].split('Assistant:')[-1]
27
28print(output)
29
30