QuentinL52 commited on
Commit
3d12257
·
verified ·
1 Parent(s): 36b7ac5

Update src/agents/analysis_agent.py

Browse files
Files changed (1) hide show
  1. src/agents/analysis_agent.py +30 -28
src/agents/analysis_agent.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import logging
2
  from typing import Dict, Any
3
  from src.config import chat_openai
@@ -9,41 +11,41 @@ class AnalysisAgent:
9
  self.llm = llm or chat_openai()
10
 
11
  def analyze_candidate(self, cv_data: Dict[str, Any]) -> Dict[str, Any]:
12
- """Produit une analyse enrichie du profil à partir des données structurées du CV"""
13
  if not cv_data or "candidat" not in cv_data:
14
  return {}
15
 
16
  candidat = cv_data["candidat"]
17
  prompt = f"""
18
- Tu es un expert en recrutement. Analyse ce profil candidat en te basant sur les données suivantes :
19
- {candidat}
20
-
21
- Fournis une analyse complète avec ces sections :
22
- 1. Évaluation des compétences techniques (niveau de maîtrise par domaine)
23
- 2. Analyse des projets (objectifs, technologies, compétences démontrées)
24
- 3. Évaluation des soft skills
25
- 4. Analyse de l’expérience professionnelle (niveau, cohérence, domaines)
26
- 5. Détection d’une reconversion (si oui, précise depuis quel domaine et pourquoi)
27
- 6. Profil global (forces, axes d’amélioration, positionnement)
28
- 7. Recommandations de postes et de progression de carrière
29
- 8. Suggestions d’amélioration du CV
30
-
31
- Donne ta réponse au format JSON clair, par exemple :
32
- {{
33
- "competence_analysis": [...],
34
- "project_analysis": [...],
35
- "soft_skills_analysis": "...",
36
- "experience_evaluation": "...",
37
- "reconversion": {{ "is_reconversion": true, "details": "..." }},
38
- "global_profile": "...",
39
- "career_recommendations": [...],
40
- "cv_improvement_suggestions": [...]
41
- }}
42
  """
43
 
44
  response = self.llm.invoke(prompt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  try:
46
- return response.to_dict() if hasattr(response, "to_dict") else response
47
- except Exception as e:
48
- logger.error(f"Erreur d'analyse enrichie : {e}")
 
 
 
 
 
 
49
  return {}
 
1
+ import json
2
+ import re
3
  import logging
4
  from typing import Dict, Any
5
  from src.config import chat_openai
 
11
  self.llm = llm or chat_openai()
12
 
13
  def analyze_candidate(self, cv_data: Dict[str, Any]) -> Dict[str, Any]:
 
14
  if not cv_data or "candidat" not in cv_data:
15
  return {}
16
 
17
  candidat = cv_data["candidat"]
18
  prompt = f"""
19
+ Tu es un expert en recrutement. Analyse ce profil candidat...
20
+ [PROMPT ICI — inchangé]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  """
22
 
23
  response = self.llm.invoke(prompt)
24
+ raw_content = response.get("content") if isinstance(response, dict) else getattr(response, "content", None)
25
+ if not raw_content:
26
+ logger.warning("Aucun contenu d'analyse trouvé dans la réponse du modèle.")
27
+ return {}
28
+
29
+ cleaned_json = self._extract_json_from_string(raw_content)
30
+ if not cleaned_json:
31
+ logger.warning("Impossible d'extraire le JSON propre du contenu.")
32
+ return {}
33
+
34
+ return cleaned_json
35
+
36
+ def _extract_json_from_string(self, text: str) -> Dict[str, Any]:
37
+ """
38
+ Extrait proprement un bloc JSON d'une réponse texte du modèle.
39
+ Supprime les balises ```json et convertit en dict Python.
40
+ """
41
  try:
42
+ json_match = re.search(r'\{.*\}', text, re.DOTALL)
43
+ if not json_match:
44
+ return {}
45
+
46
+ json_str = json_match.group(0).strip()
47
+ return json.loads(json_str)
48
+
49
+ except json.JSONDecodeError as e:
50
+ logger.error(f"Erreur de parsing du JSON de l'analyse : {e}")
51
  return {}