File size: 4,989 Bytes
9730fbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
🧪 Teste Simples - Apenas Models API
Testa apenas a API de modelos sem dependências do backend
"""

import asyncio
import httpx
import json
from datetime import datetime

# Models API URL (confirmed working)
MODELS_URL = "https://neural-thinker-cidadao-ai-models.hf.space"

async def test_models_api():
    """🤖 Teste completo da Models API"""
    print("🤖 TESTE DA CIDADÃO.AI MODELS API")
    print("=" * 50)
    print(f"🔗 URL: {MODELS_URL}")
    print(f"🕐 Iniciado em: {datetime.now().strftime('%H:%M:%S')}")
    print()
    
    async with httpx.AsyncClient(timeout=30.0) as client:
        
        # 1. Root endpoint
        print("1️⃣ TESTANDO ROOT ENDPOINT")
        try:
            response = await client.get(f"{MODELS_URL}/")
            if response.status_code == 200:
                data = response.json()
                print("   ✅ Root endpoint OK")
                print(f"   📊 API: {data.get('api', 'N/A')}")
                print(f"   🔢 Version: {data.get('version', 'N/A')}")
                print(f"   📋 Status: {data.get('status', 'N/A')}")
            else:
                print(f"   ❌ Root: {response.status_code}")
        except Exception as e:
            print(f"   ❌ Root error: {str(e)}")
        
        # 2. Health check
        print("\n2️⃣ TESTANDO HEALTH CHECK")
        try:
            response = await client.get(f"{MODELS_URL}/health")
            if response.status_code == 200:
                data = response.json()
                print("   ✅ Health check OK")
                print(f"   📊 Status: {data.get('status', 'N/A')}")
                print(f"   🤖 Models loaded: {data.get('models_loaded', 'N/A')}")
                print(f"   💬 Message: {data.get('message', 'N/A')}")
            else:
                print(f"   ❌ Health: {response.status_code}")
        except Exception as e:
            print(f"   ❌ Health error: {str(e)}")
        
        # 3. Test docs endpoint
        print("\n3️⃣ TESTANDO DOCUMENTAÇÃO")
        try:
            response = await client.get(f"{MODELS_URL}/docs")
            if response.status_code == 200:
                print("   ✅ Docs available")
                print(f"   📝 Content-Type: {response.headers.get('content-type', 'N/A')}")
            else:
                print(f"   ❌ Docs: {response.status_code}")
        except Exception as e:
            print(f"   ❌ Docs error: {str(e)}")
        
        # 4. Test spaces-info
        print("\n4️⃣ TESTANDO SPACES INFO")
        try:
            response = await client.get(f"{MODELS_URL}/spaces-info")
            if response.status_code == 200:
                data = response.json()
                print("   ✅ Spaces info OK")
                print(f"   🏠 Space ID: {data.get('space_id', 'N/A')}")
                print(f"   👤 Author: {data.get('space_author', 'N/A')}")
                print(f"   📦 Platform: {data.get('platform', 'N/A')}")
                print(f"   🤖 Models available: {data.get('models_available', 'N/A')}")
            else:
                print(f"   ❌ Spaces info: {response.status_code}")
        except Exception as e:
            print(f"   ❌ Spaces info error: {str(e)}")
        
        # 5. Test model endpoints (if available)
        print("\n5️⃣ TESTANDO ENDPOINTS DE MODELO")
        
        model_endpoints = [
            "/v1/detect-anomalies",
            "/v1/analyze-patterns",
            "/v1/analyze-spectral"
        ]
        
        for endpoint in model_endpoints:
            try:
                # Test with minimal payload
                test_payload = {
                    "contracts": [{"value": 1000, "vendor": "test"}],
                    "threshold": 0.7
                } if "anomalies" in endpoint else {
                    "data": [1, 2, 3, 4, 5],
                    "params": {"test": True}
                }
                
                response = await client.post(f"{MODELS_URL}{endpoint}", json=test_payload)
                
                if response.status_code == 200:
                    print(f"   ✅ {endpoint} - Functional")
                elif response.status_code == 422:
                    print(f"   📋 {endpoint} - Schema validation (endpoint exists)")
                elif response.status_code == 404:
                    print(f"   ❌ {endpoint} - Not found")
                else:
                    print(f"   ⚠️ {endpoint} - Status: {response.status_code}")
                    
            except Exception as e:
                print(f"   ❌ {endpoint} - Error: {str(e)[:50]}...")
    
    print("\n" + "=" * 50)
    print("🎯 RESUMO")
    print("✅ Models API está ONLINE e acessível")
    print("🔗 URL funcional:", MODELS_URL)
    print("📚 Documentação:", f"{MODELS_URL}/docs")
    print("🏥 Health check:", f"{MODELS_URL}/health")

if __name__ == "__main__":
    asyncio.run(test_models_api())