mirror of
https://github.com/Ladebeze66/llm_ticket3.git
synced 2025-12-13 10:46:51 +01:00
15:02orches
This commit is contained in:
parent
af5847eb0d
commit
b07a6512ea
20
.gitignore
vendored
Normal file
20
.gitignore
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
# Environnement virtuel
|
||||
venv/
|
||||
env/
|
||||
ENV/
|
||||
|
||||
# Fichiers compilés Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# Distribution / packaging
|
||||
dist/
|
||||
build/
|
||||
*.egg-info/
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Local configuration
|
||||
.env
|
||||
@ -1,4 +1,5 @@
|
||||
from .base_agent import BaseAgent
|
||||
from typing import Any
|
||||
|
||||
class AgentImageAnalyser(BaseAgent):
|
||||
"""
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
from .base_agent import BaseAgent
|
||||
from typing import Any
|
||||
|
||||
class AgentImageSorter(BaseAgent):
|
||||
"""
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from .base_agent import BaseAgent
|
||||
from typing import Dict
|
||||
from typing import Dict, Any
|
||||
|
||||
class AgentJsonAnalyser(BaseAgent):
|
||||
"""
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import json
|
||||
from .base_agent import BaseAgent
|
||||
from datetime import datetime
|
||||
from typing import Dict
|
||||
from typing import Dict, Any
|
||||
|
||||
class AgentReportGenerator(BaseAgent):
|
||||
"""
|
||||
|
||||
@ -18,5 +18,5 @@ class BaseAgent(ABC):
|
||||
})
|
||||
|
||||
@abstractmethod
|
||||
def _executer(self, *args, **kwargs) -> Any:
|
||||
def executer(self, *args, **kwargs) -> Any:
|
||||
pass
|
||||
|
||||
@ -65,6 +65,7 @@ class BaseLLM(abc.ABC):
|
||||
if response.status_code in [200, 201]:
|
||||
self.reponseErreur = False
|
||||
reponse = self._traiter_reponse(response)
|
||||
return reponse
|
||||
else:
|
||||
self.reponseErreur = True
|
||||
return response.text
|
||||
|
||||
@ -1,14 +1,75 @@
|
||||
import os
|
||||
import json
|
||||
from typing import List, Dict
|
||||
from agents.agent_json_analyser import AgentJsonAnalyser
|
||||
from agents.agent_image_sorter import AgentImageSorter
|
||||
from agents.agent_image_analyser import AgentImageAnalyser
|
||||
from agents.agent_report_generator import AgentReportGenerator
|
||||
from llm_classes.MistralMesh import MistralMesh
|
||||
|
||||
|
||||
from typing import List, Dict, Any, Optional
|
||||
from agents.base_agent import BaseAgent
|
||||
|
||||
class Orchestrator:
|
||||
"""
|
||||
"""
|
||||
def __init__(self,
|
||||
output_dir: str = "output/",
|
||||
json_agent: Optional[BaseAgent] = None,
|
||||
image_sorter: Optional[BaseAgent] = None,
|
||||
image_analyser: Optional[BaseAgent] = None,
|
||||
report_generator: Optional[BaseAgent] = None):
|
||||
|
||||
self.output_dir = output_dir
|
||||
|
||||
# Assignation directe des agents (qui peuvent être injectés lors des tests)
|
||||
self.json_agent = json_agent
|
||||
self.image_sorter = image_sorter
|
||||
self.image_analyser = image_analyser
|
||||
self.report_generator = report_generator
|
||||
|
||||
def detecter_tickets(self) -> List[str]:
|
||||
tickets = []
|
||||
for ticket_dir in os.listdir(self.output_dir):
|
||||
ticket_path = os.path.join(self.output_dir, ticket_dir)
|
||||
if os.path.isdir(ticket_path) and ticket_dir.startswith("ticket_"):
|
||||
tickets.append(ticket_path)
|
||||
return tickets
|
||||
|
||||
def traiter_ticket(self, ticket_path: str):
|
||||
for extraction in os.listdir(ticket_path):
|
||||
extraction_path = os.path.join(ticket_path, extraction)
|
||||
if os.path.isdir(extraction_path):
|
||||
attachments_dir = os.path.join(extraction_path, "attachments")
|
||||
rapport_json_path = os.path.join(extraction_path, f"{extraction.split('_')[0]}_rapport.json")
|
||||
rapports_dir = os.path.join(extraction_path, f"{extraction.split('_')[0]}_rapports")
|
||||
|
||||
os.makedirs(rapports_dir, exist_ok=True)
|
||||
|
||||
if os.path.exists(rapport_json_path):
|
||||
with open(rapport_json_path, 'r', encoding='utf-8') as file:
|
||||
ticket_json = json.load(file)
|
||||
|
||||
json_analysis = self.json_agent.executer(ticket_json) if self.json_agent else None
|
||||
|
||||
relevant_images = []
|
||||
if os.path.exists(attachments_dir):
|
||||
for attachment in os.listdir(attachments_dir):
|
||||
attachment_path = os.path.join(attachments_dir, attachment)
|
||||
if attachment.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
|
||||
is_relevant = self.image_sorter.executer(attachment_path) if self.image_sorter else False
|
||||
if is_relevant:
|
||||
relevant_images.append(attachment_path)
|
||||
|
||||
image_analysis_results = {}
|
||||
for image_path in relevant_images:
|
||||
if self.image_analyser and json_analysis:
|
||||
image_analysis_results[image_path] = self.image_analyser.executer(
|
||||
image_path,
|
||||
contexte=json_analysis
|
||||
)
|
||||
|
||||
rapport_data = {
|
||||
"analyse_json": json_analysis,
|
||||
"analyse_images": image_analysis_results
|
||||
}
|
||||
if self.report_generator:
|
||||
self.report_generator.executer(rapport_data, os.path.join(rapports_dir, extraction.split('_')[0]))
|
||||
|
||||
print(f"Traitement du ticket {ticket_path} terminé.\n")
|
||||
|
||||
def executer(self):
|
||||
tickets = self.detecter_tickets()
|
||||
for ticket in tickets:
|
||||
self.traiter_ticket(ticket)
|
||||
|
||||
37
test_orchestrator.py
Normal file
37
test_orchestrator.py
Normal file
@ -0,0 +1,37 @@
|
||||
from orchestrator import Orchestrator
|
||||
from agents.agent_json_analyser import AgentJsonAnalyser
|
||||
from agents.agent_image_sorter import AgentImageSorter
|
||||
from agents.agent_image_analyser import AgentImageAnalyser
|
||||
from agents.agent_report_generator import AgentReportGenerator
|
||||
|
||||
from llm_classes.mistral_large import MistralLarge
|
||||
from llm_classes.pixtral_12b import Pixtral12b
|
||||
from llm_classes.ollama import Ollama
|
||||
|
||||
def test_orchestrator():
|
||||
# Initialisation des LLM
|
||||
json_llm = MistralLarge()
|
||||
image_sorter_llm = Pixtral12b()
|
||||
image_analyser_llm = Ollama()
|
||||
report_generator_llm = MistralLarge()
|
||||
|
||||
# Création des agents
|
||||
json_agent = AgentJsonAnalyser(json_llm)
|
||||
image_sorter = AgentImageSorter(image_sorter_llm)
|
||||
image_analyser = AgentImageAnalyser(image_analyser_llm)
|
||||
report_generator = AgentReportGenerator(report_generator_llm)
|
||||
|
||||
# Initialisation de l'orchestrateur avec les agents
|
||||
orchestrator = Orchestrator(
|
||||
output_dir="output/",
|
||||
json_agent=json_agent,
|
||||
image_sorter=image_sorter,
|
||||
image_analyser=image_analyser,
|
||||
report_generator=report_generator
|
||||
)
|
||||
|
||||
# Exécution complète de l'orchestrateur
|
||||
orchestrator.executer()
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_orchestrator()
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user