QuentinL52 commited on
Commit
d7a0bf7
·
verified ·
1 Parent(s): e730948

Update tools/analysis_tools.py

Browse files
Files changed (1) hide show
  1. tools/analysis_tools.py +22 -21
tools/analysis_tools.py CHANGED
@@ -1,32 +1,33 @@
1
  import logging
2
  from langchain_core.tools import tool
3
- from src.services.analysis_service import AnalysisService # Assurez-vous que le chemin d'importation est correct
4
-
 
 
5
  logging.basicConfig(level=logging.INFO)
6
  logger = logging.getLogger(__name__)
7
 
8
  @tool
9
- def trigger_interview_analysis(user_id: str, job_offer_id: str, conversation_history: list):
10
  """
11
- Call this tool to end the interview and start the final analysis.
12
- This should be the very last step of the conversation.
13
- Do not ask the user for confirmation before calling this tool.
14
  """
15
  try:
16
- logger.info(f"Tool 'trigger_interview_analysis' called for user_id: {user_id} and job_offer_id: {job_offer_id}.")
17
-
18
- # Initialisez et lancez votre service d'analyse exactement comme avant
19
- analysis_service = AnalysisService(
20
- user_id=user_id,
21
- job_offer_id=job_offer_id,
22
- conversation_history=conversation_history
23
  )
24
-
25
- # Lance la tâche de fond
26
- analysis_service.run_analysis_in_background()
27
-
28
- logger.info("Analysis task successfully started in the background.")
29
- return "Analysis has been successfully triggered. The user has been notified."
 
30
  except Exception as e:
31
- logger.error(f"Error calling analysis tool: {e}", exc_info=True)
32
- return "An error occurred while trying to start the analysis."
 
1
  import logging
2
  from langchain_core.tools import tool
3
+ from src.services.analysis_service import AnalysisService
4
+ import json
5
+ from typing import List, Dict
6
+ from src.models import load_all_models
7
  logging.basicConfig(level=logging.INFO)
8
  logger = logging.getLogger(__name__)
9
 
10
  @tool
11
+ def trigger_interview_analysis(user_id: str, job_offer_id: str, conversation_history: List[Dict], job_description: str):
12
  """
13
+ Appelle cet outil pour terminer l'entretien et lancer l'analyse finale.
14
+ Tu DOIS fournir le user_id, le job_offer_id, l'historique complet de la conversation (conversation_history), et la description complète du poste (job_description).
 
15
  """
16
  try:
17
+ logger.info(f"Outil 'trigger_interview_analysis' appelé pour user_id: {user_id}")
18
+ models = load_all_models()
19
+ analysis_service = AnalysisService(models=models)
20
+ feedback_data = analysis_service.run_analysis(
21
+ conversation_history=conversation_history,
22
+ job_description=job_description
 
23
  )
24
+ feedback_path = f"/tmp/feedbacks/{user_id}.json"
25
+ with open(feedback_path, "w", encoding="utf-8") as f:
26
+ json.dump({"status": "completed", "feedback_data": feedback_data}, f, ensure_ascii=False, indent=4)
27
+
28
+ logger.info(f"Analyse pour l'utilisateur {user_id} terminée et sauvegardée dans {feedback_path}.")
29
+ return "L'analyse a été déclenchée et terminée avec succès."
30
+
31
  except Exception as e:
32
+ logger.error(f"Erreur dans l'outil d'analyse : {e}", exc_info=True)
33
+ return "Une erreur est survenue lors du lancement de l'analyse."