mirror of
https://github.com/Ladebeze66/llm_ticket3.git
synced 2025-12-13 10:46:51 +01:00
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import os
|
|
import pandas as pd
|
|
import logging
|
|
from typing import Optional
|
|
from ..base_agent import BaseAgent
|
|
|
|
logger = logging.getLogger("AgentRagIndexer")
|
|
|
|
class AgentRagIndexer(BaseAgent):
|
|
def __init__(self, ragflow, llm):
|
|
super().__init__("AgentRagIndexer", llm)
|
|
self.ragflow = ragflow
|
|
|
|
def executer(self, chemin_csv: str, ticket_id: Optional[str] = None) -> int:
|
|
if not os.path.exists(chemin_csv):
|
|
logger.error(f"Fichier CSV introuvable : {chemin_csv}")
|
|
return 0
|
|
|
|
df = pd.read_csv(chemin_csv)
|
|
lignes_indexees = 0
|
|
|
|
for index, row in df.iterrows():
|
|
question = str(row.get("question", "")).strip()
|
|
reponse = str(row.get("reponse", "")).strip()
|
|
|
|
if not question or not reponse:
|
|
continue
|
|
|
|
contenu = f"Question : {question}\nRéponse : {reponse}"
|
|
metadata = {
|
|
"ticket_id": ticket_id or "UNKNOWN",
|
|
"ligne": index + 1
|
|
}
|
|
|
|
try:
|
|
self.ragflow.indexer(contenu, metadata)
|
|
lignes_indexees += 1
|
|
except Exception as e:
|
|
logger.warning(f"Erreur lors de l'indexation ligne {index}: {e}")
|
|
|
|
logger.info(f"{lignes_indexees} lignes indexées depuis {chemin_csv}")
|
|
return lignes_indexees
|