RAG local de Mind sur le serveur Minecraft (fiches + BM25 + pont modifié)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
e9507333f6
révision
f684023188
23 fichiers modifiés
+574
Aucun fichier ne correspond à votre recherche
@@ -0,0 +1,64 @@
|
||||
"""Tests hors-jeu du RAG : python3 -m unittest test_rag_minecraft (depuis le dossier connaissances/)"""
|
||||
import re
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import rag_minecraft as rag
|
||||
|
||||
ICI = Path(__file__).parent
|
||||
BASE = rag.Base.charger(ICI / "fiches")
|
||||
|
||||
# (question, fiche attendue en tête)
|
||||
ATTENDUS = [
|
||||
("comment je me téléporte chez un ami", "tpa"),
|
||||
("combien de homes je peux avoir ?", "homes"),
|
||||
("comment protéger ma maison", "claims"),
|
||||
("c'est quoi la touche vocal", "vocal"),
|
||||
("comment je donne accès à mon claim à un pote, /friend", "amis"),
|
||||
("j'ai perdu mes affaires en mourant", "mort-gravestone"),
|
||||
("comment revenir au spawn", "spawn"),
|
||||
("c'est quoi /rtp", "rtp"),
|
||||
("quelles sont les règles du serveur ?", "regles"),
|
||||
("quels mods y a-t-il ?", "mods-liste"),
|
||||
("est-ce qu'il y a un /back ?", "inexistant"),
|
||||
]
|
||||
HORS_SUJET = ["quelle est la capitale de la France ?", "raconte-moi une blague",
|
||||
"comment fabriquer une pioche en diamant", "combien font 2 + 2"]
|
||||
|
||||
|
||||
class TestRag(unittest.TestCase):
|
||||
def test_attendus(self):
|
||||
for q, attendu in ATTENDUS:
|
||||
with self.subTest(q=q):
|
||||
r = BASE.rechercher(q)
|
||||
self.assertTrue(r, f"aucune fiche pour {q!r}")
|
||||
self.assertEqual(r[0].id, attendu, [f.id for f in r])
|
||||
self.assertLessEqual(len(r), 4)
|
||||
|
||||
def test_hors_sujet(self):
|
||||
for q in HORS_SUJET:
|
||||
with self.subTest(q=q):
|
||||
self.assertEqual(BASE.rechercher(q), [])
|
||||
|
||||
def test_limites_reelles(self):
|
||||
homes = next(f for f in BASE.fiches if f.id == "homes").corps
|
||||
claims = next(f for f in BASE.fiches if f.id == "claims").corps
|
||||
self.assertIn("3 au maximum", homes)
|
||||
self.assertIn("25 au maximum", claims)
|
||||
|
||||
def test_aucun_secret(self):
|
||||
for f in BASE.fiches:
|
||||
texte = f.titre + " " + f.corps + " " + " ".join(f.mots_cles)
|
||||
self.assertIsNone(re.search(r"\b\d{1,3}(\.\d{1,3}){3}\b", texte), f.id) # IPv4
|
||||
self.assertIsNone(re.search(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}", texte), f.id) # UUID
|
||||
self.assertIsNone(re.search(r"(?i)mot de passe|password|token|secret", texte.replace(
|
||||
"ni de mot de passe", "")), f.id)
|
||||
|
||||
def test_brouillon_marque(self):
|
||||
regles = next(f for f in BASE.fiches if f.id == "regles")
|
||||
self.assertIn("BROUILLON", rag.bloc_contexte([regles]))
|
||||
self.assertIn("pas encore validées", regles.corps)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur