File size: 2,102 Bytes
b5c6814
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import json

# Test the API endpoints
def test_api():
    base_url = "http://localhost:8000"
    
    print("πŸ§ͺ Testing API endpoints...")
    
    # Test root endpoint
    try:
        response = requests.get(f"{base_url}/")
        print(f"βœ… Root endpoint: {response.status_code}")
        print(f"   Response: {response.json()}")
    except Exception as e:
        print(f"❌ Root endpoint failed: {e}")
    
    # Test health endpoint
    try:
        response = requests.get(f"{base_url}/health")
        print(f"βœ… Health endpoint: {response.status_code}")
        health_data = response.json()
        print(f"   AI Models Ready: {health_data.get('ai_models_ready')}")
        print(f"   Initialization Status: {health_data.get('initialization_status')}")
    except Exception as e:
        print(f"❌ Health endpoint failed: {e}")
    
    # Test debug endpoint
    try:
        response = requests.get(f"{base_url}/debug")
        print(f"βœ… Debug endpoint: {response.status_code}")
        debug_data = response.json()
        print(f"   AI Assistant Exists: {debug_data.get('ai_assistant_exists')}")
        print(f"   Models Ready: {debug_data.get('models_ready')}")
        print(f"   Initialization Status: {debug_data.get('initialization_status')}")
    except Exception as e:
        print(f"❌ Debug endpoint failed: {e}")
    
    # Test chat endpoint
    try:
        chat_data = {
            "message": "Hello, can you help me with math?",
            "subject": "Mathematics",
            "message_type": "text"
        }
        response = requests.post(f"{base_url}/chat", json=chat_data)
        print(f"βœ… Chat endpoint: {response.status_code}")
        if response.status_code == 200:
            chat_response = response.json()
            print(f"   Success: {chat_response.get('success')}")
            print(f"   Response: {chat_response.get('response')[:100]}...")
        else:
            print(f"   Error: {response.text}")
    except Exception as e:
        print(f"❌ Chat endpoint failed: {e}")

if __name__ == "__main__":
    test_api()