from httpx import AsyncClient from src.envs import API_URL, TIMEOUT from src.result import LbData, Result async def get_leaderboard_names() -> list[str]: async with AsyncClient(timeout=TIMEOUT) as client: response = await client.get(f"{API_URL}/leaderboards") response.raise_for_status() return [lb["name"] for lb in response.json()] async def get_gpus_for_leaderboard(lb_name: str) -> list[str]: async with AsyncClient(timeout=TIMEOUT) as client: response = await client.get(f"{API_URL}/gpus/{lb_name}") response.raise_for_status() return response.json() async def get_leaderboard_submissions( lb_name: str, gpu: str, limit: int = None, offset: int = 0 ) -> LbData: async with AsyncClient(timeout=TIMEOUT) as client: params = {"limit": limit, "offset": offset} response = await client.get( f"{API_URL}/submissions/{lb_name}/{gpu}", params=params ) response.raise_for_status() return LbData( gpu=gpu, name=lb_name, results=[Result.from_dict(result) for result in response.json()], ) async def get_submission_count(lb_name: str, gpu: str) -> int: async with AsyncClient(timeout=TIMEOUT) as client: response = await client.get(f"{API_URL}/submission_count/{lb_name}/{gpu}") response.raise_for_status() return response.json()["count"]