-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rag.py
More file actions
executable file
Β·155 lines (123 loc) Β· 5.15 KB
/
test_rag.py
File metadata and controls
executable file
Β·155 lines (123 loc) Β· 5.15 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python3
"""
Test script to simulate a recruiter interest email and test RAG reply suggestions
"""
import requests
import json
import sys
from datetime import datetime
BASE_URL = "http://localhost:3001/api"
def print_header(text):
print("\n" + "="*80)
print(f" {text}")
print("="*80)
def print_json(data):
print(json.dumps(data, indent=2))
def test_rag_reply():
print_header("π§ͺ Testing RAG Reply Suggestions")
# Create a test email that simulates recruiter interest
test_email = {
"sender": "hr@techcorp.com",
"subject": "Technical Interview Invitation - Senior Full Stack Developer",
"body": """Hi Jason,
Thank you for applying to the Senior Full Stack Developer position at TechCorp.
Your resume has been shortlisted by our technical team. We're impressed with your experience in React, Node.js, and AI/ML technologies.
We would like to schedule a technical interview with you. When would be a good time for you to attend the technical round?
Looking forward to hearing from you.
Best regards,
Sarah Johnson
Tech Recruiter
TechCorp Inc.
""",
"date": datetime.now().isoformat(),
"category": "Interested",
"folder": "INBOX",
"account": "test@reachinbox.ai"
}
print("\nπ§ Test Email (Simulating Recruiter Interest):")
print(f"From: {test_email['sender']}")
print(f"Subject: {test_email['subject']}")
print(f"Body: {test_email['body'][:200]}...")
# Note: In production, this email would be synced via IMAP
# For testing, we'll use an existing email ID
print("\nβ οΈ Note: Using an existing email from the database for testing")
# Get any email ID for testing
response = requests.get(f"{BASE_URL}/emails?limit=1")
if response.status_code != 200:
print("β Failed to get test email")
return
emails = response.json()['emails']
if not emails:
print("β No emails found in database")
return
email_id = emails[0]['id']
print(f"\nπ Testing with email ID: {email_id}")
# Test RAG reply suggestion
print_header("π€ Generating AI Reply Suggestion (with RAG)")
response = requests.post(f"{BASE_URL}/emails/{email_id}/suggest-reply")
if response.status_code == 200:
result = response.json()
print("\nβ
Success!")
print(f"\nπ Suggested Reply:")
print("-" * 80)
print(result['suggestion'])
print("-" * 80)
print(f"\nπ Metadata:")
print(f" β’ Tone: {result['tone']}")
print(f" β’ Vector DB Used: {'β
Yes' if result.get('vectorDBUsed') else 'β No (fallback mode)'}")
print(f" β’ Context Items: {result.get('contextUsed', 0)}")
print(f" β’ Timestamp: {result['timestamp']}")
# Check if meeting link is included
if 'cal.com' in result['suggestion'] or 'https://' in result['suggestion']:
print("\nπ― Meeting link detected in reply! β
")
else:
print("\nβ οΈ No meeting link detected (may not be recruiter interest email)")
else:
print(f"\nβ Failed: {response.status_code}")
print(response.text)
# Test multiple variations
print_header("π Generating Reply Variations")
response = requests.post(f"{BASE_URL}/emails/{email_id}/suggest-reply/variations")
if response.status_code == 200:
result = response.json()
variations = result['variations']
print(f"\nβ
Generated {len(variations)} variations:")
for i, variation in enumerate(variations, 1):
print(f"\n{'β' * 80}")
print(f"Variation {i}:")
print(f"{'β' * 80}")
print(variation)
else:
print(f"\nβ Failed: {response.status_code}")
print(response.text)
def test_vector_db_status():
print_header("π Vector Database Status")
response = requests.get(f"{BASE_URL}/stats")
if response.status_code == 200:
stats = response.json()
print(f"\nβ
Backend is running")
print(f" β’ Total Emails: {stats['totalEmails']}")
print(f" β’ Categorized: {stats['categorizedEmails']}")
print(f" β’ Interested: {stats['interestedEmails']}")
else:
print("β Backend not responding")
if __name__ == "__main__":
try:
test_vector_db_status()
test_rag_reply()
print("\n" + "="*80)
print(" β
RAG Testing Complete!")
print("="*80)
print("\nπ‘ Next Steps:")
print(" 1. Add PINECONE_API_KEY to .env for full vector search")
print(" 2. Restart backend to initialize Pinecone")
print(" 3. Check logs for 'Training data stored in vector database'")
print(" 4. Test with real recruiter emails")
print("\nπ Documentation: See PINECONE_SETUP.md for setup instructions\n")
except requests.exceptions.ConnectionError:
print("\nβ Error: Backend is not running!")
print(" Start it with: cd backend && npm run dev")
sys.exit(1)
except Exception as e:
print(f"\nβ Error: {e}")
sys.exit(1)