-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_hybrid_setup.py
More file actions
295 lines (253 loc) · 9.85 KB
/
test_hybrid_setup.py
File metadata and controls
295 lines (253 loc) · 9.85 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
"""
Test script to verify the hybrid architecture setup
Run this after starting both Node.js and Python servers
"""
import requests
import json
from datetime import datetime
# Configuration
NODE_API = "http://localhost:3000"
PYTHON_API = "http://localhost:8000"
def print_section(title):
"""Print a formatted section header"""
print("\n" + "="*70)
print(f" {title}")
print("="*70)
def test_health_checks():
"""Test health endpoints for both servers"""
print_section("HEALTH CHECKS")
# Test Python API
try:
response = requests.get(f"{PYTHON_API}/health", timeout=5)
if response.status_code == 200:
data = response.json()
print(f"✅ Python API: {data['status']} (DB: {data['database']})")
else:
print(f"❌ Python API: Status code {response.status_code}")
except Exception as e:
print(f"❌ Python API: {str(e)}")
# Test Node.js API
try:
response = requests.get(f"{NODE_API}/health", timeout=5)
if response.status_code == 200:
data = response.json()
print(f"✅ Node.js API: {data['status']}")
else:
print(f"❌ Node.js API: Status code {response.status_code}")
except Exception as e:
print(f"❌ Node.js API: {str(e)}")
def test_translation():
"""Test translation endpoint"""
print_section("TRANSLATION TEST")
payload = {
"text": "Hello, this is a test complaint",
"source_language": "en",
"target_language": "en"
}
try:
response = requests.post(
f"{PYTHON_API}/api/process/translate",
json=payload,
timeout=10
)
if response.status_code == 200:
data = response.json()
print(f"✅ Translation successful")
print(f" Original: {data['original_text']}")
print(f" Translated: {data['translated_text']}")
print(f" Method: {data['method']}")
else:
print(f"❌ Translation failed: {response.status_code}")
print(f" {response.text}")
except Exception as e:
print(f"❌ Translation error: {str(e)}")
def test_classification():
"""Test complaint classification"""
print_section("CLASSIFICATION TEST")
payload = {
"text": "Water supply is not working in my area since morning",
"language": "en"
}
try:
response = requests.post(
f"{PYTHON_API}/api/process/classify",
json=payload,
timeout=10
)
if response.status_code == 200:
data = response.json()
print(f"✅ Classification successful")
print(f" Category: {data['category']['name']} ({data['category']['code']})")
print(f" Confidence: {data['confidence']:.2%}")
print(f" Urgency: {data['category']['urgency']}")
print(f" Method: {data['method']}")
else:
print(f"❌ Classification failed: {response.status_code}")
print(f" {response.text}")
except Exception as e:
print(f"❌ Classification error: {str(e)}")
def test_location_resolution():
"""Test location resolution"""
print_section("LOCATION RESOLUTION TEST")
payload = {
"text": "There is garbage problem in Shivaji Nagar area near main road"
}
try:
response = requests.post(
f"{PYTHON_API}/api/process/resolve-location",
json=payload,
timeout=10
)
if response.status_code == 200:
data = response.json()
print(f"✅ Location resolution successful")
print(f" Found: {data['found']}")
if data['found']:
print(f" Location: {data['location']}")
print(f" Ward: {data['wardNumber']} - {data['wardName']}")
print(f" Zone: {data['zone']}")
print(f" Confidence: {data['confidence']:.2%}")
else:
print(f" No location found")
else:
print(f"❌ Location resolution failed: {response.status_code}")
print(f" {response.text}")
except Exception as e:
print(f"❌ Location error: {str(e)}")
def test_full_pipeline():
"""Test complete complaint processing pipeline"""
print_section("FULL PIPELINE TEST")
payload = {
"text": "Water supply problem in Shivaji Nagar since yesterday morning",
"language": "en",
"phone_number": "+919876543210",
"call_sid": f"TEST-{datetime.now().strftime('%Y%m%d-%H%M%S')}"
}
try:
print(f"Testing complaint: {payload['text']}")
print(f"Call SID: {payload['call_sid']}")
response = requests.post(
f"{PYTHON_API}/api/process/complaint",
json=payload,
timeout=30
)
if response.status_code == 200:
data = response.json()
print(f"\n✅ Full pipeline successful!")
# Translation
if data.get('translation'):
print(f"\n📝 Translation:")
print(f" Used: {data['translation']['translation_used']}")
print(f" Method: {data['translation']['method']}")
# Classification
if data.get('classification'):
cls = data['classification']
print(f"\n🏷️ Classification:")
print(f" Category: {cls['category']['name']}")
print(f" Confidence: {cls['confidence']:.2%}")
# Location
if data.get('location'):
loc = data['location']
print(f"\n📍 Location:")
print(f" Found: {loc['found']}")
if loc['found']:
print(f" Area: {loc.get('location', 'N/A')}")
print(f" Ward: {loc.get('wardNumber', 'N/A')}")
print(f" Zone: {loc.get('zone', 'N/A')}")
# Urgency
if data.get('urgency'):
urg = data['urgency']
print(f"\n⚡ Urgency:")
print(f" Level: {urg['urgency_level']}")
print(f" Score: {urg['urgency_score']:.2%}")
print(f" Method: {urg['method']}")
# Duplicate
if data.get('duplicate'):
dup = data['duplicate']
print(f"\n🔄 Duplicate Check:")
print(f" Is Duplicate: {dup['is_duplicate']}")
print(f" Method: {dup['method']}")
print(f"\n📄 Complete Response:")
print(json.dumps(data, indent=2))
else:
print(f"❌ Full pipeline failed: {response.status_code}")
print(f" {response.text}")
except Exception as e:
print(f"❌ Pipeline error: {str(e)}")
def test_duplicate_detection():
"""Test duplicate detection endpoint"""
print_section("DUPLICATE DETECTION TEST (Placeholder)")
payload = {
"text": "Water supply issue",
"category": "WATER_SUPPLY",
"ward_number": 1
}
try:
response = requests.post(
f"{PYTHON_API}/api/process/detect-duplicate",
json=payload,
timeout=10
)
if response.status_code == 200:
data = response.json()
print(f"✅ Duplicate detection called (placeholder)")
print(f" Is Duplicate: {data['is_duplicate']}")
print(f" Method: {data['method']}")
print(f" Note: This is a placeholder - teammate will implement")
else:
print(f"❌ Duplicate detection failed: {response.status_code}")
except Exception as e:
print(f"❌ Duplicate detection error: {str(e)}")
def test_urgency_classification():
"""Test urgency classification endpoint"""
print_section("URGENCY CLASSIFICATION TEST (Placeholder)")
payload = {
"text": "Emergency water supply problem",
"category": "WATER_SUPPLY",
"category_base_urgency": "high"
}
try:
response = requests.post(
f"{PYTHON_API}/api/process/classify-urgency",
json=payload,
timeout=10
)
if response.status_code == 200:
data = response.json()
print(f"✅ Urgency classification called (placeholder)")
print(f" Level: {data['urgency_level']}")
print(f" Score: {data['urgency_score']:.2%}")
print(f" Method: {data['method']}")
print(f" Note: This is a placeholder - teammate will implement")
else:
print(f"❌ Urgency classification failed: {response.status_code}")
except Exception as e:
print(f"❌ Urgency classification error: {str(e)}")
def main():
"""Run all tests"""
print("\n" + "="*70)
print(" VMC CALLING AGENT - HYBRID ARCHITECTURE TEST SUITE")
print("="*70)
print(f"\nTesting at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print(f"Node.js API: {NODE_API}")
print(f"Python API: {PYTHON_API}")
# Run tests
test_health_checks()
test_translation()
test_classification()
test_location_resolution()
test_duplicate_detection()
test_urgency_classification()
test_full_pipeline()
# Summary
print_section("TEST SUMMARY")
print("✅ If all tests passed, your hybrid architecture is working!")
print("⏳ Placeholder services (duplicate, urgency) need implementation")
print("\nNext steps:")
print("1. Ensure both servers are running")
print("2. Test with actual Twilio phone call")
print("3. Check MongoDB for saved complaints")
print("4. Implement placeholder services")
print("\n" + "="*70 + "\n")
if __name__ == "__main__":
main()