File size: 1,429 Bytes
0339ef7
 
6493bef
0339ef7
 
 
6493bef
 
0339ef7
 
 
 
 
6493bef
 
0339ef7
 
 
 
 
75f9ceb
 
 
6493bef
75f9ceb
 
 
 
0339ef7
 
 
 
 
 
 
 
75f9ceb
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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"]