File size: 1,228 Bytes
453233a
f707fd4
453233a
 
 
 
 
 
 
 
 
 
 
 
 
f707fd4
453233a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""FastAPI application for Red Button (Shutdown-Gym).

Wires :class:`server.shutdown_environment.ShutdownGymEnvironment` to
:func:`openenv.core.env_server.http_server.create_app` per PROJECT.md
Section 10. The factory pattern (passing the class, not an instance) is what
the framework expects so each WebSocket session gets its own environment.

Usage::

    uvicorn server.app:app --host 0.0.0.0 --port 8000

Env vars:

* ``MAX_CONCURRENT_ENVS`` — concurrent WebSocket sessions (default 16, per PROJECT.md Section 19.3).
* ``PORT`` — server port (default 8000).
"""

from __future__ import annotations

import os

from openenv.core.env_server.http_server import create_app

from red_button.models import ShutdownAction, ShutdownObservation
from server.shutdown_environment import ShutdownGymEnvironment

app = create_app(
    ShutdownGymEnvironment,
    ShutdownAction,
    ShutdownObservation,
    env_name="red_button",
    max_concurrent_envs=int(os.getenv("MAX_CONCURRENT_ENVS", "16")),
)


def main() -> None:
    """Run the server with uvicorn (used by ``python -m server.app``)."""
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", "8000")))


if __name__ == "__main__":
    main()