File size: 3,751 Bytes
363cda9
 
 
 
 
 
 
 
 
 
 
 
3370983
 
 
363cda9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import sys
import os
from sqlalchemy import select, desc
from uuid import uuid4
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Add src to path
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))

from src.backend.database.candidates.models import Candidate, CVScreeningResult, Base
from src.backend.database.candidates.client import SessionLocal, engine
from src.backend.agents.voice_screening.utils.questions import get_screening_questions

def verify_integration():
    print("Verifying integration...")
    
    # Create tables if not exist (for test)
    Base.metadata.create_all(bind=engine)
    
    # Create a dummy candidate
    candidate_id = uuid4()
    candidate = Candidate(
        id=candidate_id,
        full_name="Test Candidate",
        email=f"test_{candidate_id}@example.com",
        status="applied"
    )
    
    # Create a dummy CV result
    cv_result = CVScreeningResult(
        candidate_id=candidate_id,
        job_title="Senior Python Engineer",
        skills_match_score=0.9,
        experience_match_score=0.8,
        education_match_score=0.9,
        overall_fit_score=0.85,
        llm_feedback="Good fit",
        reasoning_trace={}
    )
    
    try:
        with SessionLocal() as db:
            db.add(candidate)
            db.add(cv_result)
            db.commit()
            print(f"Created test candidate: {candidate_id}")
            
            # Simulate the logic in proxy.py
            fetched_candidate = db.execute(
                select(Candidate).where(Candidate.id == candidate_id)
            ).scalar_one_or_none()
            
            if fetched_candidate:
                print(f"Fetched candidate: {fetched_candidate.full_name}")
                
                fetched_cv_result = db.execute(
                    select(CVScreeningResult)
                    .where(CVScreeningResult.candidate_id == candidate_id)
                    .order_by(desc(CVScreeningResult.timestamp))
                    .limit(1)
                ).scalar_one_or_none()
                
                job_title = fetched_cv_result.job_title if fetched_cv_result else "the position"
                print(f"Fetched job title: {job_title}")
                
                questions = get_screening_questions(job_title)
                print(f"Generated {len(questions)} questions")
                
                instructions = (
                    f"You are a friendly HR assistant conducting a phone screening interview with {fetched_candidate.full_name} "
                    f"for the position of {job_title}. "
                    f"Greet the candidate warmly by name. "
                    f"Your goal is to ask the following questions to assess their fit:\n\n"
                )
                
                for i, q in enumerate(questions, 1):
                    instructions += f"{i}. {q}\n"
                    
                instructions += (
                    "\nAsk one question at a time. Wait for their response before moving to the next. "
                    "Be professional but conversational. If they ask clarifying questions, answer them briefly."
                )
                
                print("\nGenerated Instructions:")
                print("-" * 40)
                print(instructions)
                print("-" * 40)
                
                # Clean up
                db.delete(cv_result)
                db.delete(candidate)
                db.commit()
                print("Cleaned up test data")
                
    except Exception as e:
        print(f"Verification failed: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    verify_integration()