hfchat / gdpr.py
Phitographix's picture
Upload 14 files
bda6294 verified
Raw
History Blame Contribute Delete
2.27 kB
# -*- coding: utf-8 -*-
"""
Utilitaires de conformite RGPD / GDPR compliance utilities (Space edition).
"""
import re
import json
from datetime import datetime
import config
_EMAIL_RE = re.compile(r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}")
_PHONE_RE = re.compile(r"(\+?\d[\d\s().-]{7,}\d)")
def anonymize(text: str) -> str:
if not text:
return text
text = _EMAIL_RE.sub("[email masque]", text)
text = _PHONE_RE.sub("[telephone masque]", text)
return text
def safe_for_processing(text: str) -> str:
return anonymize(text) if config.ANONYMIZE_INPUT else text
def log_interaction(question, answer, sources):
if not config.ENABLE_LOGGING:
return
entry = {
"ts": datetime.utcnow().isoformat(),
"question": anonymize(question),
"answer": anonymize(answer),
"sources": [s.get("url") for s in sources],
}
log_file = config.LOG_DIR / f"log_{datetime.utcnow():%Y%m%d}.jsonl"
with open(log_file, "a", encoding="utf-8") as f:
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
def purge_all_logs():
n = 0
for f in config.LOG_DIR.glob("log_*.jsonl"):
f.unlink()
n += 1
return n
NOTICE_FR = (
"**Confidentialite (RGPD).** Assistant reserve repondant a partir du "
"contenu du site Vizyon Ayiti 360, y compris des documents internes selon "
"vos droits. Vos questions et documents sont traites pour generer la "
"reponse et ne sont pas conserves. Ne partagez ces reponses qu'avec les "
"personnes autorisees."
)
NOTICE_EN = (
"**Privacy (GDPR).** Restricted assistant answering from Vizyon Ayiti 360 "
"website content, including internal documents according to your rights. "
"Your questions and documents are processed to generate the answer and are "
"not stored. Share these answers only with authorized people."
)
NOTICE_HT = (
"**Konfidansyalite (RGPD).** Asistan rezeve k ap reponn ak kontni sit "
"Vizyon Ayiti 360, ki gen ladan dokiman enten selon dwa ou. Kesyon ak "
"dokiman ou yo trete pou bay repons lan epi yo pa konseve. Pataje repons "
"sa yo selman ak moun ki otorize."
)
def notice(lang="fr"):
return {"en": NOTICE_EN, "ht": NOTICE_HT}.get(lang, NOTICE_FR)