-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
194 lines (156 loc) · 7.24 KB
/
test_api.py
File metadata and controls
194 lines (156 loc) · 7.24 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
"""
API Test Script for LinkedIn Sourcing Agent
Demonstrates all API endpoints and functionality
"""
import json
import requests
import time
API_BASE = "http://localhost:8000"
def test_basic_health():
"""Test basic API health"""
print("🔍 Testing API Health...")
try:
response = requests.get(f"{API_BASE}/")
print(f"✅ Root endpoint: {response.status_code}")
print(f" Response: {response.json()}")
health_response = requests.get(f"{API_BASE}/health")
print(f"✅ Health endpoint: {health_response.status_code}")
health_data = health_response.json()
print(f" Status: {health_data['status']}")
print(f" Agent initialized: {health_data['agent_initialized']}")
print(f" Outreach generator: {health_data['outreach_generator_initialized']}")
return True
except Exception as e:
print(f"❌ Health check failed: {e}")
return False
def test_demo_endpoint():
"""Test the demo endpoint with sample data"""
print("\n🚀 Testing Demo Endpoint...")
try:
response = requests.get(f"{API_BASE}/demo")
if response.status_code == 200:
data = response.json()
print(f"✅ Demo endpoint: {response.status_code}")
print(f" Job ID: {data['job_id']}")
print(f" Candidates found: {data['candidates_found']}")
print(f" Processing time: {data['processing_time_seconds']}s")
print(f" Top candidates: {len(data['top_candidates'])}")
# Show first candidate details
if data['top_candidates']:
first_candidate = data['top_candidates'][0]
print(f"\n📋 Sample Candidate:")
print(f" Name: {first_candidate['name']}")
print(f" Headline: {first_candidate['headline'][:80]}...")
print(f" Fit Score: {first_candidate['fit_score']}")
print(f" Key Characteristics: {first_candidate['key_characteristics']}")
if first_candidate.get('outreach_message'):
print(f" Outreach Message: {first_candidate['outreach_message'][:100]}...")
return True
else:
print(f"❌ Demo failed: {response.status_code}")
print(f" Error: {response.text}")
return False
except Exception as e:
print(f"❌ Demo test failed: {e}")
return False
def test_main_endpoint():
"""Test the main source-candidates endpoint"""
print("\n🎯 Testing Main Sourcing Endpoint...")
# Windsurf ML Research job (from hackathon)
job_request = {
"job_description": """
Software Engineer, ML Research at Windsurf (Codeium)
We're looking for a talented Software Engineer to join our ML Research team at Windsurf,
the company behind Codeium. You'll be working on training and optimizing Large Language Models
for code generation and AI-powered developer tools.
Requirements:
- Strong experience with Python, PyTorch, TensorFlow
- Machine Learning and Deep Learning expertise
- Experience with LLMs and code generation
- Located in Mountain View, CA or remote
Compensation: $140-300k + equity
""",
"location": "Mountain View",
"max_candidates": 5,
"include_outreach": True
}
try:
response = requests.post(
f"{API_BASE}/source-candidates",
json=job_request,
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
data = response.json()
print(f"✅ Main endpoint: {response.status_code}")
print(f" Job ID: {data['job_id']}")
print(f" Candidates found: {data['candidates_found']}")
print(f" Processing time: {data['processing_time_seconds']}s")
print(f" Search query used: {data['search_query_used']}")
print(f" Top candidates returned: {len(data['top_candidates'])}")
# Show detailed candidate information
for i, candidate in enumerate(data['top_candidates'][:2], 1):
print(f"\n🏆 Top Candidate #{i}:")
print(f" Name: {candidate['name']}")
print(f" Headline: {candidate['headline']}")
print(f" Location: {candidate['location']}")
print(f" Fit Score: {candidate['fit_score']:.1f}/10")
print(f" Confidence: {candidate['confidence']}")
print(f" Score Breakdown:")
for category, score in candidate['score_breakdown'].items():
print(f" • {category.replace('_', ' ').title()}: {score:.1f}")
print(f" Key Characteristics:")
for char in candidate['key_characteristics']:
print(f" • {char}")
print(f" Job Match Reasons:")
for reason in candidate['job_match_reasons']:
print(f" • {reason}")
if candidate.get('outreach_message'):
print(f" Outreach Message:")
print(f" {candidate['outreach_message'][:200]}...")
return True
else:
print(f"❌ Main endpoint failed: {response.status_code}")
print(f" Error: {response.text}")
return False
except Exception as e:
print(f"❌ Main endpoint test failed: {e}")
return False
def run_performance_test():
"""Quick performance test"""
print("\n⚡ Performance Test...")
start_time = time.time()
response = requests.get(f"{API_BASE}/demo")
end_time = time.time()
if response.status_code == 200:
processing_time = end_time - start_time
data = response.json()
agent_processing_time = data.get('processing_time_seconds', 0)
print(f"✅ Performance Test Results:")
print(f" Total request time: {processing_time:.2f}s")
print(f" Agent processing time: {agent_processing_time:.2f}s")
print(f" Network overhead: {processing_time - agent_processing_time:.2f}s")
print(f" Candidates per second: {data['candidates_found'] / max(agent_processing_time, 0.01):.1f}")
def main():
"""Run all API tests"""
print("🚀 LinkedIn Sourcing Agent API Test Suite")
print("=" * 50)
# Test 1: Basic health
if not test_basic_health():
print("❌ Basic health check failed. Is the server running?")
return
# Test 2: Demo endpoint
if not test_demo_endpoint():
print("❌ Demo endpoint failed")
return
# Test 3: Main endpoint
if not test_main_endpoint():
print("❌ Main endpoint failed")
return
# Test 4: Performance
run_performance_test()
print("\n🎉 All API tests passed!")
print("\n📚 API Documentation available at: http://localhost:8000/docs")
print("🔗 Interactive testing at: http://localhost:8000/docs")
if __name__ == "__main__":
main()