-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (46 loc) · 2.16 KB
/
Copy pathmain.py
File metadata and controls
62 lines (46 loc) · 2.16 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from __future__ import annotations
import argparse
import json
from pathlib import Path
import sys
from medexplainer_pro.agent import MedAgent
from medexplainer_pro.models import AgentConfig
ROOT = Path(__file__).resolve().parent
SAMPLE_PATIENT = ROOT / "samples" / "synthetic_patient.json"
SAMPLE_HISTORY = ROOT / "samples" / "synthetic_patient_history.json"
def _read_json(path: str | Path) -> dict | list:
return json.loads(Path(path).read_text(encoding="utf-8"))
def _read_text(path: str | Path) -> str:
return Path(path).read_text(encoding="utf-8")
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="MedExplainer Pro unified agent runner")
parser.add_argument("--demo", action="store_true", help="Run the built-in synthetic demo patient.")
parser.add_argument("--history-demo", action="store_true", help="Run the built-in synthetic longitudinal trend demo.")
parser.add_argument("--patient-json", help="Path to a simplified FHIR-style patient JSON payload.")
parser.add_argument("--fhir-json", help="Path to a FHIR resource JSON payload.")
parser.add_argument("--report-text", help="Path to a plain-text lab report.")
parser.add_argument("--question", help="Optional user question for the reasoning layer.")
return parser
def main() -> None:
args = build_parser().parse_args()
config = AgentConfig.from_env()
if (args.demo or args.history_demo) and not config.llm.enabled:
print(
"Demo note: running in deterministic fallback mode (no active LLM provider). "
"Set GROQ_API_KEY or OPENAI_API_KEY to demonstrate AI reasoning.",
file=sys.stderr,
)
if args.patient_json:
payload = _read_json(args.patient_json)
elif args.fhir_json:
payload = _read_json(args.fhir_json)
elif args.report_text:
payload = _read_text(args.report_text)
elif args.history_demo:
payload = _read_json(SAMPLE_HISTORY)
else:
payload = _read_json(SAMPLE_PATIENT)
result = MedAgent(config=config).run(payload, user_question=args.question)
print(json.dumps(result, indent=2))
if __name__ == "__main__":
main()