coffreobsidian/inbox/main_llama.py.md
2025-04-30 17:20:20 +02:00

238 lines
3.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#### Phase de test tri image
python main_llama.py <ticket_id> --skip-ticket-analysis --skip-image-analysis --skip-report
### 🧩 1. Préparation initiale (via `main_llama.py`)
#### 🔹 Entrées :
- ID du ticket (`T11143`)
- Arguments éventuels : `--skip-*`
#### 🔹 Appels internes :
- `OrchestratorLlama.executer(ticket_id, config)`
---
## 🧠 Pipeline complet orchestré
### ▶️ Étape 1 : **Chargement des données**
📁 Fichier : `ticket_data_loader.py`
- Charge :
- Données du ticket (`ticket.json`)
- Captures décran (`*.png`, `*.jpg`, `*.gif`)
- Transmet :
- `ticket` (dict)
- `images` (list[str]) ← chemins absolus
---
### ▶️ Étape 2 : **Dédoublonnage**
📁 Fichier : `image_dedup.py`
- Entrée : `images`
- Méthode : distance de Hamming
- Sortie : `images_uniques` (filtrées)
✅ À partir dici, on ne traite plus que les images utiles
---
### ▶️ Étape 3 : **OCR + Traduction**
📁 Fichiers : `ocr_utils.py` + `translate_utils.py`
#### Pour chaque image :
1. `ocr_utils.extraire_texte_fr(image_path)`
- → texte brut FR
2. `translate_utils.fr_to_en()`
- → traduction EN
3. `translate_utils.en_to_fr()` (optionnel)
- → re-traduction EN→FR
4. `translate_utils.sauvegarder_ocr_traduction()`
- 🔽 Sauvegarde :
- `ocr_traduction/<image>.json`
- `ocr_traduction.txt` (append)
---
## 🤖 CHAÎNE DAGENTS
---
### ▶️ Étape 4 : `AgentImageSorter`
📁 Fichier : `agent_image_sorter.py`
#### Reçoit :
- 1 image à la fois
- OCR_FR + EN injecté dans prompt
#### Fonction :
- Génère un prompt en anglais
- Analyse via `llama_vision.interroger_avec_image()`
#### Rend :
- JSON avec :
- `is_relevant: bool`
- `reason`
- `raw_response`
- `ocr_fr`, `ocr_en`
- 🔽 Sauvegarde :
- `tri_image_llama_*.json`
- `tri_image_llama_*.txt`
---
### ▶️ Étape 5 : `AgentImageAnalyser`
📁 Fichier : `agent_image_analyser.py`
#### Reçoit :
- Liste des **images pertinentes**
- (via `image_sorter`)
#### Fonction :
- Prompt visuel spécifique par image
- Analyse ce que montre limage
- Peut enrichir le contenu visuel à inclure dans le rapport
#### Rend :
- Pour chaque image :
- Résumé structuré
- Mots-clés, erreurs détectées, éléments visuels
- 🔽 Sauvegarde :
- `analyse_image_llama_*.json`
- `analyse_image_llama_*.txt`
---
### ▶️ Étape 6 : `AgentTicketAnalyser`
📁 Fichier : `agent_ticket_analyser.py`
#### Reçoit :
- Texte du ticket
- Analyse des images pertinentes
#### Fonction :
- Génère des Q&R contextuelles
- Résume le besoin utilisateur ou les problèmes détectés
#### Rend :
- Liste de Q/R
- Résumé en texte libre
- 🔽 Sauvegarde :
- `analyse_ticket_llama_*.json`
- `analyse_ticket_llama_*.txt`
---
### ▶️ Étape 7 : `AgentReportGenerator`
📁 Fichier : `agent_report_generator.py`
#### Reçoit :
- Analyse du ticket
- Analyse des images
#### Fonction :
- Génère un **rapport final** structuré
- Peut créer des tableaux CSV/Q&A
#### Rend :
- `rapport_final_llama_*.json`
- `rapport_final_llama_*.txt`
- CSV généré si demandé
---
### 🧾 Étapes transverses
Tous les agents :
- Appellent `sauvegarder_donnees()` de `pipeline_logger.py`
- Le chemin est déterminé par `ticket_id`, `timestamp`, `base_dir="reports"``output/ticket_TXXXX/TXXXX_YYYYMMDD_HHMMSS/TXXXX_rapports/pipeline/`
---
## ✅ Résumé des attentes par agent