File size: 1,375 Bytes
ee117a1
 
 
 
 
 
 
 
 
 
 
 
 
 
4bca719
 
 
ee117a1
4bca719
c888aa7
ee117a1
 
 
 
423cd48
ee117a1
 
 
 
 
 
 
 
2c2ad37
 
ee117a1
2c2ad37
ee117a1
2c2ad37
ee117a1
 
 
 
423cd48
2c2ad37
 
 
 
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
"""
server/app.py — FastAPI server for the Medical Diagnostic Environment.

This exposes the environment over WebSocket and HTTP using OpenEnv's built-in
create_fastapi_app helper. One line of meaningful code!

The helper automatically creates:
- /ws endpoint for WebSocket connections (stateful, for training)
- /reset, /step, /state endpoints (stateless, for testing)
- /health endpoint (for Docker health checks)
- /docs endpoint (auto-generated OpenAPI documentation)
"""

from openenv.core.env_server import create_fastapi_app
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from models import DiagnosticAction, PatientObservation
from .environment import MedicalDiagnosticEnvironment


# Create FastAPI app with all endpoints
app = create_fastapi_app(
    MedicalDiagnosticEnvironment,  # Pass the class, not an instance
    DiagnosticAction,
    PatientObservation,
    max_concurrent_envs=100,  # Support up to 100 parallel training sessions
)

# Optional: Add custom middleware or endpoints here if needed
# (Most common use cases are already handled by create_fastapi_app)

def main() -> None:
    """Start the FastAPI server."""
    import uvicorn

    uvicorn.run(
        app,
        host="0.0.0.0",
        port=8000,
        workers=4,
        reload=False,
    )


if __name__ == "__main__":
    main()