Public Access
Mise à jour du RAG : Ajout d'une catégorie générale pour la sauvegarde systématique
Build and Push Docker Image / build-and-push (push) Successful in 38s
Build and Push Docker Image / build-and-push (push) Successful in 38s
This commit is contained in:
1 parent
9a454dd15e
commit
c82e12f49a
1 file changed
+25
-19
+25
-19
@@ -5,13 +5,15 @@ from modules.logger import log_event
|
|||||||
# Définition du chemin racine sécurisé sur ton RAID
|
# Définition du chemin racine sécurisé sur ton RAID
|
||||||
RAG_BASE_DIR = "/DATA/AppData/MULTI-IA-AETHAS38/RAG"
|
RAG_BASE_DIR = "/DATA/AppData/MULTI-IA-AETHAS38/RAG"
|
||||||
|
|
||||||
# Les thématiques générales pour organiser l'apprentissage
|
# Les thématiques pour organiser l'apprentissage (Ajout de Général et Éducation)
|
||||||
THEMATIQUES_RAG = [
|
THEMATIQUES_RAG = [
|
||||||
"Minecraft_KubeJS",
|
"Minecraft_KubeJS",
|
||||||
"Juridique_Loi_Francaise",
|
"Juridique_Loi_Francaise",
|
||||||
"Serveur_Debian",
|
"Serveur_Debian",
|
||||||
"Bureautique_Excel",
|
"Bureautique_Excel",
|
||||||
"Regles_Aethas38"
|
"Regles_Aethas38",
|
||||||
|
"Education_Nationale",
|
||||||
|
"Connaissances_Generales"
|
||||||
]
|
]
|
||||||
|
|
||||||
def initialiser_arborescence_rag():
|
def initialiser_arborescence_rag():
|
||||||
@@ -37,16 +39,18 @@ def extraire_contexte_rag(thematique):
|
|||||||
contexte_global = ""
|
contexte_global = ""
|
||||||
chemin_theme = os.path.join(RAG_BASE_DIR, thematique)
|
chemin_theme = os.path.join(RAG_BASE_DIR, thematique)
|
||||||
|
|
||||||
if not os.path.exists(chemin_theme):
|
# Si le thème est "aucun" ou introuvable, on tape dans les connaissances générales
|
||||||
return contexte_global
|
if thematique == "aucun" or not os.path.exists(chemin_theme):
|
||||||
|
chemin_theme = os.path.join(RAG_BASE_DIR, "Connaissances_Generales")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for fichier in os.listdir(chemin_theme):
|
if os.path.exists(chemin_theme):
|
||||||
if fichier.endswith(".txt") or fichier.endswith(".md"):
|
for fichier in os.listdir(chemin_theme):
|
||||||
chemin_fichier = os.path.join(chemin_theme, fichier)
|
if fichier.endswith(".txt") or fichier.endswith(".md"):
|
||||||
with open(chemin_fichier, 'r', encoding='utf-8') as f:
|
chemin_fichier = os.path.join(chemin_theme, fichier)
|
||||||
contexte_global += f"\n--- Extrait de {fichier} ---\n"
|
with open(chemin_fichier, 'r', encoding='utf-8') as f:
|
||||||
contexte_global += f.read() + "\n"
|
contexte_global += f"\n--- Extrait de {fichier} ---\n"
|
||||||
|
contexte_global += f.read() + "\n"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_event("ERROR", "RAG", f"Erreur de lecture du contexte {thematique} : {e}")
|
log_event("ERROR", "RAG", f"Erreur de lecture du contexte {thematique} : {e}")
|
||||||
|
|
||||||
@@ -57,7 +61,6 @@ def rechercher_contexte_rag(prompt, categorie="general"):
|
|||||||
Récupère le contenu des fichiers de la thématique pour alimenter l'IA.
|
Récupère le contenu des fichiers de la thématique pour alimenter l'IA.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# On fait appel à la fonction qui lit tous les .md/.txt du dossier thématique
|
|
||||||
return extraire_contexte_rag(categorie)
|
return extraire_contexte_rag(categorie)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_event("ERROR", "RAG_MANAGER", f"Erreur lors de la recherche RAG : {e}")
|
log_event("ERROR", "RAG_MANAGER", f"Erreur lors de la recherche RAG : {e}")
|
||||||
@@ -65,26 +68,29 @@ def rechercher_contexte_rag(prompt, categorie="general"):
|
|||||||
|
|
||||||
def auto_apprendre_rag(prompt, reponse, thematique_simplifiee):
|
def auto_apprendre_rag(prompt, reponse, thematique_simplifiee):
|
||||||
"""
|
"""
|
||||||
Sauvegarde automatiquement les réponses pertinentes pour enrichir la base de connaissances.
|
Sauvegarde systématiquement TOUTES les réponses pour enrichir la base de connaissances.
|
||||||
"""
|
"""
|
||||||
# Mapping entre le mot-clé deviné par Qwen et le vrai nom de ton dossier
|
# Mapping élargi
|
||||||
mapping = {
|
mapping = {
|
||||||
"minecraft": "Minecraft_KubeJS",
|
"minecraft": "Minecraft_KubeJS",
|
||||||
"droit": "Juridique_Loi_Francaise",
|
"droit": "Juridique_Loi_Francaise",
|
||||||
"serveur": "Serveur_Debian",
|
"serveur": "Serveur_Debian",
|
||||||
"excel": "Bureautique_Excel",
|
"excel": "Bureautique_Excel",
|
||||||
"regles": "Regles_Aethas38"
|
"regles": "Regles_Aethas38",
|
||||||
|
"education_nationale": "Education_Nationale"
|
||||||
}
|
}
|
||||||
|
|
||||||
theme_reel = mapping.get(thematique_simplifiee.lower())
|
# Si le thème n'est pas dans le mapping (ex: "aucun", "physique", "cuisine"),
|
||||||
if not theme_reel:
|
# on le force dans le dossier "Connaissances_Generales" au lieu de l'ignorer.
|
||||||
return # Si Qwen n'a pas détecté de thème précis (ex: "aucun"), on n'enregistre rien pour ne pas polluer.
|
theme_reel = mapping.get(thematique_simplifiee.lower(), "Connaissances_Generales")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
chemin_theme = os.path.join(RAG_BASE_DIR, theme_reel)
|
chemin_theme = os.path.join(RAG_BASE_DIR, theme_reel)
|
||||||
os.makedirs(chemin_theme, exist_ok=True)
|
os.makedirs(chemin_theme, exist_ok=True)
|
||||||
|
|
||||||
nom_fichier = f"apprentissage_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md"
|
# On raccourcit le prompt pour créer un nom de fichier propre
|
||||||
|
sujet_court = "".join(c for c in prompt[:15] if c.isalnum() or c == " ").strip().replace(" ", "_")
|
||||||
|
nom_fichier = f"rag_{sujet_court}_{datetime.now().strftime('%H%M%S')}.md"
|
||||||
chemin_fichier = os.path.join(chemin_theme, nom_fichier)
|
chemin_fichier = os.path.join(chemin_theme, nom_fichier)
|
||||||
|
|
||||||
contenu = f"## Question utilisateur\n{prompt}\n\n## Réponse de l'IA (Contexte validé)\n{reponse}\n"
|
contenu = f"## Question utilisateur\n{prompt}\n\n## Réponse de l'IA (Contexte validé)\n{reponse}\n"
|
||||||
@@ -92,7 +98,7 @@ def auto_apprendre_rag(prompt, reponse, thematique_simplifiee):
|
|||||||
with open(chemin_fichier, 'w', encoding='utf-8') as f:
|
with open(chemin_fichier, 'w', encoding='utf-8') as f:
|
||||||
f.write(contenu)
|
f.write(contenu)
|
||||||
|
|
||||||
log_event("INFO", "RAG_MANAGER", f"Nouvelle connaissance acquise et sauvegardée dans {theme_reel} ({nom_fichier}).")
|
log_event("INFO", "RAG_MANAGER", f"Connaissance sauvegardée dans {theme_reel} ({nom_fichier}).")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_event("ERROR", "RAG_MANAGER", f"Erreur lors de l'auto-apprentissage : {e}")
|
log_event("ERROR", "RAG_MANAGER", f"Erreur lors de l'auto-apprentissage : {e}")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user