Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from fastapi import FastAPI
|
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
4 |
from config import setup_app, agent, logger, patients_collection, analysis_collection, users_collection
|
5 |
from endpoints import create_router
|
|
|
6 |
|
7 |
# Create the FastAPI app
|
8 |
app = FastAPI(title="TxAgent API", version="2.6.0")
|
@@ -16,6 +17,16 @@ app.add_middleware(
|
|
16 |
allow_headers=["*"]
|
17 |
)
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
# Setup the app (e.g., initialize globals, startup event)
|
20 |
setup_app(app)
|
21 |
|
|
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
4 |
from config import setup_app, agent, logger, patients_collection, analysis_collection, users_collection
|
5 |
from endpoints import create_router
|
6 |
+
from fastapi import WebSocket, WebSocketDisconnect
|
7 |
|
8 |
# Create the FastAPI app
|
9 |
app = FastAPI(title="TxAgent API", version="2.6.0")
|
|
|
17 |
allow_headers=["*"]
|
18 |
)
|
19 |
|
20 |
+
@app.websocket("/ws/notifications")
|
21 |
+
async def websocket_endpoint(websocket: WebSocket):
|
22 |
+
await websocket.accept()
|
23 |
+
try:
|
24 |
+
while True:
|
25 |
+
# Keep connection alive
|
26 |
+
await websocket.receive_text()
|
27 |
+
except WebSocketDisconnect:
|
28 |
+
logger.info("Client disconnected")
|
29 |
+
|
30 |
# Setup the app (e.g., initialize globals, startup event)
|
31 |
setup_app(app)
|
32 |
|