#!/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())