Views
No views yet
1from unsloth import FastLanguageModel
2import torch
3
4# Load base model
5model, tokenizer = FastLanguageModel.from_pretrained(
6 model_name="unsloth/Meta-Llama-3.1-8B-Instruct",
7 max_seq_length=2048,
8 dtype=None,
9 load_in_4bit=True,
10 device_map="auto", # Use this if you have memory issues
11)
12
13# Load this adapter
14model.load_adapter("menikev/Llama-3.1-8B-NigerianLegalBot", adapter_name="default")
15
16# Enable inference
17FastLanguageModel.for_inference(model)
18
19# Use the model
20system_prompt = "You are a helpful and knowledgeable legal assistant in Nigeria. Respond to queries in the language of the user's question."
21
22messages = [
23 {"role": "system", "content": system_prompt},
24 {"role": "user", "content": "What are the requirements for business registration in Nigeria?"}
25]
26
27inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
28
29with torch.no_grad():
30 outputs = model.generate(
31 input_ids=inputs.to("cuda"),
32 max_new_tokens=512,
33 temperature=0.7,
34 do_sample=True,
35 )
36
37response = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
38print(response)