File size: 1,504 Bytes
e75c8ce
 
 
 
 
 
4f8cf04
 
e75c8ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f8cf04
e75c8ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f8cf04
 
e75c8ce
 
 
 
4f8cf04
 
 
 
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
"""OpenEnv FastAPI server: full HTTPEnvServer + task/grader discovery routes."""

from __future__ import annotations

import os
from typing import Optional

import uvicorn
from openenv.core.env_server import create_fastapi_app

from env.cache_environment import CacheInvalidationEnvironment
from env.models import CacheAction, CacheObservation
from env.task_graders import TASK_AGENT_GRADERS
from env.tasks import TASK_MANIFEST, list_graders

_singleton: CacheInvalidationEnvironment | None = None


def _env_factory() -> CacheInvalidationEnvironment:
    global _singleton
    if _singleton is None:
        _singleton = CacheInvalidationEnvironment()
    return _singleton


app = create_fastapi_app(
    _env_factory,
    CacheAction,
    CacheObservation,
    max_concurrent_envs=1,
)


@app.get(
    "/tasks",
    tags=["Environment Info"],
    summary="List tasks and grader registration",
)
def http_list_tasks():
    return {
        "tasks": TASK_MANIFEST,
        "graders": list_graders(),
        "grader_registry": {
            name: {
                "enabled": True,
                "qualified_name": f"{fn.__module__}:{fn.__name__}",
            }
            for name, fn in TASK_AGENT_GRADERS.items()
        },
    }


def main(host: Optional[str] = None, port: Optional[int] = None) -> None:
    host = host or os.environ.get("HOST", "0.0.0.0")
    port = int(port or os.environ.get("PORT", "7860"))
    uvicorn.run(app, host=host, port=port)


if __name__ == "__main__":
    main()