Update config.py
Browse files
config.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import os
|
2 |
import logging
|
3 |
-
import asyncio
|
4 |
from fastapi import FastAPI
|
5 |
from txagent.txagent import TxAgent
|
6 |
from db.mongo import get_mongo_client
|
|
|
7 |
|
8 |
# Logging
|
9 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
@@ -20,13 +20,20 @@ users_collection = None
|
|
20 |
SECRET_KEY = os.getenv("SECRET_KEY", "your-secret-key")
|
21 |
ALGORITHM = "HS256"
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def setup_app(app: FastAPI):
|
24 |
-
global agent
|
25 |
|
26 |
@app.on_event("startup")
|
27 |
async def startup_event():
|
28 |
-
global agent
|
29 |
-
|
30 |
agent = TxAgent(
|
31 |
model_name="mims-harvard/TxAgent-T1-Llama-3.1-8B",
|
32 |
rag_model_name="mims-harvard/ToolRAG-T1-GTE-Qwen2-1.5B",
|
@@ -43,17 +50,11 @@ def setup_app(app: FastAPI):
|
|
43 |
agent.init_model()
|
44 |
logger.info("✅ TxAgent initialized")
|
45 |
|
46 |
-
|
47 |
-
users_collection = db["users"]
|
48 |
-
patients_collection = db["patients"]
|
49 |
-
analysis_collection = db["patient_analysis_results"]
|
50 |
-
alerts_collection = db["clinical_alerts"]
|
51 |
-
logger.info("📡 Connected to MongoDB")
|
52 |
-
|
53 |
asyncio.create_task(analyze_all_patients())
|
54 |
|
55 |
async def analyze_all_patients():
|
56 |
-
from analysis import analyze_patient
|
57 |
patients = await patients_collection.find({}).to_list(length=None)
|
58 |
for patient in patients:
|
59 |
await analyze_patient(patient)
|
|
|
1 |
import os
|
2 |
import logging
|
|
|
3 |
from fastapi import FastAPI
|
4 |
from txagent.txagent import TxAgent
|
5 |
from db.mongo import get_mongo_client
|
6 |
+
import asyncio
|
7 |
|
8 |
# Logging
|
9 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
|
|
20 |
SECRET_KEY = os.getenv("SECRET_KEY", "your-secret-key")
|
21 |
ALGORITHM = "HS256"
|
22 |
|
23 |
+
# Initialize collections synchronously
|
24 |
+
db = get_mongo_client()["cps_db"]
|
25 |
+
users_collection = db["users"]
|
26 |
+
patients_collection = db["patients"]
|
27 |
+
analysis_collection = db["patient_analysis_results"]
|
28 |
+
alerts_collection = db["clinical_alerts"]
|
29 |
+
logger.info("📡 Connected to MongoDB synchronously")
|
30 |
+
|
31 |
def setup_app(app: FastAPI):
|
32 |
+
global agent
|
33 |
|
34 |
@app.on_event("startup")
|
35 |
async def startup_event():
|
36 |
+
global agent
|
|
|
37 |
agent = TxAgent(
|
38 |
model_name="mims-harvard/TxAgent-T1-Llama-3.1-8B",
|
39 |
rag_model_name="mims-harvard/ToolRAG-T1-GTE-Qwen2-1.5B",
|
|
|
50 |
agent.init_model()
|
51 |
logger.info("✅ TxAgent initialized")
|
52 |
|
53 |
+
# Run async analysis task
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
asyncio.create_task(analyze_all_patients())
|
55 |
|
56 |
async def analyze_all_patients():
|
57 |
+
from analysis import analyze_patient
|
58 |
patients = await patients_collection.find({}).to_list(length=None)
|
59 |
for patient in patients:
|
60 |
await analyze_patient(patient)
|