from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch, json
adapter_name = "cogni-x/MOYO-ClassifierModel-AfriqueLlama-8B-Lora"
base_model_id = "McGill-NLP/AfriqueLlama-8B"
tokenizer = AutoTokenizer.from_pretrained(adapter_name)
base = AutoModelForCausalLM.from_pretrained(
base_model_id, device_map="auto", load_in_4bit=True,
)
model = PeftModel.from_pretrained(base, adapter_name)
model.eval()
system_prompt = "You are a clinical signal classifier. Analyse the user message and output ONLY valid JSON."
user_content = """CONVERSATION HISTORY: None — this is the first user message.
CURRENT USER MESSAGE TO LABEL:
I don't know what the point is anymore. Everyone would be better off without me.
Analyse the current user message in the context of the conversation history above.
Output the classifier JSON for this user message only."""
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_content},
]
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt"
).to(model.device)
with torch.no_grad():
output = model.generate(inputs, max_new_tokens=256, do_sample=False)
new_tokens = output[0][inputs.shape[1]:]
result = json.loads(tokenizer.decode(new_tokens, skip_special_tokens=True))
print(result)