utils.py 482 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import time

from aiohttp import ClientConnectorError, ClientOSError, ServerDisconnectedError
from text_generation import AsyncClient


async def health_check(client: AsyncClient, timeout: int = 60):
    assert timeout > 0
    for _ in range(timeout):
        try:
            await client.generate("test")
            return
        except (ClientConnectorError, ClientOSError, ServerDisconnectedError) as e:
            time.sleep(1)
    raise RuntimeError("Health check failed")