Files
aethas-free/modules/rag_manager.py
T
xavier 2d7d93bc27
Build and Push Docker Image / build-and-push (push) Successful in 38s
fix: Résolution import RAG et correction HTTPResponse pour les pings
2026-08-20 19:33:17 +02:00

68 lines
2.5 KiB
Python

import os
from modules.logger import log_event
# Définition du chemin racine sécurisé sur ton RAID
RAG_BASE_DIR = "/DATA/AppData/MULTI-IA-AETHAS38/RAG"
# Les thématiques générales pour organiser l'apprentissage
THEMATIQUES_RAG = [
"Minecraft_KubeJS",
"Juridique_Loi_Francaise",
"Serveur_Debian",
"Bureautique_Excel",
"Regles_Aethas38"
]
def initialiser_arborescence_rag():
"""Crée les dossiers RAG physiques sur le disque s'ils n'existent pas."""
try:
if not os.path.exists(RAG_BASE_DIR):
os.makedirs(RAG_BASE_DIR)
log_event("INFO", "RAG", "Création du dossier racine RAG.")
for theme in THEMATIQUES_RAG:
chemin_theme = os.path.join(RAG_BASE_DIR, theme)
if not os.path.exists(chemin_theme):
os.makedirs(chemin_theme)
log_event("INFO", "RAG", f"Création du sous-dossier thématique : {theme}")
except Exception as e:
log_event("ERROR", "RAG", f"Erreur lors de l'initialisation de l'arborescence : {e}")
def extraire_contexte_rag(thematique):
"""
Lit tous les fichiers .txt ou .md d'une thématique donnée
et les concatène pour les injecter dans le prompt de l'IA.
"""
contexte_global = ""
chemin_theme = os.path.join(RAG_BASE_DIR, thematique)
if not os.path.exists(chemin_theme):
return contexte_global
try:
for fichier in os.listdir(chemin_theme):
if fichier.endswith(".txt") or fichier.endswith(".md"):
chemin_fichier = os.path.join(chemin_theme, fichier)
with open(chemin_fichier, 'r', encoding='utf-8') as f:
contexte_global += f"\n--- Extrait de {fichier} ---\n"
contexte_global += f.read() + "\n"
except Exception as e:
log_event("ERROR", "RAG", f"Erreur de lecture du contexte {thematique} : {e}")
return contexte_global
def rechercher_contexte_rag(prompt, categorie="general"):
"""
Fonction appelée par le chat_handler pour récupérer le contexte.
Pour l'instant, c'est un bouchon qui empêche le crash du serveur.
"""
try:
# À terme, nous ferons le lien intelligent ici avec extraire_contexte_rag()
# et une analyse sémantique. Pour l'instant on renvoie vide pour tester.
return ""
except Exception as e:
log_event("ERROR", "RAG_MANAGER", f"Erreur lors de la recherche RAG : {e}")
return ""
# On s'assure que les dossiers existent dès l'import du module
initialiser_arborescence_rag()