Spaces:
Paused
Paused
Download scripts/smoke_test_api.py from uranusmediaconn/bridgenton: direct link, hf CLI and curl.
- Browser
- Download file 3.6 kB
-
https://huggingface.co/spaces/uranusmediaconn/bridgenton/resolve/main/scripts/smoke_test_api.py
- Command line
-
hf download hf://spaces/uranusmediaconn/bridgenton/scripts/smoke_test_api.py
-
curl -L -o smoke_test_api.py https://huggingface.co/spaces/uranusmediaconn/bridgenton/resolve/main/scripts/smoke_test_api.py
3.6 kB
| import sys | |
| import json | |
| import os | |
| import time | |
| from typing import Any, Dict, Optional | |
| import requests | |
| BASE_URL = os.getenv("API_BASE_URL", "http://127.0.0.1:7860") | |
| TIMEOUT = int(os.getenv("API_TIMEOUT", "120")) | |
| def post(path: str, payload: Dict[str, Any], headers: Optional[Dict[str, str]] = None): | |
| url = f"{BASE_URL}{path}" | |
| r = requests.post(url, json=payload, headers=headers or {}, timeout=TIMEOUT) | |
| return r | |
| def get(path: str, params: Optional[Dict[str, Any]] = None, headers: Optional[Dict[str, str]] = None): | |
| url = f"{BASE_URL}{path}" | |
| r = requests.get(url, params=params or {}, headers=headers or {}, timeout=TIMEOUT) | |
| return r | |
| def pretty(r: requests.Response): | |
| ct = r.headers.get("content-type", "") | |
| if "application/json" in ct: | |
| try: | |
| return json.dumps(r.json(), indent=2)[:2000] | |
| except Exception: | |
| pass | |
| return (r.text or "").strip()[:2000] | |
| def main(): | |
| print(f"[*] API_BASE_URL={BASE_URL}") | |
| checks = [] | |
| # Basic | |
| checks.append(("GET /health", lambda: get("/health"))) | |
| # Chat models without keys | |
| checks.append(("GET /api/chat/models (no key)", lambda: get("/api/chat/models"))) | |
| # Chat request without key should error (401/500) | |
| checks.append(("POST /api/chat/chat (no key)", lambda: post( | |
| "/api/chat/chat", | |
| { | |
| "message": "Say hello in one sentence.", | |
| "model": "openrouter/free", | |
| "provider": "openrouter", | |
| }, | |
| ))) | |
| # Scrape (requests scraper) | |
| checks.append(("POST /scrape (requests)", lambda: post( | |
| "/scrape", | |
| {"url": "https://example.com", "scraper": "requests", "timeout": 30}, | |
| ))) | |
| # Search | |
| checks.append(("POST /search", lambda: post( | |
| "/search", | |
| {"query": "software company", "engine": "duckduckgo", "num_results": 5}, | |
| ))) | |
| # Swarm (uses UI mapping; will likely run without DB/provider keys) | |
| checks.append(("POST /swarm", lambda: post( | |
| "/swarm", | |
| {"industry": "Software", "location": "Chicago", "amount": 5}, | |
| ))) | |
| # Validate endpoints (edge case empty + example) | |
| checks.append(("POST /validate/email", lambda: post( | |
| "/validate/email", | |
| {"emails": ["test@example.com", "invalid-email"], "do_smtp": False}, | |
| ))) | |
| checks.append(("POST /validate/phone", lambda: post( | |
| "/validate/phone", | |
| {"numbers": ["+14155552671", "12345"], "region": "US"}, | |
| ))) | |
| # Enrichment/discovery | |
| checks.append(("POST /enrich/domain", lambda: post( | |
| "/enrich/domain", | |
| {"domain": "example.com"}, | |
| ))) | |
| checks.append(("POST /enrich/batch", lambda: post( | |
| "/enrich/batch", | |
| {"domains": ["example.com", "example.org"]}, | |
| ))) | |
| checks.append(("POST /discovery/emails", lambda: post( | |
| "/discovery/emails", | |
| {"domain": "example.com"}, | |
| ))) | |
| # Proxy endpoints (may be unavailable if not configured) | |
| checks.append(("GET /proxy/stats", lambda: get("/proxy/stats"))) | |
| checks.append(("GET /proxies/stats", lambda: get("/proxies/stats"))) | |
| for name, fn in checks: | |
| print("\n" + "=" * 80) | |
| print(f"[TEST] {name}") | |
| try: | |
| r = fn() | |
| print(f"[RESULT] HTTP {r.status_code}") | |
| print(pretty(r)) | |
| except Exception as e: | |
| print(f"[ERROR] {e.__class__.__name__}: {e}") | |
| time.sleep(0.25) | |
| print("\n[*] Smoke test completed") | |
| if __name__ == "__main__": | |
| try: | |
| main() | |
| except KeyboardInterrupt: | |
| print("\n[!] Interrupted") | |
| sys.exit(130) | |