Delta-Ultra-Mini / delta /identity.py
Delta-FlareAI's picture
Upload folder using huggingface_hub
a006332 verified
Raw
History Blame Contribute Delete
2.73 kB
"""Hardcoded identity helpers for Delta Ultra Mini.
This module keeps the immutable public identity of the model in one place and
provides a small interceptor for identity questions. The interceptor is used
before neural generation so the model never has to infer facts about itself.
"""
from __future__ import annotations
import logging
import os
import re
from typing import Any
logging.basicConfig(level=os.getenv("DELTA_LOG_LEVEL", "INFO").upper())
logger = logging.getLogger(__name__)
_IDENTITY: dict[str, str] = {
"name": "Delta",
"version": "Ultra Mini",
"created_by": "Flame Corporation",
"parameters": "~50 milhões",
"purpose": "Assistente conversacional inteligente via API",
}
_IDENTITY_PATTERNS: tuple[re.Pattern[str], ...] = tuple(
re.compile(pattern, flags=re.IGNORECASE)
for pattern in (
r"qual.*seu nome",
r"who are you",
r"quem.*voc[eê]",
r"sua vers[aã]o",
r"your version",
r"quem.*criou",
r"who made you",
r"quantos par[aâ]metros",
r"how many parameters",
)
)
def get_identity() -> dict[str, str]:
"""Return Delta's immutable identity.
Returns:
A copy of the identity dictionary.
"""
return dict(_IDENTITY)
def is_identity_question(text: str) -> bool:
"""Check whether a user message asks about Delta's identity.
Args:
text: User-provided text.
Returns:
True when the text matches one of the hardcoded identity regexes.
"""
return any(pattern.search(text) for pattern in _IDENTITY_PATTERNS)
def identity_response(text: str) -> str | None:
"""Return a deterministic identity answer when the input asks for it.
Args:
text: User-provided text.
Returns:
A precise identity answer, or None when the input should go to the
neural model.
"""
if not is_identity_question(text):
return None
identity: dict[str, Any] = get_identity()
lowered = text.lower()
if re.search(r"quantos par[aâ]metros|how many parameters", lowered):
return f"Eu sou {identity['name']} {identity['version']} e tenho {identity['parameters']} de parâmetros."
if re.search(r"sua vers[aã]o|your version", lowered):
return f"Minha versão é {identity['version']}."
if re.search(r"quem.*criou|who made you", lowered):
return f"Fui criada pela {identity['created_by']}."
if re.search(r"qual.*seu nome", lowered):
return f"Meu nome é {identity['name']}."
return (
f"Eu sou {identity['name']} {identity['version']}, criada pela "
f"{identity['created_by']}. Meu propósito é ser um "
f"{identity['purpose'].lower()}."
)