File size: 5,549 Bytes
bda6294
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
"""
Configuration de l'Assistant Vizyon Ayiti 360 - version Hugging Face Space.
Config for the Vizyon Ayiti 360 Assistant - Hugging Face Space edition.

Sur Hugging Face, definissez les valeurs sensibles dans
Settings > Variables and secrets (elles arrivent comme variables d'env).
On Hugging Face, set sensitive values in Settings > Variables and secrets.
"""
import os
from pathlib import Path

try:
    from dotenv import load_dotenv
    load_dotenv()
except Exception:
    pass

# --------------------------------------------------------------------------
# Site source (seule source autorisee / only allowed source)
# --------------------------------------------------------------------------
SITE_URL = os.getenv("SITE_URL", "https://www.vizyonayiti360.org")
WP_API_BASE = f"{SITE_URL.rstrip('/')}/wp-json/wp/v2"

WP_CONTENT_TYPES = {
    "posts": "Article",
    "pages": "Page",
    "mec-events": "Evenement",
}

# --------------------------------------------------------------------------
# Authentification WordPress (pour lire le contenu NON public)
# WordPress authentication (to read NON-public content)
# --------------------------------------------------------------------------
# Cree un "mot de passe d'application" dans WordPress :
#   Utilisateurs > Profil > Mots de passe d'application.
# Create an "Application Password" in WordPress:
#   Users > Profile > Application Passwords.
WP_USERNAME = os.getenv("WP_USERNAME", "")
WP_APP_PASSWORD = os.getenv("WP_APP_PASSWORD", "")
# Inclure le contenu non public si des identifiants sont fournis.
INCLUDE_NON_PUBLIC = os.getenv("INCLUDE_NON_PUBLIC", "true").lower() == "true"
# Statuts a recuperer quand on est authentifie.
WP_STATUSES = os.getenv("WP_STATUSES", "publish,private,draft,pending,future")

# --------------------------------------------------------------------------
# Backend LLM : sur un Space, on utilise l'API Hugging Face.
# LLM backend: on a Space we use the Hugging Face Inference API.
# --------------------------------------------------------------------------
LLM_BACKEND = os.getenv("LLM_BACKEND", "hf_api").lower()

# Token HF : dans un Space, ajoutez le secret HF_TOKEN (fourni par defaut sur
# certains Spaces) ou HF_API_TOKEN.
HF_API_TOKEN = os.getenv("HF_API_TOKEN", os.getenv("HF_TOKEN", ""))
HF_MODEL = os.getenv("HF_MODEL", "meta-llama/Llama-3.1-8B-Instruct")

# Repli local optionnel (si vous testez hors Space avec Ollama).
OLLAMA_HOST = os.getenv("OLLAMA_HOST", "http://localhost:11434")
OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "qwen2.5:7b-instruct")

# --------------------------------------------------------------------------
# Embeddings (locaux, multilingues FR/EN) / local multilingual embeddings
# --------------------------------------------------------------------------
EMBEDDING_MODEL = os.getenv(
    "EMBEDDING_MODEL",
    "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
)

# --------------------------------------------------------------------------
# Parametres RAG / RAG parameters
# --------------------------------------------------------------------------
CHUNK_SIZE = int(os.getenv("CHUNK_SIZE", "800"))
CHUNK_OVERLAP = int(os.getenv("CHUNK_OVERLAP", "120"))
TOP_K = int(os.getenv("TOP_K", "5"))
MIN_SCORE = float(os.getenv("MIN_SCORE", "0.25"))
MAX_TOKENS = int(os.getenv("MAX_TOKENS", "1024"))
TEMPERATURE = float(os.getenv("TEMPERATURE", "0.2"))

# Reconstruire l'index a chaque demarrage du Space (contenu frais).
REBUILD_ON_START = os.getenv("REBUILD_ON_START", "true").lower() == "true"

# --------------------------------------------------------------------------
# Stockage / storage (ephemere sur un Space)
# --------------------------------------------------------------------------
BASE_DIR = Path(__file__).resolve().parent
DATA_DIR = BASE_DIR / "data"
INDEX_DIR = DATA_DIR / "index"
LOG_DIR = DATA_DIR / "logs"
for _d in (DATA_DIR, INDEX_DIR, LOG_DIR):
    _d.mkdir(parents=True, exist_ok=True)

INDEX_FILE = INDEX_DIR / "faiss.index"
CHUNKS_FILE = INDEX_DIR / "chunks.pkl"
META_FILE = INDEX_DIR / "meta.json"

# --------------------------------------------------------------------------
# Interface / UI
# --------------------------------------------------------------------------
APP_TITLE = "Assistant Vizyon Ayiti 360"
DEFAULT_LANG = os.getenv("DEFAULT_LANG", "fr")

# Jeton d'acces partage : si defini, l'app n'accepte que les visiteurs dont
# l'URL contient ?access=<jeton>. Protege l'acces direct au Space quand il est
# integre en iframe. Laisser vide pour desactiver.
# Shared access token: if set, the app only serves visitors whose URL contains
# ?access=<token>. Protects direct Space access when embedded via iframe.
APP_ACCESS_TOKEN = os.getenv("APP_ACCESS_TOKEN", "")

LOGO_URL = os.getenv(
    "LOGO_URL",
    "https://www.vizyonayiti360.org/wp-content/uploads/2025/12/"
    "cropped-logo-4_1-300x100.png",
)
FAVICON_URL = os.getenv(
    "FAVICON_URL",
    "https://www.vizyonayiti360.org/wp-content/uploads/2026/06/"
    "cropped-fivicon-192x192.png",
)

# --------------------------------------------------------------------------
# RGPD / GDPR
# --------------------------------------------------------------------------
ENABLE_LOGGING = os.getenv("ENABLE_LOGGING", "false").lower() == "true"
ANONYMIZE_INPUT = os.getenv("ANONYMIZE_INPUT", "true").lower() == "true"
LOG_RETENTION_DAYS = int(os.getenv("LOG_RETENTION_DAYS", "30"))

# Le contenu non public est confidentiel : ne jamais journaliser par defaut.
if INCLUDE_NON_PUBLIC:
    ENABLE_LOGGING = False