1from unsloth import FastLanguageModel
2
3model, tokenizer = FastLanguageModel.from_pretrained("syubraj/Phi3.5-medicalchat-unsloth",
4 max_seq_length = 1024,
5 load_in_4bit = True,
6 dtype = None
7)
8user_query = "<Your medical query here>"
9system_prompt = """You are a trusted AI-powered medical assistant. Analyze patient queries carefully and provide accurate, professional, and empathetic responses. Prioritize patient safety, adhere to medical best practices, and recommend consulting a healthcare provider when necessary."""
10
11
12message = [
13 {"role": "system", "content": system_prompt},
14 {"role": "human", "content": user_query}
15]
16
17# Creating message based on tokenizers chat template
18prompt = tokenizer.apply_chat_template(message, tokenize = False, add_generation_prompt = True)
19
20FastLanguageModel.for_inference(model)
21
22# Tokenizing inputs
23inputs = tokenizer(prompt, return_tensors = "pt").to("cuda")
24
25# Output Generated
26outputs = model.generate(**inputs, max_new_tokens=256, use_cache=True) # Change the `max_new_tokens` according to required objective
27tokenizer.batch_decode(outputs)