File size: 1,097 Bytes
2f97d42
 
 
 
 
 
 
 
 
e9e9c50
3b2e578
 
 
e9e9c50
 
2f97d42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3caa30c
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
"""FastAPI application for the RedVeil Environment."""

try:
    from openenv.core.env_server.http_server import create_app
except Exception as e:
    raise ImportError(
        "openenv is required. Install with: pip install openenv-core[core]"
    ) from e

try:
    from redveil.models import RedVeilAction, RedVeilObservation
    from redveil.server.redveil_environment import RedVeilEnvironment
except (ModuleNotFoundError, ImportError):
    from ..models import RedVeilAction, RedVeilObservation
    from .redveil_environment import RedVeilEnvironment


# Singleton: OpenEnv calls the factory on every request, so we return
# the same instance to preserve state across reset() -> step() calls.
_singleton_env = RedVeilEnvironment()


def _env_factory() -> RedVeilEnvironment:
    return _singleton_env


app = create_app(
    _env_factory,
    RedVeilAction,
    RedVeilObservation,
    env_name="redveil",
    max_concurrent_envs=4,
)


def main(host: str = "0.0.0.0", port: int = 8000):
    import uvicorn
    uvicorn.run(app, host=host, port=port)


if __name__ == "__main__":
    main()