Spaces:
Build error
Build error
File size: 2,511 Bytes
08f24b1 | 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 | import os
import sys
# Setup environment for Django-related imports
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
project_root = os.path.dirname(base_dir)
sys.path.insert(0, project_root)
sys.path.insert(0, base_dir)
sys.path.insert(0, os.path.join(base_dir, "api"))
sys.path.insert(0, os.path.join(base_dir, "pipeline"))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "animetix_project.settings")
import django # noqa: E402
django.setup()
from datetime import datetime # noqa: E402
from animetix.containers import get_container # noqa: E402
from core.domain.services.ragas_eval_service import RagasEvalService # noqa: E402
def run_mlops_eval():
"""
Lance une évaluation automatique de la qualité de l'IA sur un échantillon de requêtes.
Retourne un dictionnaire de stats pour le pipeline MLOps.
"""
print("Starting Automated RAG Evaluation...")
container = get_container()
judge = container.inference.inference_engine()
eval_service = RagasEvalService(judge_engine=judge)
# Échantillon de test (Golden Dataset simplifié)
test_queries = [
{
"q": "Qui est le créateur de One Piece ?",
"type": "Anime",
"ctx": "Eiichiro Oda",
},
{
"q": "Quelle est l'intrigue de Akira ?",
"type": "Movie",
"ctx": "Katsuhiro Otomo, néo-tokyo",
},
]
all_scores = []
for item in test_queries:
print(f"Evaluating query: '{item['q']}'")
# 1. Génération de la réponse
response = container.agentic.agentic_rag().plan_and_solve(
item["q"], item["type"]
)
# 2. Évaluation
scores = eval_service.evaluate_response(item["q"], item["ctx"], response)
all_scores.append({"query": item["q"], "scores": scores})
# Stats Finales
avg_faith = sum(s["scores"]["faithfulness"] for s in all_scores) / len(all_scores)
avg_relevancy = sum(s["scores"]["answer_relevancy"] for s in all_scores) / len(
all_scores
)
report = {
"avg_faithfulness": avg_faith,
"avg_answer_relevancy": avg_relevancy,
"timestamp": str(datetime.now()),
}
print("\n" + "=" * 30)
print("MLOPS REPORT")
print(f"Avg Faithfulness: {avg_faith:.2f}")
print(f"Avg Relevancy: {avg_relevancy:.2f}")
print("=" * 30)
return report
if __name__ == "__main__":
from datetime import datetime # noqa: E402
run_mlops_eval()
|