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
This commit is contained in:
TerminalMan 2024-08-28 02:37:41 +01:00 committed by GitHub
parent 872eeed581
commit 80198ca056
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -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

View file

@ -44,6 +44,13 @@ from endpoints.core.utils.model import (
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)])