Преглед изворни кода

Add method GET on route `/health` (#886)

* add get method `/health`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Pandede пре 1 година
родитељ
комит
c0677738b3
1 измењених фајлова са 18 додато и 4 уклоњено
  1. 18 4
      tools/server/views.py

+ 18 - 4
tools/server/views.py

@@ -7,7 +7,15 @@ import numpy as np
 import ormsgpack
 import soundfile as sf
 import torch
-from kui.asgi import Body, HTTPException, JSONResponse, Routes, StreamResponse, request
+from kui.asgi import (
+    Body,
+    HTTPException,
+    HttpView,
+    JSONResponse,
+    Routes,
+    StreamResponse,
+    request,
+)
 from loguru import logger
 from typing_extensions import Annotated
 
@@ -40,9 +48,15 @@ MAX_NUM_SAMPLES = int(os.getenv("NUM_SAMPLES", 1))
 routes = Routes()
 
 
-@routes.http.post("/v1/health")
-async def health():
-    return JSONResponse({"status": "ok"})
+@routes.http("/v1/health")
+class Health(HttpView):
+    @classmethod
+    async def get(cls):
+        return JSONResponse({"status": "ok"})
+
+    @classmethod
+    async def post(cls):
+        return JSONResponse({"status": "ok"})
 
 
 @routes.http.post("/v1/vqgan/encode")