From 80198ca056ae36f2d2698e9c115f13293bd2d257 Mon Sep 17 00:00:00 2001 From: TerminalMan <84923604+SecretiveShell@users.noreply.github.com> Date: Wed, 28 Aug 2024 02:37:41 +0100 Subject: [PATCH] API: Add /v1/health endpoint (#178) * Add healthcheck - localhost only /healthcheck endpoint - cURL healthcheck in docker compose file * Update Healthcheck Response - change endpoint to /health - remove localhost restriction - add docstring * move healthcheck definition to top of the file - make the healthcheck show up first in the openAPI spec * Tree: Format --- docker/docker-compose.yml | 5 +++++ endpoints/core/router.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 87eaea68..d55d8570 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -8,6 +8,11 @@ services: - DO_PULL=true ports: - "5000:5000" + healthcheck: + test: ["CMD", "curl", "-f", "http://127.0.0.1:5000/health"] + interval: 30s + timeout: 10s + retries: 3 environment: - NAME=TabbyAPI - NVIDIA_VISIBLE_DEVICES=all diff --git a/endpoints/core/router.py b/endpoints/core/router.py index a857a1a1..88505242 100644 --- a/endpoints/core/router.py +++ b/endpoints/core/router.py @@ -44,6 +44,13 @@ router = APIRouter() +# Healthcheck endpoint +@router.get("/health") +async def healthcheck(): + """Get the current service health status""" + return {"status": "healthy"} + + # Model list endpoint @router.get("/v1/models", dependencies=[Depends(check_api_key)]) @router.get("/v1/model/list", dependencies=[Depends(check_api_key)])