File size: 1,246 Bytes
62d835c
 
f126604
5795f83
7cd1148
a4ccb56
f275c80
62d835c
f275c80
f126604
62d835c
f126604
 
046255d
ac9926b
 
 
f126604
 
a4ccb56
 
 
 
 
 
 
 
 
 
62d835c
 
1e0df14
046255d
5795f83
7cd1148
 
ac9926b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from config import setup_app, agent, logger, patients_collection, analysis_collection, users_collection, chats_collection, notifications_collection
from endpoints import create_router
from fastapi import WebSocket, WebSocketDisconnect

# Create the FastAPI app
app = FastAPI(title="TxAgent API", version="2.6.0")

# Apply CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"]
)

@app.websocket("/ws/notifications")
async def websocket_endpoint(websocket: WebSocket):
    await websocket.accept()
    try:
        while True:
            # Keep connection alive
            await websocket.receive_text()
    except WebSocketDisconnect:
        logger.info("Client disconnected")

# Setup the app (e.g., initialize globals, startup event)
setup_app(app)

# Create and include the router with dependencies
router = create_router(agent, logger, patients_collection, analysis_collection, users_collection, chats_collection, notifications_collection)
app.include_router(router)

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)