mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-14 00:53:25 +00:00
feat
This commit is contained in:
36
src/main.py
36
src/main.py
@ -1,25 +1,21 @@
|
||||
from typing import Union
|
||||
|
||||
import asyncio
|
||||
import websockets
|
||||
from websockets.server import serve
|
||||
from websockets.legacy.server import WebSocketServerProtocol
|
||||
from fastapi import FastAPI, Request, UploadFile, status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from connection.connection import ConnectionContext
|
||||
|
||||
async def echo(websocket: WebSocketServerProtocol):
|
||||
connection = ConnectionContext()
|
||||
while True:
|
||||
try:
|
||||
message = await websocket.recv()
|
||||
except websockets.ConnectionClosedOK:
|
||||
break
|
||||
connection.handle(message)
|
||||
|
||||
from blackbox.blockbox_factory import BlockboxFactory
|
||||
import io
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
async def main():
|
||||
async with serve(echo, "localhost", 8765):
|
||||
await asyncio.Future()
|
||||
blackbox_factory = BlockboxFactory()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@app.post("/")
|
||||
async def blackbox(blackbox_name: Union[str, None] = None, request: Request = None):
|
||||
if not blackbox_name:
|
||||
return await JSONResponse(content={"error": "blackbox_name is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
try:
|
||||
box = blackbox_factory.create_blockbox(blackbox_name, {})
|
||||
except ValueError:
|
||||
return await JSONResponse(content={"error": "value error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
return await box.fast_api_handler(request)
|
||||
|
||||
Reference in New Issue
Block a user