Spaces:
Sleeping
Sleeping
Update src/services/interview_service.py
Browse files
src/services/interview_service.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
from typing import Dict, List, Any
|
| 3 |
from typing_extensions import TypedDict
|
|
@@ -10,7 +12,7 @@ from src.config import read_system_prompt, format_cv
|
|
| 10 |
class State(TypedDict):
|
| 11 |
messages: List[add_messages]
|
| 12 |
|
| 13 |
-
class
|
| 14 |
def __init__(self, models: Dict[str, Any]):
|
| 15 |
self.models = models
|
| 16 |
self.llm = self._get_llm()
|
|
@@ -26,12 +28,103 @@ class InterviewService:
|
|
| 26 |
)
|
| 27 |
|
| 28 |
def _load_prompt_template(self) -> str:
|
| 29 |
-
return read_system_prompt('prompts/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
def _chatbot_node(self, state: State) -> Dict[str, Any]:
|
| 32 |
messages = state["messages"]
|
| 33 |
formatted_cv_str = format_cv(self.cv_data)
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
system_prompt = self.system_prompt_template.format(
|
| 36 |
entreprise=self.job_offer.get('entreprise', 'notre entreprise'),
|
| 37 |
poste=self.job_offer.get('poste', 'ce poste'),
|
|
@@ -39,7 +132,9 @@ class InterviewService:
|
|
| 39 |
profil_recherche=self.job_offer.get('profil_recherche', 'Non spécifié'),
|
| 40 |
competences=self.job_offer.get('competences', 'Non spécifiées'),
|
| 41 |
pole=self.job_offer.get('pole', 'Non spécifié'),
|
| 42 |
-
cv=formatted_cv_str
|
|
|
|
|
|
|
| 43 |
)
|
| 44 |
|
| 45 |
llm_messages = [SystemMessage(content=system_prompt)] + messages
|
|
@@ -72,7 +167,6 @@ class InterviewService:
|
|
| 72 |
self.job_offer = job_offer
|
| 73 |
self.cv_data = cv_document['candidat']
|
| 74 |
self.conversation_history = conversation_history
|
| 75 |
-
|
| 76 |
initial_state = conversation_history + messages
|
| 77 |
result = self.graph.invoke({"messages": initial_state})
|
| 78 |
|
|
|
|
| 1 |
+
# Mise à jour pour src/services/interview_service.py
|
| 2 |
+
|
| 3 |
import os
|
| 4 |
from typing import Dict, List, Any
|
| 5 |
from typing_extensions import TypedDict
|
|
|
|
| 12 |
class State(TypedDict):
|
| 13 |
messages: List[add_messages]
|
| 14 |
|
| 15 |
+
class EnhancedInterviewService:
|
| 16 |
def __init__(self, models: Dict[str, Any]):
|
| 17 |
self.models = models
|
| 18 |
self.llm = self._get_llm()
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
def _load_prompt_template(self) -> str:
|
| 31 |
+
return read_system_prompt('prompts/enhanced_rag_prompt.txt')
|
| 32 |
+
|
| 33 |
+
def _analyze_candidate_profile(self, cv_data: Dict[str, Any]) -> Dict[str, str]:
|
| 34 |
+
"""Analyse le profil candidat pour générer des insights pour l'entretien"""
|
| 35 |
+
|
| 36 |
+
# Analyse des compétences avec niveaux
|
| 37 |
+
skills_analysis = self._generate_skills_analysis(cv_data)
|
| 38 |
+
|
| 39 |
+
# Analyse de reconversion
|
| 40 |
+
reconversion_analysis = self._generate_reconversion_analysis(cv_data)
|
| 41 |
+
|
| 42 |
+
return {
|
| 43 |
+
"skills_analysis": skills_analysis,
|
| 44 |
+
"reconversion_analysis": reconversion_analysis
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
def _generate_skills_analysis(self, cv_data: Dict[str, Any]) -> str:
|
| 48 |
+
"""Génère une analyse textuelle des compétences pour le prompt"""
|
| 49 |
+
|
| 50 |
+
competences = cv_data.get("analyse_competences", [])
|
| 51 |
+
|
| 52 |
+
if not competences:
|
| 53 |
+
return "Aucune analyse de compétences disponible."
|
| 54 |
+
|
| 55 |
+
# Grouper par niveau
|
| 56 |
+
levels_groups = {
|
| 57 |
+
"expert": [],
|
| 58 |
+
"avance": [],
|
| 59 |
+
"intermediaire": [],
|
| 60 |
+
"debutant": []
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
for comp in competences:
|
| 64 |
+
level = comp.get("level", "debutant")
|
| 65 |
+
skill = comp.get("skill", "")
|
| 66 |
+
if skill and level in levels_groups:
|
| 67 |
+
levels_groups[level].append(skill)
|
| 68 |
+
|
| 69 |
+
# Construire l'analyse textuelle
|
| 70 |
+
analysis_parts = []
|
| 71 |
+
|
| 72 |
+
if levels_groups["expert"]:
|
| 73 |
+
analysis_parts.append(f"COMPÉTENCES EXPERTES : {', '.join(levels_groups['expert'])}")
|
| 74 |
+
analysis_parts.append("→ Pose des questions techniques approfondies, demande des exemples d'innovation et de leadership technique")
|
| 75 |
+
|
| 76 |
+
if levels_groups["avance"]:
|
| 77 |
+
analysis_parts.append(f"COMPÉTENCES AVANCÉES : {', '.join(levels_groups['avance'])}")
|
| 78 |
+
analysis_parts.append("→ Explore les défis complexes, l'autonomie et la résolution de problèmes")
|
| 79 |
+
|
| 80 |
+
if levels_groups["intermediaire"]:
|
| 81 |
+
analysis_parts.append(f"COMPÉTENCES INTERMÉDIAIRES : {', '.join(levels_groups['intermediaire'])}")
|
| 82 |
+
analysis_parts.append("→ Vérifie la compréhension pratique avec des exemples concrets")
|
| 83 |
+
|
| 84 |
+
if levels_groups["debutant"]:
|
| 85 |
+
analysis_parts.append(f"COMPÉTENCES DÉBUTANTES : {', '.join(levels_groups['debutant'])}")
|
| 86 |
+
analysis_parts.append("→ Teste les connaissances de base et évalue la motivation à apprendre")
|
| 87 |
+
|
| 88 |
+
return "\n".join(analysis_parts) if analysis_parts else "Aucune compétence analysée."
|
| 89 |
+
|
| 90 |
+
def _generate_reconversion_analysis(self, cv_data: Dict[str, Any]) -> str:
|
| 91 |
+
"""Génère une analyse de reconversion pour le prompt"""
|
| 92 |
+
|
| 93 |
+
reconversion_data = cv_data.get("reconversion", {})
|
| 94 |
+
|
| 95 |
+
if not reconversion_data:
|
| 96 |
+
return "Aucune analyse de reconversion disponible."
|
| 97 |
+
|
| 98 |
+
is_reconversion = reconversion_data.get("is_reconversion", False)
|
| 99 |
+
analysis = reconversion_data.get("analysis", "")
|
| 100 |
+
|
| 101 |
+
if not is_reconversion:
|
| 102 |
+
return "PROFIL CLASSIQUE : Parcours cohérent dans le domaine. Focus sur l'évolution et les projets marquants."
|
| 103 |
+
|
| 104 |
+
reconversion_guidance = [
|
| 105 |
+
"CANDIDAT EN RECONVERSION DÉTECTÉE :",
|
| 106 |
+
f"Analyse : {analysis}",
|
| 107 |
+
"",
|
| 108 |
+
"POINTS À EXPLORER OBLIGATOIREMENT :",
|
| 109 |
+
"1. Motivations du changement de carrière",
|
| 110 |
+
"2. Compétences transférables de l'expérience passée",
|
| 111 |
+
"3. Démarches d'apprentissage et de formation",
|
| 112 |
+
"4. Engagement et projets dans la nouvelle voie",
|
| 113 |
+
"5. Vision à long terme dans ce nouveau domaine",
|
| 114 |
+
"",
|
| 115 |
+
"APPROCHE : Valorise l'expérience passée, rassure sur la pertinence de la reconversion"
|
| 116 |
+
]
|
| 117 |
+
|
| 118 |
+
return "\n".join(reconversion_guidance)
|
| 119 |
|
| 120 |
def _chatbot_node(self, state: State) -> Dict[str, Any]:
|
| 121 |
messages = state["messages"]
|
| 122 |
formatted_cv_str = format_cv(self.cv_data)
|
| 123 |
+
|
| 124 |
+
# Générer les analyses du profil candidat
|
| 125 |
+
profile_analysis = self._analyze_candidate_profile(self.cv_data)
|
| 126 |
+
|
| 127 |
+
# Formatage du prompt système enrichi
|
| 128 |
system_prompt = self.system_prompt_template.format(
|
| 129 |
entreprise=self.job_offer.get('entreprise', 'notre entreprise'),
|
| 130 |
poste=self.job_offer.get('poste', 'ce poste'),
|
|
|
|
| 132 |
profil_recherche=self.job_offer.get('profil_recherche', 'Non spécifié'),
|
| 133 |
competences=self.job_offer.get('competences', 'Non spécifiées'),
|
| 134 |
pole=self.job_offer.get('pole', 'Non spécifié'),
|
| 135 |
+
cv=formatted_cv_str,
|
| 136 |
+
skills_analysis=profile_analysis["skills_analysis"],
|
| 137 |
+
reconversion_analysis=profile_analysis["reconversion_analysis"]
|
| 138 |
)
|
| 139 |
|
| 140 |
llm_messages = [SystemMessage(content=system_prompt)] + messages
|
|
|
|
| 167 |
self.job_offer = job_offer
|
| 168 |
self.cv_data = cv_document['candidat']
|
| 169 |
self.conversation_history = conversation_history
|
|
|
|
| 170 |
initial_state = conversation_history + messages
|
| 171 |
result = self.graph.invoke({"messages": initial_state})
|
| 172 |
|