Spaces:
Sleeping
Sleeping
Create analysis_service.py
Browse files
src/services/analysis_service.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import logging
|
| 3 |
+
from typing import Dict, List, Any
|
| 4 |
+
from crewai import Agent, Task, Crew, Process
|
| 5 |
+
|
| 6 |
+
logger = logging.getLogger(__name__)
|
| 7 |
+
|
| 8 |
+
class AnalysisService:
|
| 9 |
+
def __init__(self, models: Dict[str, Any]):
|
| 10 |
+
self.models = models
|
| 11 |
+
self.analyzer = models.get("deep_learning_analyzer")
|
| 12 |
+
self.rag_handler = models.get("rag_handler")
|
| 13 |
+
self.llm = models.get("llm")
|
| 14 |
+
self._create_report_agent()
|
| 15 |
+
|
| 16 |
+
def _create_report_agent(self):
|
| 17 |
+
self.report_agent = Agent(
|
| 18 |
+
role='Rédacteur de Rapports Synthétiques',
|
| 19 |
+
goal='Générer un feedback pertinent à partir du déroulement de l\'entretien',
|
| 20 |
+
backstory=(
|
| 21 |
+
"Spécialisé dans le recrutement et les ressources humaines, capable d'évaluer les candidats "
|
| 22 |
+
"sur la communication et la pertinence des réponses en fonction des questions posées, rédige "
|
| 23 |
+
"en un rapport clair, un feedback détaillé sur le candidat."
|
| 24 |
+
),
|
| 25 |
+
allow_delegation=False,
|
| 26 |
+
verbose=False,
|
| 27 |
+
llm=self.llm
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
def run_analysis(self, conversation_history: List[Dict[str, Any]], job_description: str) -> Dict[str, Any]:
|
| 31 |
+
if not self.analyzer:
|
| 32 |
+
return {"error": "Analyzer non disponible"}
|
| 33 |
+
|
| 34 |
+
structured_analysis = self.analyzer.run_full_analysis(conversation_history, job_description)
|
| 35 |
+
|
| 36 |
+
rag_feedback = []
|
| 37 |
+
if self.rag_handler:
|
| 38 |
+
rag_feedback = self._get_contextual_feedback(structured_analysis)
|
| 39 |
+
|
| 40 |
+
report = self._generate_final_report(structured_analysis, rag_feedback)
|
| 41 |
+
|
| 42 |
+
return report
|
| 43 |
+
|
| 44 |
+
def _get_contextual_feedback(self, structured_analysis: Dict[str, Any]) -> List[str]:
|
| 45 |
+
rag_feedback = []
|
| 46 |
+
|
| 47 |
+
if structured_analysis.get("intent_analysis
|