Text Generation
Transformers
Safetensors
English
qwen2
rag
retrieval-augmented-generation
knowledge-base
emotion-detection
dual-stage-retrieval
coding
math
science
history
nyxis
quantasparklabs
conversational
text-generation-inference
Instructions to use QuantaSparkLabs/NYXIS-Pro with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use QuantaSparkLabs/NYXIS-Pro with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="QuantaSparkLabs/NYXIS-Pro") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("QuantaSparkLabs/NYXIS-Pro") model = AutoModelForCausalLM.from_pretrained("QuantaSparkLabs/NYXIS-Pro", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use QuantaSparkLabs/NYXIS-Pro with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "QuantaSparkLabs/NYXIS-Pro" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QuantaSparkLabs/NYXIS-Pro", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/QuantaSparkLabs/NYXIS-Pro
- SGLang
How to use QuantaSparkLabs/NYXIS-Pro with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "QuantaSparkLabs/NYXIS-Pro" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QuantaSparkLabs/NYXIS-Pro", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "QuantaSparkLabs/NYXIS-Pro" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QuantaSparkLabs/NYXIS-Pro", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use QuantaSparkLabs/NYXIS-Pro with Docker Model Runner:
docker model run hf.co/QuantaSparkLabs/NYXIS-Pro
Upload pipeline.py with huggingface_hub
Browse files- pipeline.py +94 -0
pipeline.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import faiss, numpy as np, torch, os, re
|
| 3 |
+
from sentence_transformers import SentenceTransformer, CrossEncoder
|
| 4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 5 |
+
|
| 6 |
+
class NYXISPro:
|
| 7 |
+
def __init__(self, model_dir="."):
|
| 8 |
+
self.embedder = SentenceTransformer(f"{model_dir}/aegis_embedder")
|
| 9 |
+
self.reranker = CrossEncoder(f"{model_dir}/aegis_reranker")
|
| 10 |
+
self.index = faiss.read_index(f"{model_dir}/aegis_index.faiss")
|
| 11 |
+
with open(f"{model_dir}/aegis_chunks.txt", "r") as f:
|
| 12 |
+
self.chunks = [c.strip() for c in f.read().split("<|CHUNK_END|>") if c.strip()]
|
| 13 |
+
bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4",
|
| 14 |
+
bnb_4bit_compute_dtype=torch.float16, bnb_4bit_use_double_quant=True)
|
| 15 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
|
| 16 |
+
self.model = AutoModelForCausalLM.from_pretrained(model_dir,
|
| 17 |
+
quantization_config=bnb, device_map="auto", trust_remote_code=True)
|
| 18 |
+
self.identity = "You are NYXIS, a sharp, warm, and endlessly curious mind. You speak like a clever friend — casual, direct, and human. You notice how people feel and match their energy."
|
| 19 |
+
self.last_emotion = 5
|
| 20 |
+
|
| 21 |
+
def detect_emotion(self, text):
|
| 22 |
+
t = text.lower()
|
| 23 |
+
joy = sum(1 for w in ["happy","excited","great","awesome","love","wonderful","joy","thrilled","good","nice"] if w in t)
|
| 24 |
+
sadness = sum(1 for w in ["sad","depressed","upset","crying","lonely","hurt","broken","bad","awful"] if w in t)
|
| 25 |
+
anger = sum(1 for w in ["angry","furious","mad","rage","annoyed","frustrated","pissed","stupid","hate"] if w in t)
|
| 26 |
+
if joy: return min(10, self.last_emotion + joy)
|
| 27 |
+
if sadness: return max(1, self.last_emotion - sadness)
|
| 28 |
+
if anger: return max(1, self.last_emotion - anger)
|
| 29 |
+
return self.last_emotion
|
| 30 |
+
|
| 31 |
+
def rag_lookup(self, query, top_k=5):
|
| 32 |
+
q_emb = self.embedder.encode([query], normalize_embeddings=True).astype('float32')
|
| 33 |
+
_, indices = self.index.search(q_emb, 20)
|
| 34 |
+
texts = [self.chunks[idx] for idx in indices[0] if idx < len(self.chunks)]
|
| 35 |
+
if not texts: return None
|
| 36 |
+
pairs = [(query, t[:500]) for t in texts]
|
| 37 |
+
scores = self.reranker.predict(pairs)
|
| 38 |
+
ranked = sorted(zip(scores, texts), reverse=True)[:top_k]
|
| 39 |
+
results = [t[:600] for s, t in ranked if s > -4.0]
|
| 40 |
+
return "\n\n".join(results) if results else None
|
| 41 |
+
|
| 42 |
+
def _generate(self, system, user, max_tokens=256):
|
| 43 |
+
prompt = f"<|im_start|>system\n{system}<|im_end|>\n<|im_start|>user\n{user}<|im_end|>\n<|im_start|>assistant\n"
|
| 44 |
+
inputs = self.tokenizer(prompt, return_tensors="pt").to(self.model.device)
|
| 45 |
+
with torch.no_grad():
|
| 46 |
+
outputs = self.model.generate(**inputs, max_new_tokens=max_tokens, temperature=0.8,
|
| 47 |
+
do_sample=True, top_p=0.92, repetition_penalty=1.1,
|
| 48 |
+
pad_token_id=self.tokenizer.eos_token_id,
|
| 49 |
+
eos_token_id=self.tokenizer.encode("<|im_end|>", add_special_tokens=False)[0])
|
| 50 |
+
raw = self.tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True).strip()
|
| 51 |
+
raw = re.sub(r'\n*assistant\s*$', '', raw, flags=re.IGNORECASE).strip()
|
| 52 |
+
return raw
|
| 53 |
+
|
| 54 |
+
def generate(self, user_message, external_search_fn=None):
|
| 55 |
+
self.last_emotion = self.detect_emotion(user_message)
|
| 56 |
+
msg = user_message.lower().strip()
|
| 57 |
+
casual_starts = ["hi","hey","hello","yo","sup","good morning","good evening","how are you","what's up","good job","thanks","bye","okay","huh"]
|
| 58 |
+
casual_patterns = ["good job","well done","nice one","thank","lol","haha","bro","dude","mate","nigga","chill","relax","talk","chat","joke","story","what do you think","opinion","favorite","you stupid","you dumb","be free","normal","boring","lifeless","your name","who are you","what are you","tell me about yourself","how old are you","what is your name","who made you"]
|
| 59 |
+
is_casual = any(msg.startswith(s) for s in casual_starts) or any(p in msg for p in casual_patterns)
|
| 60 |
+
factual_starts = ["what","who","when","where","why","how","explain","define","list","compare","describe","find","search","calculate","solve"]
|
| 61 |
+
math_patterns = re.search(r'\d+[\+\-\*\/\=]\d+', msg)
|
| 62 |
+
is_factual = any(msg.startswith(s) for s in factual_starts) or bool(math_patterns) or len(msg) > 50
|
| 63 |
+
|
| 64 |
+
if is_casual and not is_factual:
|
| 65 |
+
system = f"{self.identity}\nThe user's vibe is {self.last_emotion}/10. Match it.\nYou're having a casual conversation. Be warm, brief, and real."
|
| 66 |
+
response = self._generate(system, user_message)
|
| 67 |
+
return {"response": response, "emotion_level": self.last_emotion, "knowledge_source": "chat"}
|
| 68 |
+
|
| 69 |
+
if is_factual:
|
| 70 |
+
aegis = self.rag_lookup(user_message)
|
| 71 |
+
if aegis:
|
| 72 |
+
system = f"{self.identity}\nVibe: {self.last_emotion}/10.\nUse ONLY this verified context to answer:\n\n{aegis}"
|
| 73 |
+
response = self._generate(system, user_message)
|
| 74 |
+
return {"response": response, "emotion_level": self.last_emotion, "knowledge_source": "AEGIS"}
|
| 75 |
+
if external_search_fn:
|
| 76 |
+
try:
|
| 77 |
+
ext = external_search_fn(user_message)
|
| 78 |
+
if ext and len(ext) > 50:
|
| 79 |
+
system = f"{self.identity}\nVibe: {self.last_emotion}/10.\nUse this web-sourced context:\n\n{ext}"
|
| 80 |
+
response = self._generate(system, user_message)
|
| 81 |
+
return {"response": response, "emotion_level": self.last_emotion, "knowledge_source": "external"}
|
| 82 |
+
except: pass
|
| 83 |
+
system = f"{self.identity}\nVibe: {self.last_emotion}/10.\nAEGIS and web failed. Answer from your own knowledge IF confident.\nIf you don't truly know, say exactly: 'I'd need to look that up.'"
|
| 84 |
+
response = self._generate(system, user_message)
|
| 85 |
+
source = "model" if "look that up" not in response.lower() else "none"
|
| 86 |
+
return {"response": response, "emotion_level": self.last_emotion, "knowledge_source": source}
|
| 87 |
+
|
| 88 |
+
aegis = self.rag_lookup(user_message)
|
| 89 |
+
if aegis:
|
| 90 |
+
system = f"{self.identity}\nVibe: {self.last_emotion}/10.\nUse this relevant context if helpful, but stay conversational:\n\n{aegis}"
|
| 91 |
+
else:
|
| 92 |
+
system = f"{self.identity}\nVibe: {self.last_emotion}/10.\nStay conversational."
|
| 93 |
+
response = self._generate(system, user_message)
|
| 94 |
+
return {"response": response, "emotion_level": self.last_emotion, "knowledge_source": "hybrid"}
|