mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-14 17:13:25 +00:00
feat: sum
This commit is contained in:
23
src/blackbox/sum.py
Normal file
23
src/blackbox/sum.py
Normal file
@ -0,0 +1,23 @@
|
||||
from typing import Any, Coroutine
|
||||
|
||||
from fastapi import Request, Response, status
|
||||
from fastapi.responses import JSONResponse
|
||||
from .blackbox import Blackbox
|
||||
|
||||
|
||||
class SUM(Blackbox):
|
||||
|
||||
def valid(self, data: any) -> bool:
|
||||
return isinstance(data, list)
|
||||
|
||||
def processing(self, data: list) -> Coroutine[Any, Any, Any]:
|
||||
return sum(data)
|
||||
|
||||
async def fast_api_handler(self, request: Request) -> Response:
|
||||
try:
|
||||
data = await request.json()
|
||||
except:
|
||||
return JSONResponse(content={"error": "json parse error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
if not self.valid(data):
|
||||
return JSONResponse(content={"error": "format error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
return JSONResponse(content={"result": self.processing(data)}, status_code=status.HTTP_200_OK)
|
||||
Reference in New Issue
Block a user