QuentinL52 commited on
Commit
29856a8
·
verified ·
1 Parent(s): 57f1508

Update src/crew/crew_pool.py

Browse files
Files changed (1) hide show
  1. src/crew/crew_pool.py +106 -14
src/crew/crew_pool.py CHANGED
@@ -1,15 +1,25 @@
1
- import json
2
  from crewai import Crew, Process
3
- from .agents import report_generator_agent, skills_extractor_agent, experience_extractor_agent, project_extractor_agent, education_extractor_agent, ProfileBuilderAgent, informations_personnelle_agent, reconversion_detector_agent
4
- from .tasks import generate_report_task
5
- from typing import List
 
 
 
 
 
 
6
 
7
- def run_interview_analysis(conversation_history: list, job_description_text: str, analyzer_model, rag_handler) -> str:
 
8
  """
9
- Analyse l'intégralité de la conversation et génère un rapport de feedback.
10
- Cette fonction est conçue pour être appelée en arrière-plan.
 
11
  """
12
- structured_analysis = analyzer_model.run_full_analysis(conversation_history, job_description_text)
 
 
 
13
  rag_feedback = []
14
  if structured_analysis.get("intent_analysis"):
15
  for intent in structured_analysis["intent_analysis"]:
@@ -19,9 +29,8 @@ def run_interview_analysis(conversation_history: list, job_description_text: str
19
  if structured_analysis.get("sentiment_analysis"):
20
  for sentiment_group in structured_analysis["sentiment_analysis"]:
21
  for sentiment in sentiment_group:
22
- if sentiment['label'] == 'stress' and sentiment['score'] > 0.6:
23
  rag_feedback.extend(rag_handler.get_relevant_feedback("gestion du stress en entretien"))
24
-
25
  unique_feedback = list(set(rag_feedback))
26
  interview_crew = Crew(
27
  agents=[report_generator_agent],
@@ -35,11 +44,86 @@ def run_interview_analysis(conversation_history: list, job_description_text: str
35
  'structured_analysis_data': json.dumps(structured_analysis, indent=2),
36
  'rag_contextual_feedback': "\n".join(unique_feedback)
37
  })
38
-
39
  return final_report
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  def analyse_cv(cv_content: str) -> json:
42
- crew = Crew(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  agents=[
44
  informations_personnelle_agent,
45
  skills_extractor_agent,
@@ -47,7 +131,6 @@ def analyse_cv(cv_content: str) -> json:
47
  project_extractor_agent,
48
  education_extractor_agent,
49
  reconversion_detector_agent,
50
-
51
  ProfileBuilderAgent
52
  ],
53
  tasks=[
@@ -63,5 +146,14 @@ def analyse_cv(cv_content: str) -> json:
63
  verbose=False,
64
  telemetry=False
65
  )
66
- result = crew.kickoff(inputs={"cv_content": cv_content})
 
 
 
 
 
 
 
 
 
67
  return result
 
 
1
  from crewai import Crew, Process
2
+ from langchain_core.tools import tool
3
+ import json
4
+ from pydantic import BaseModel, Field
5
+ from typing import Dict, List, Any, Type
6
+ from .agents import report_generator_agent, cv_section_splitter_agent, skills_extractor_agent, experience_extractor_agent, project_extractor_agent, education_extractor_agent, ProfileBuilderAgent, informations_personnelle_agent, reconversion_detector_agent
7
+ from .tasks import generate_report_task, task_split_cv_sections, task_extract_skills, task_extract_experience, task_extract_projects, task_extract_education, task_build_profile, task_extract_informations, task_detect_reconversion
8
+ from src.deep_learning_analyzer import MultiModelInterviewAnalyzer
9
+ from src.rag_handler import RAGHandler
10
+ from langchain_core.tools import BaseTool
11
 
12
+ @tool
13
+ def interview_analyser(conversation_history: list, job_description_text: list) -> str:
14
  """
15
+ Appelle cet outil à la toute fin d'un entretien d'embauche pour analyser
16
+ l'intégralité de la conversation et générer un rapport de feedback.
17
+ Ne l'utilise PAS pour répondre à une question normale, mais seulement pour conclure et analyser l'entretien.
18
  """
19
+ analyzer = MultiModelInterviewAnalyzer()
20
+ structured_analysis = analyzer.run_full_analysis(conversation_history, job_description_text)
21
+
22
+ rag_handler = RAGHandler()
23
  rag_feedback = []
24
  if structured_analysis.get("intent_analysis"):
25
  for intent in structured_analysis["intent_analysis"]:
 
29
  if structured_analysis.get("sentiment_analysis"):
30
  for sentiment_group in structured_analysis["sentiment_analysis"]:
31
  for sentiment in sentiment_group:
32
+ if sentiment['label'] == 'stress' and sentiment['score'].item() > 0.6:
33
  rag_feedback.extend(rag_handler.get_relevant_feedback("gestion du stress en entretien"))
 
34
  unique_feedback = list(set(rag_feedback))
35
  interview_crew = Crew(
36
  agents=[report_generator_agent],
 
44
  'structured_analysis_data': json.dumps(structured_analysis, indent=2),
45
  'rag_contextual_feedback': "\n".join(unique_feedback)
46
  })
 
47
  return final_report
48
 
49
+ class CVSectionExtractor:
50
+ """
51
+ Extracteur de sections qui utilise les résultats du CVSectionSplitterAgent
52
+ pour distribuer le contenu approprié à chaque agent spécialisé.
53
+ """
54
+
55
+ def __init__(self, sections_data: dict):
56
+ self.sections = sections_data
57
+
58
+ def get_contact_section(self) -> str:
59
+ return self.sections.get("contact", "")
60
+
61
+ def get_experiences_section(self) -> str:
62
+ return self.sections.get("experiences", "")
63
+
64
+ def get_projects_section(self) -> str:
65
+ return self.sections.get("projects", "")
66
+
67
+ def get_education_section(self) -> str:
68
+ return self.sections.get("education", "")
69
+
70
+ def get_skills_section(self) -> str:
71
+ return self.sections.get("skills", "")
72
+
73
+ def get_skills_context(self) -> str:
74
+ """Combine les sections pertinentes pour l'extraction de compétences"""
75
+ return f"""
76
+ Section Expériences:
77
+ {self.get_experiences_section()}
78
+
79
+ Section Projets:
80
+ {self.get_projects_section()}
81
+
82
+ Section Compétences:
83
+ {self.get_skills_section()}
84
+ """
85
+
86
  def analyse_cv(cv_content: str) -> json:
87
+ section_splitting_crew = Crew(
88
+ agents=[cv_section_splitter_agent],
89
+ tasks=[task_split_cv_sections],
90
+ process=Process.sequential,
91
+ verbose=False,
92
+ telemetry=False
93
+ )
94
+
95
+ sections_result = section_splitting_crew.kickoff(inputs={"cv_content": cv_content})
96
+
97
+ try:
98
+ if hasattr(sections_result, 'raw'):
99
+ sections_json = sections_result.raw
100
+ else:
101
+ sections_json = str(sections_result)
102
+
103
+ sections_json_cleaned = sections_json.strip()
104
+ if '```' in sections_json:
105
+ if '```json' in sections_json:
106
+ sections_json_cleaned = sections_json.split('```json')[1].split('```')[0].strip()
107
+ else:
108
+ parts = sections_json.split('```')
109
+ if len(parts) >= 3:
110
+ sections_json_cleaned = parts[1].strip()
111
+
112
+ sections_data = json.loads(sections_json_cleaned)
113
+ extractor = CVSectionExtractor(sections_data)
114
+
115
+ except (json.JSONDecodeError, Exception) as e:
116
+ sections_data = {
117
+ "contact": cv_content[:500],
118
+ "experiences": cv_content,
119
+ "projects": cv_content,
120
+ "education": cv_content,
121
+ "skills": cv_content,
122
+ "other": ""
123
+ }
124
+ extractor = CVSectionExtractor(sections_data)
125
+
126
+ main_crew = Crew(
127
  agents=[
128
  informations_personnelle_agent,
129
  skills_extractor_agent,
 
131
  project_extractor_agent,
132
  education_extractor_agent,
133
  reconversion_detector_agent,
 
134
  ProfileBuilderAgent
135
  ],
136
  tasks=[
 
146
  verbose=False,
147
  telemetry=False
148
  )
149
+
150
+ main_inputs = {
151
+ "contact": extractor.get_contact_section(),
152
+ "experiences": extractor.get_experiences_section(),
153
+ "projects": extractor.get_projects_section(),
154
+ "education": extractor.get_education_section(),
155
+ "skills": extractor.get_skills_section()
156
+ }
157
+
158
+ result = main_crew.kickoff(inputs=main_inputs)
159
  return result