CaesarFrenchLLM / main.py
palondomus's picture
CaesarFrenchLLM first test
37cb9fa
raw
history blame
1.05 kB
import asyncio
from fastapi import FastAPI, UploadFile, WebSocket, WebSocketDisconnect
from fastapi.responses import FileResponse
from caesarfrenchllm import CaesarFrenchLLM
import uvicorn
app = FastAPI()
caesarmodel = CaesarFrenchLLM()
@app.get("/")
def caesaraihome():
return "Welcome to CaesarAI's API's and CaesarAINL."
@app.websocket("/caesarfrenchllmws")
async def caesarfrenchllmws(websocket: WebSocket):
# listen for connections
await websocket.accept()
try:
while True:
contents = await websocket.receive_json()
textresp = caesarmodel.chat(contents["message"])
final_response = {"message":textresp}
await websocket.send_json(final_response) # sends the buffer as bytes
except WebSocketDisconnect:
print("Client disconnected")
async def main():
config = uvicorn.Config("main:app", port=7860, log_level="info",host="0.0.0.0",reload=True)
server = uvicorn.Server(config)
await server.serve()
if __name__ == "__main__":
asyncio.run(main())