Ali2206 commited on
Commit
d899239
·
verified ·
1 Parent(s): 2a02fdb

Update config.py

Browse files
Files changed (1) hide show
  1. config.py +24 -29
config.py CHANGED
@@ -9,16 +9,26 @@ import asyncio
9
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
10
  logger = logging.getLogger("TxAgentAPI")
11
 
12
- # Globals
13
- agent = None
14
- patients_collection = None
15
- analysis_collection = None
16
- alerts_collection = None
17
- users_collection = None
18
-
19
- # JWT settings (must match CPS-API)
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"]
@@ -28,28 +38,13 @@ 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",
40
- enable_finish=True,
41
- enable_rag=False,
42
- force_finish=True,
43
- enable_checker=True,
44
- step_rag_num=4,
45
- seed=42
46
- )
47
- agent.chat_prompt = (
48
- "You are a clinical assistant AI. Analyze the patient's data and provide clear clinical recommendations."
49
- )
50
- agent.init_model()
51
- logger.info("✅ TxAgent initialized")
52
-
53
  # Run async analysis task
54
  asyncio.create_task(analyze_all_patients())
55
 
 
9
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
10
  logger = logging.getLogger("TxAgentAPI")
11
 
12
+ # Initialize agent synchronously with error handling
13
+ try:
14
+ agent = TxAgent(
15
+ model_name="mims-harvard/TxAgent-T1-Llama-3.1-8B",
16
+ rag_model_name="mims-harvard/ToolRAG-T1-GTE-Qwen2-1.5B",
17
+ enable_finish=True,
18
+ enable_rag=False,
19
+ force_finish=True,
20
+ enable_checker=True,
21
+ step_rag_num=4,
22
+ seed=42
23
+ )
24
+ agent.init_model()
25
+ agent.chat_prompt = (
26
+ "You are a clinical assistant AI. Analyze the patient's data and provide clear clinical recommendations."
27
+ )
28
+ logger.info("✅ TxAgent initialized synchronously with chat_prompt: %s", agent.chat_prompt)
29
+ except Exception as e:
30
+ logger.error("❌ Failed to initialize TxAgent: %s", str(e))
31
+ raise
32
 
33
  # Initialize collections synchronously
34
  db = get_mongo_client()["cps_db"]
 
38
  alerts_collection = db["clinical_alerts"]
39
  logger.info("📡 Connected to MongoDB synchronously")
40
 
41
+ # JWT settings (must match CPS-API)
42
+ SECRET_KEY = os.getenv("SECRET_KEY", "your-secret-key")
43
+ ALGORITHM = "HS256"
44
 
45
+ def setup_app(app: FastAPI):
46
  @app.on_event("startup")
47
  async def startup_event():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  # Run async analysis task
49
  asyncio.create_task(analyze_all_patients())
50