File size: 2,527 Bytes
5db4cdd
 
d7a0bf7
 
 
 
5db4cdd
 
 
53bdc35
 
 
 
 
 
 
 
 
5db4cdd
53bdc35
 
5db4cdd
 
5471363
 
 
 
d7a0bf7
 
 
 
 
5db4cdd
d7a0bf7
 
 
 
 
 
5db4cdd
d7a0bf7
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import logging
from langchain_core.tools import tool
from src.services.analysis_service import AnalysisService 
import json
from typing import List, Dict
from src.models import load_all_models
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

class InterviewAnalysisArgs(BaseModel):
    """Arguments for the trigger_interview_analysis tool."""
    user_id: str = Field(..., description="The unique identifier for the user, provided in the system prompt.")
    job_offer_id: str = Field(..., description="The unique identifier for the job offer, provided in the system prompt.")
    job_description: str = Field(..., description="The full JSON string of the job offer description.")
    conversation_history: List[Dict[str, Any]] = Field(..., description="The complete conversation history between the user and the agent.")

@tool("trigger_interview_analysis", args_schema=InterviewAnalysisArgs)
def trigger_interview_analysis(user_id: str, job_offer_id: str, job_description: str, conversation_history: List[Dict[str, Any]]):
    """
    Call this tool to end the interview and launch the final analysis.
    You MUST provide all arguments: user_id, job_offer_id, job_description, and the complete conversation_history.
    """
    try:
        logger.info(f"Outil 'trigger_interview_analysis' appelé pour user_id: {user_id} et job_offer_id: {job_offer_id}")
        if '@' in user_id or ' ' in job_offer_id:
             logger.error(f"Appel de l'outil avec des données invalides. User ID: {user_id}, Job Offer ID: {job_offer_id}")
             return "Erreur: Appel de l'outil avec des paramètres invalides. L'analyse n'a pas pu être lancée."
        models = load_all_models()
        analysis_service = AnalysisService(models=models)
        feedback_data = analysis_service.run_analysis(
            conversation_history=conversation_history,
            job_description=job_description
        )
        feedback_path = f"/tmp/feedbacks/{user_id}.json"
        with open(feedback_path, "w", encoding="utf-8") as f:
            json.dump({"status": "completed", "feedback_data": feedback_data}, f, ensure_ascii=False, indent=4)
        logger.info(f"Analyse pour l'utilisateur {user_id} terminée et sauvegardée dans {feedback_path}.")
        return "L'analyse a été déclenchée et terminée avec succès."

    except Exception as e:
        logger.error(f"Erreur dans l'outil d'analyse : {e}", exc_info=True)
        return "Une erreur est survenue lors du lancement de l'analyse."