File size: 4,173 Bytes
3951d64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test script for the Ultra-Fast RAG System API
Usage: python test_api.py <base_url>
Example: python test_api.py https://your-app.railway.app
"""

import requests
import json
import time
import sys

def test_api(base_url):
    """Test the deployed API endpoints"""
    
    print(f"πŸ§ͺ Testing API at: {base_url}")
    
    # Test 1: Health Check
    print("\n1️⃣ Testing Health Check...")
    try:
        response = requests.get(f"{base_url}/health", timeout=10)
        if response.status_code == 200:
            print("βœ… Health check passed!")
            print(f"   Response: {response.json()}")
        else:
            print(f"❌ Health check failed: {response.status_code}")
            return False
    except Exception as e:
        print(f"❌ Health check error: {e}")
        return False
    
    # Test 2: Sample RAG Query
    print("\n2️⃣ Testing RAG Endpoint...")
    
    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "Authorization": "Bearer dbbdb701cfc45d4041e22a03edbfc65753fe9d7b4b9ba1df4884e864f3bb934d"
    }
    
    test_payload = {
        "documents": "https://hackrx.blob.core.windows.net/assets/policy.pdf?sv=2023-01-03&st=2025-07-04T09%3A11%3A24Z&se=2027-07-05T09%3A11%3A00Z&sr=b&sp=r&sig=N4a9OU0w0QXO6AOIBiu4bpl7AXvEZogeT%2FjUHNO7HzQ%3D",
        "questions": [
            "What is the grace period for premium payment?",
            "What is the waiting period for pre-existing diseases?"
        ]
    }
    
    try:
        print("   Sending request... (this may take 15-30 seconds)")
        start_time = time.time()
        
        response = requests.post(
            f"{base_url}/hackrx/run", 
            json=test_payload,
            headers=headers,
            timeout=120
        )
        
        end_time = time.time()
        response_time = end_time - start_time
        
        if response.status_code == 200:
            result = response.json()
            print(f"βœ… RAG query successful! ({response_time:.2f} seconds)")
            print(f"   Questions: {len(test_payload['questions'])}")
            print(f"   Answers: {len(result['answers'])}")
            print("\n   Sample answers:")
            for i, answer in enumerate(result['answers'][:2]):
                print(f"   Q{i+1}: {answer[:100]}...")
        else:
            print(f"❌ RAG query failed: {response.status_code}")
            print(f"   Response: {response.text}")
            return False
            
    except Exception as e:
        print(f"❌ RAG query error: {e}")
        return False
    
    # Test 3: Metrics (optional)
    print("\n3️⃣ Testing Metrics Endpoint...")
    try:
        response = requests.get(
            f"{base_url}/metrics", 
            headers=headers,
            timeout=10
        )
        if response.status_code == 200:
            print("βœ… Metrics endpoint working!")
            metrics = response.json()
            print(f"   Total queries: {metrics.get('total_queries_24h', 0)}")
        else:
            print(f"⚠️ Metrics endpoint issue: {response.status_code}")
    except Exception as e:
        print(f"⚠️ Metrics endpoint error: {e}")
    
    print(f"\nπŸŽ‰ API testing complete! System is ready for hackathon use.")
    return True

def main():
    if len(sys.argv) != 2:
        print("Usage: python test_api.py <base_url>")
        print("Example: python test_api.py https://your-app.railway.app")
        sys.exit(1)
    
    base_url = sys.argv[1].rstrip('/')
    
    print("πŸš€ Ultra-Fast RAG System API Tester")
    print("=" * 50)
    
    success = test_api(base_url)
    
    if success:
        print("\nβœ… All tests passed! Your API is ready for the hackathon! πŸ†")
        print(f"\nπŸ“‹ API Usage Summary:")
        print(f"   Endpoint: POST {base_url}/hackrx/run")
        print(f"   Auth: Bearer dbbdb701cfc45d4041e22a03edbfc65753fe9d7b4b9ba1df4884e864f3bb934d")
        print(f"   Health: GET {base_url}/health")
    else:
        print("\n❌ Some tests failed. Please check your deployment.")
        sys.exit(1)

if __name__ == "__main__":
    main()