File size: 619 Bytes
6bf9c98
36334a9
 
6bf9c98
 
36334a9
6bf9c98
 
 
36334a9
6bf9c98
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# status_check.py

from typing import Optional, Tuple
import os
import requests

def resolve_endpoint() -> Optional[str]:
    # however you get it today; env var is simplest
    return os.environ.get("HF_ENDPOINT_URI")

def is_endpoint_healthy(uri: str, timeout: float = 5.0) -> Tuple[bool, str]:
    if not uri:
        return False, "No endpoint URI configured."
    try:
        r = requests.post(uri, json={"inputs": "ping"}, timeout=timeout)
        return (True, "OK") if r.ok else (False, f"HTTP {r.status_code}")
    except requests.exceptions.RequestException as e:
        return False, f"{type(e).__name__}"