ASE-GLM / server /insight.py
Bit-Trading-Company's picture
CI deploy local
17b22d9 verified
Raw History Blame Contribute Delete
1.61 kB
"""Live metadata from the Hub, for the panels that exist to show it.
Separate from `catalog.py` because these calls can be slow or fail: the app
must start and chat without them.
"""
from __future__ import annotations
import httpx
HUB = "https://huggingface.co/api/models"
async def model_info(model_id: str, token: str | None) -> dict:
"""Provider routing and card metadata for one model."""
headers = {"Authorization": f"Bearer {token}"} if token else {}
params = {"expand[]": ["inferenceProviderMapping", "pipeline_tag", "gated", "downloads"]}
try:
async with httpx.AsyncClient(timeout=15.0) as client:
r = await client.get(f"{HUB}/{model_id}", headers=headers, params=params)
if r.status_code >= 400:
return {"id": model_id, "error": f"hub returned {r.status_code}"}
data = r.json()
except httpx.HTTPError as e:
return {"id": model_id, "error": f"{type(e).__name__}: {e}"}
mapping = data.get("inferenceProviderMapping") or {}
providers = []
if isinstance(mapping, dict):
for name, spec in mapping.items():
providers.append({
"provider": name,
"status": spec.get("status"),
"providerId": spec.get("providerId"),
"task": spec.get("task"),
"firstParty": bool(spec.get("isModelAuthor")),
})
return {
"id": model_id,
"pipeline": data.get("pipeline_tag"),
"gated": data.get("gated"),
"downloads": data.get("downloads"),
"providers": providers,
}