mirror of
https://github.com/Ladebeze66/llm_ticket3.git
synced 2025-12-13 10:46:51 +01:00
83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Script pour régénérer les versions texte des fichiers JSON dans le pipeline.
|
|
"""
|
|
|
|
import os
|
|
import json
|
|
import sys
|
|
from agents.utils.pipeline_logger import generer_version_texte
|
|
|
|
def regenerer_fichiers_txt(ticket_id):
|
|
"""
|
|
Régénère les fichiers TXT pour tous les fichiers JSON dans le pipeline du ticket.
|
|
|
|
Args:
|
|
ticket_id: ID du ticket (ex: T11143)
|
|
"""
|
|
# Déterminer le chemin du dossier pipeline
|
|
base_dir = "output"
|
|
ticket_dir = f"ticket_{ticket_id}"
|
|
ticket_path = os.path.join(base_dir, ticket_dir)
|
|
|
|
if not os.path.exists(ticket_path):
|
|
print(f"Répertoire du ticket non trouvé: {ticket_path}")
|
|
return
|
|
|
|
# Trouver la dernière extraction
|
|
extractions = []
|
|
for extract in os.listdir(ticket_path):
|
|
extraction_path = os.path.join(ticket_path, extract)
|
|
if os.path.isdir(extraction_path) and extract.startswith(ticket_id):
|
|
extractions.append(extraction_path)
|
|
|
|
if not extractions:
|
|
print(f"Aucune extraction trouvée pour le ticket {ticket_id}")
|
|
return
|
|
|
|
# Trier par date (plus récente en premier)
|
|
extractions.sort(key=lambda x: os.path.getmtime(x), reverse=True)
|
|
latest_extraction = extractions[0]
|
|
|
|
# Trouver le dossier pipeline
|
|
pipeline_dir = os.path.join(latest_extraction, f"{ticket_id}_rapports", "pipeline")
|
|
|
|
if not os.path.exists(pipeline_dir):
|
|
print(f"Dossier pipeline non trouvé: {pipeline_dir}")
|
|
return
|
|
|
|
print(f"Dossier pipeline trouvé: {pipeline_dir}")
|
|
|
|
# Traiter chaque fichier JSON
|
|
json_files = [f for f in os.listdir(pipeline_dir) if f.endswith('.json')]
|
|
print(f"Fichiers JSON trouvés: {len(json_files)}")
|
|
|
|
for json_file in json_files:
|
|
json_path = os.path.join(pipeline_dir, json_file)
|
|
print(f"Traitement du fichier: {json_file}")
|
|
|
|
try:
|
|
# Charger les données JSON
|
|
with open(json_path, 'r', encoding='utf-8') as f:
|
|
data = json.load(f)
|
|
|
|
# Déterminer le nom de l'étape (première partie du nom du fichier)
|
|
step_name = json_file.split('_')[0]
|
|
|
|
# Générer la version texte
|
|
generer_version_texte(data, ticket_id, step_name, json_path)
|
|
print(f"Fichier texte généré pour {json_file}")
|
|
except Exception as e:
|
|
print(f"Erreur lors du traitement de {json_file}: {str(e)}")
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) != 2:
|
|
print("Usage: python regenerer_txt.py <ticket_id>")
|
|
print("Exemple: python regenerer_txt.py T11143")
|
|
sys.exit(1)
|
|
|
|
ticket_id = sys.argv[1]
|
|
regenerer_fichiers_txt(ticket_id)
|
|
print("Terminé!") |