paraAI_rag / test_api.py
caarleexx's picture
Upload 7 files
35e36f1 verified
#!/usr/bin/env python3
"""
Script de teste rápido para verificar conexão com API
"""
import requests
import json
API_URL = "http://localhost:7860"
print("🔍 Testando conexão com API...")
print("="*60)
# Teste 1: Status
print("\n1. Verificando status...")
try:
r = requests.get(f"{API_URL}/")
print(f" ✅ Status: {r.status_code}")
data = r.json()
print(f" RAG Ready: {data.get('rag_ready', False)}")
print(f" Setup: {data.get('setup', {}).get('status', 'N/A')}")
except Exception as e:
print(f" ❌ Erro: {e}")
# Teste 2: Setup status
print("\n2. Verificando setup...")
try:
r = requests.get(f"{API_URL}/setup/status")
print(f" ✅ Status: {r.status_code}")
data = r.json()
print(f" Progresso: {data.get('progress', 0)}%")
print(f" Mensagem: {data.get('message', 'N/A')}")
except Exception as e:
print(f" ❌ Erro: {e}")
# Teste 3: Busca (se pronto)
print("\n3. Testando busca semântica...")
try:
payload = {
"query": "teste",
"top_k": 3,
"return_embeddings": False
}
r = requests.post(
f"{API_URL}/search/embedding",
json=payload,
timeout=10
)
if r.status_code == 200:
data = r.json()
print(f" ✅ Busca OK!")
print(f" Total: {data.get('total_results', 0)} resultados")
print(f" Tempo: {data.get('query_time_ms', 0)}ms")
elif r.status_code == 503:
print(f" ⏳ RAG ainda não pronto (503)")
else:
print(f" ❌ Erro: {r.status_code}")
except Exception as e:
print(f" ❌ Erro: {e}")
print("\n" + "="*60)
print("✅ Testes completos!")
print("\nSe todos os testes passaram, rode:")
print(" python app_gradio.py")