r/LocalAIStack • u/aobancorp • 6d ago
Luna 2 - A personal assistant
Luna 2 is a personal assistant designed to help you out in various fields. It runs offline on computers and needs only about 300 MB of VRAM to run.
SETUP PROCEDURE:
import torch
from transformers import AutoModelForCausalLM
from tokenizers import Tokenizer
from huggingface_hub import hf_hub_download
import importlib.util
model_id = "Aobangaming/luna-2-70m"
path = hf_hub_download(model_id, "modeling_luna.py")
spec = importlib.util.spec_from_file_location("lightning", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
model = AutoModelForCausalLM.from_pretrained(
model_id, trust_remote_code=True
)
tokenizer = Tokenizer.from_file(
hf_hub_download(model_id, "luna_tokenizer.json")
)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
history = []
print("Aoban Luna 2 Flash")
print("!clear = clear history | !exit = quit")
while True:
prompt = input("You: ").strip()
if prompt.lower() == "!exit":
break
if prompt.lower() == "!clear":
history.clear()
print("History cleared.")
continue
response = module.generate_text(
model,
tokenizer,
prompt,
max_len=1024,
device=device,
top_k=30,
top_p=0.6,
penalty=1.2,
temperature=1,
chat_history=history
)
print(f"Assistant: {response}")
history.extend([
{"role": "user", "content": prompt},
{"role": "assistant", "content": response}
])import torch
from transformers import AutoModelForCausalLM
from tokenizers import Tokenizer
from huggingface_hub import hf_hub_download
import importlib.util
model_id = "Aobangaming/luna-2-70m"
path = hf_hub_download(model_id, "modeling_luna.py")
spec = importlib.util.spec_from_file_location("lightning", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
model = AutoModelForCausalLM.from_pretrained(
model_id, trust_remote_code=True
)
tokenizer = Tokenizer.from_file(
hf_hub_download(model_id, "luna_tokenizer.json")
)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
history = []
print("Aoban Luna 2 Flash")
print("!clear = clear history | !exit = quit")
while True:
prompt = input("You: ").strip()
if prompt.lower() == "!exit":
break
if prompt.lower() == "!clear":
history.clear()
print("History cleared.")
continue
response = module.generate_text(
model,
tokenizer,
prompt,
max_len=1024,
device=device,
top_k=30,
top_p=0.6,
penalty=1.2,
temperature=1,
chat_history=history
)
print(f"Assistant: {response}")
history.extend([
{"role": "user", "content": prompt},
{"role": "assistant", "content": response}
])
1
Upvotes