uvpatel7271 commited on
Commit
c1b10f3
·
verified ·
1 Parent(s): 96d51f5

Upload folder using huggingface_hub

Browse files
Dockerfile CHANGED
@@ -1,33 +1,25 @@
1
- FROM python:3.11-slim
 
 
 
 
 
 
 
2
 
3
  WORKDIR /app
4
 
5
- # Install system dependencies
6
  RUN apt-get update && apt-get install -y --no-install-recommends \
7
- gcc \
8
- git \
9
  curl \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- # Install Python dependencies
13
- COPY requirements.txt /app/server/requirements.txt
14
- RUN pip install --no-cache-dir -r /app/server/requirements.txt
15
-
16
- # Copy the self-contained server package
17
- COPY . /app/server
18
 
19
- # Set environment variables
20
- ENV PYTHONUNBUFFERED=1
21
- ENV HOST=0.0.0.0
22
- ENV PORT=8000
23
- ENV WORKERS=1
24
- ENV MAX_CONCURRENT_ENVS=16
25
 
26
- # Health check
27
- HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
28
- CMD curl -f http://localhost:${PORT}/health || exit 1
29
 
30
- # Run FastAPI app
31
- EXPOSE ${PORT}
32
  ENV ENABLE_WEB_INTERFACE=true
33
  CMD ["python", "-m", "server.app"]
 
1
+ FROM python:3.10-slim
2
+
3
+ ENV PYTHONDONTWRITEBYTECODE=1 \
4
+ PYTHONUNBUFFERED=1 \
5
+ HOST=0.0.0.0 \
6
+ PORT=8000 \
7
+ WORKERS=1 \
8
+ MAX_CONCURRENT_ENVS=16
9
 
10
  WORKDIR /app
11
 
 
12
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
 
13
  curl \
14
  && rm -rf /var/lib/apt/lists/*
15
 
16
+ COPY requirements.txt ./
17
+ RUN pip install --no-cache-dir --upgrade pip && \
18
+ pip install --no-cache-dir -r requirements.txt
 
 
 
19
 
20
+ COPY . .
 
 
 
 
 
21
 
22
+ EXPOSE 8000
 
 
23
 
 
 
24
  ENV ENABLE_WEB_INTERFACE=true
25
  CMD ["python", "-m", "server.app"]
client.py CHANGED
@@ -1,15 +1,31 @@
1
- """Client for the Python code review environment."""
2
-
3
  from __future__ import annotations
4
 
 
5
  from typing import Dict
6
 
7
  from compat import install_openenv_fastmcp_compat
8
 
9
  install_openenv_fastmcp_compat()
10
 
11
- from openenv.core import EnvClient
12
- from openenv.core.client_types import StepResult
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  from models import (
15
  HistoryEntry,
 
1
+ """Client for the Python code review environment."""
2
+
3
  from __future__ import annotations
4
 
5
+ from dataclasses import dataclass
6
  from typing import Dict
7
 
8
  from compat import install_openenv_fastmcp_compat
9
 
10
  install_openenv_fastmcp_compat()
11
 
12
+ try:
13
+ from openenv.core import EnvClient
14
+ from openenv.core.client_types import StepResult
15
+ except Exception: # pragma: no cover
16
+ class EnvClient: # type: ignore[override]
17
+ """Lightweight fallback placeholder when openenv-core is unavailable."""
18
+
19
+ def __class_getitem__(cls, item): # type: ignore[no-untyped-def]
20
+ return cls
21
+
22
+ @dataclass
23
+ class StepResult: # type: ignore[override]
24
+ """Fallback step result used for import safety."""
25
+
26
+ observation: object
27
+ reward: object = None
28
+ done: bool = False
29
 
30
  from models import (
31
  HistoryEntry,
compat.py CHANGED
@@ -1,92 +1,128 @@
1
- """Compatibility helpers for OpenEnv and FastMCP runtime drift."""
2
 
3
  from __future__ import annotations
4
 
5
- import sys
6
- import types
7
- from typing import Any, Optional
8
 
 
 
9
 
10
- def install_openenv_fastmcp_compat() -> None:
11
- """Patch FastMCP API differences so older OpenEnv builds keep importing."""
12
- try:
13
- import fastmcp # type: ignore
14
- except Exception:
15
- return
16
-
17
- try:
18
- if not hasattr(fastmcp, "Client"):
19
- class CompatClient:
20
- """Minimal async MCP client used for legacy OpenEnv imports."""
21
-
22
- def __init__(self, *args: Any, **kwargs: Any) -> None:
23
- self.args = args
24
- self.kwargs = kwargs
25
-
26
- async def __aenter__(self) -> "CompatClient":
27
- return self
28
-
29
- async def __aexit__(self, exc_type: Any, exc: Any, tb: Any) -> bool:
30
- return False
31
-
32
- async def list_tools(self) -> list[Any]:
33
- return []
34
-
35
- async def call_tool(self, tool_name: str, arguments: dict[str, Any]) -> Any:
36
- raise RuntimeError(
37
- f"MCP client compatibility mode cannot call tool: {tool_name}"
38
- )
39
-
40
- fastmcp.Client = CompatClient # type: ignore[attr-defined]
41
- except Exception:
42
- pass
43
-
44
- try:
45
- client_pkg = sys.modules.get("fastmcp.client")
46
- if client_pkg is None:
47
- client_pkg = types.ModuleType("fastmcp.client")
48
- sys.modules["fastmcp.client"] = client_pkg
49
-
50
- client_mod = sys.modules.get("fastmcp.client.client")
51
- if client_mod is None:
52
- client_mod = types.ModuleType("fastmcp.client.client")
53
- sys.modules["fastmcp.client.client"] = client_mod
54
 
55
- if not hasattr(client_mod, "CallToolResult"):
56
- class CallToolResult:
57
- """Compatibility container for legacy OpenEnv response handling."""
58
 
59
- def __init__(
60
- self,
61
- content: Any = None,
62
- structured_content: Any = None,
63
- meta: Any = None,
64
- data: Any = None,
65
- is_error: bool = False,
66
- ) -> None:
67
- self.content = content
68
- self.structured_content = structured_content
69
- self.meta = meta
70
- self.data = data
71
- self.is_error = is_error
72
-
73
- client_mod.CallToolResult = CallToolResult
74
-
75
- client_pkg.client = client_mod # type: ignore[attr-defined]
76
- except Exception:
77
- pass
78
-
79
-
80
- install_openenv_fastmcp_compat()
81
-
82
-
83
- try:
84
- from openenv.core.env_server.http_server import create_app as openenv_create_app
85
- from openenv.core.env_server.interfaces import Environment
86
- from openenv.core.env_server.types import Action, Observation, State
87
- except Exception as exc: # pragma: no cover
88
- raise RuntimeError(f"OpenEnv runtime import failed after compatibility patch: {exc}") from exc
89
-
90
-
91
- create_app = openenv_create_app
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Lightweight OpenEnv-compatible helpers for local and container builds."""
2
 
3
  from __future__ import annotations
4
 
5
+ from abc import ABC, abstractmethod
6
+ from typing import Any, Generic, Optional, TypeVar
 
7
 
8
+ from fastapi import FastAPI, HTTPException
9
+ from pydantic import BaseModel, ConfigDict, Field
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ ActT = TypeVar("ActT", bound="Action")
13
+ ObsT = TypeVar("ObsT", bound="Observation")
14
+ StateT = TypeVar("StateT", bound="State")
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ def install_openenv_fastmcp_compat() -> None:
18
+ """Compatibility hook retained for callers; no-op in the local shim."""
19
+ return None
20
+
21
+
22
+ class Action(BaseModel):
23
+ """Minimal action base model."""
24
+
25
+ model_config = ConfigDict(extra="forbid", validate_assignment=True, arbitrary_types_allowed=True)
26
+ metadata: dict[str, Any] = Field(default_factory=dict)
27
+
28
+
29
+ class Observation(BaseModel):
30
+ """Minimal observation base model."""
31
+
32
+ model_config = ConfigDict(extra="forbid", validate_assignment=True, arbitrary_types_allowed=True)
33
+ done: bool = False
34
+ reward: bool | int | float | None = None
35
+ metadata: dict[str, Any] = Field(default_factory=dict)
36
+
37
+
38
+ class State(BaseModel):
39
+ """Minimal state base model."""
40
+
41
+ model_config = ConfigDict(extra="allow", validate_assignment=True, arbitrary_types_allowed=True)
42
+ episode_id: Optional[str] = None
43
+ step_count: int = Field(default=0, ge=0)
44
+
45
+
46
+ class Environment(ABC, Generic[ActT, ObsT, StateT]):
47
+ """Minimal environment interface compatible with this project."""
48
+
49
+ SUPPORTS_CONCURRENT_SESSIONS: bool = False
50
+
51
+ def __init__(self, transform: Any = None, rubric: Any = None) -> None:
52
+ self.transform = transform
53
+ self.rubric = rubric
54
+
55
+ @abstractmethod
56
+ def reset(self, seed: Optional[int] = None, episode_id: Optional[str] = None, **kwargs: Any) -> ObsT:
57
+ """Reset the environment."""
58
+
59
+ @abstractmethod
60
+ def step(self, action: ActT, timeout_s: Optional[float] = None, **kwargs: Any) -> ObsT:
61
+ """Execute one step."""
62
+
63
+ @property
64
+ @abstractmethod
65
+ def state(self) -> StateT:
66
+ """Return current state."""
67
+
68
+ def _reset_rubric(self) -> None:
69
+ """Compatibility no-op."""
70
+ return None
71
+
72
+
73
+ def create_app(
74
+ env_cls: type[Environment[Any, Any, Any]],
75
+ action_model: type[BaseModel],
76
+ observation_model: type[BaseModel],
77
+ max_concurrent_envs: int = 1,
78
+ ) -> FastAPI:
79
+ """Create a minimal FastAPI app exposing reset/step/state/schema endpoints."""
80
+ app = FastAPI(title="python_code_review_env")
81
+ env = env_cls()
82
+ del observation_model, max_concurrent_envs
83
+
84
+ @app.post("/reset")
85
+ def reset(payload: dict[str, Any] | None = None) -> dict[str, Any]:
86
+ try:
87
+ observation = env.reset(**(payload or {}))
88
+ dumped = observation.model_dump()
89
+ return {
90
+ "observation": dumped,
91
+ "reward": dumped.get("reward"),
92
+ "done": dumped.get("done", False),
93
+ }
94
+ except Exception as exc:
95
+ raise HTTPException(status_code=500, detail=str(exc)) from exc
96
+
97
+ @app.post("/step")
98
+ def step(payload: dict[str, Any]) -> dict[str, Any]:
99
+ try:
100
+ action_payload = payload.get("action", payload)
101
+ timeout_s = payload.get("timeout_s")
102
+ action = action_model(**action_payload)
103
+ observation = env.step(action, timeout_s=timeout_s)
104
+ dumped = observation.model_dump()
105
+ return {
106
+ "observation": dumped,
107
+ "reward": dumped.get("reward"),
108
+ "done": dumped.get("done", False),
109
+ }
110
+ except Exception as exc:
111
+ raise HTTPException(status_code=500, detail=str(exc)) from exc
112
+
113
+ @app.get("/state")
114
+ def state() -> dict[str, Any]:
115
+ try:
116
+ return env.state.model_dump()
117
+ except Exception as exc:
118
+ raise HTTPException(status_code=500, detail=str(exc)) from exc
119
+
120
+ @app.get("/schema")
121
+ def schema() -> dict[str, Any]:
122
+ return {
123
+ "action": action_model.model_json_schema(),
124
+ "observation": observation_model.model_json_schema(),
125
+ "state": env.state.__class__.model_json_schema(),
126
+ }
127
+
128
+ return app
openenv_python_env.egg-info/PKG-INFO CHANGED
@@ -3,10 +3,10 @@ Name: openenv-python_env
3
  Version: 0.2.0
4
  Summary: Deterministic Python code review and repair benchmark environment for OpenEnv
5
  Requires-Python: >=3.10
6
- Requires-Dist: openenv-core[core]>=0.2.2
7
  Requires-Dist: fastapi>=0.115.0
8
  Requires-Dist: uvicorn>=0.30.0
9
  Requires-Dist: openai>=1.40.0
 
10
  Requires-Dist: pytest>=8.0.0
11
  Provides-Extra: dev
12
  Requires-Dist: pytest>=8.0.0; extra == "dev"
 
3
  Version: 0.2.0
4
  Summary: Deterministic Python code review and repair benchmark environment for OpenEnv
5
  Requires-Python: >=3.10
 
6
  Requires-Dist: fastapi>=0.115.0
7
  Requires-Dist: uvicorn>=0.30.0
8
  Requires-Dist: openai>=1.40.0
9
+ Requires-Dist: pydantic>=2.0.0
10
  Requires-Dist: pytest>=8.0.0
11
  Provides-Extra: dev
12
  Requires-Dist: pytest>=8.0.0; extra == "dev"
openenv_python_env.egg-info/SOURCES.txt CHANGED
@@ -1,10 +1,10 @@
1
  README.md
 
 
 
 
 
2
  pyproject.toml
3
- ./__init__.py
4
- ./client.py
5
- ./compat.py
6
- ./inference.py
7
- ./models.py
8
  openenv_python_env.egg-info/PKG-INFO
9
  openenv_python_env.egg-info/SOURCES.txt
10
  openenv_python_env.egg-info/dependency_links.txt
@@ -15,12 +15,21 @@ server/__init__.py
15
  server/app.py
16
  server/code_review_env_environment.py
17
  server/code_review_environment.py
 
18
  server/env.py
19
  server/env_safe.py
20
  server/grading.py
 
21
  server/python_env_environment.py
22
  server/static_review.py
23
  server/task_bank.py
 
 
 
 
 
 
 
24
  tests/test_api.py
25
  tests/test_environment.py
26
  tests/test_examples.py
 
1
  README.md
2
+ __init__.py
3
+ client.py
4
+ compat.py
5
+ inference.py
6
+ models.py
7
  pyproject.toml
 
 
 
 
 
8
  openenv_python_env.egg-info/PKG-INFO
9
  openenv_python_env.egg-info/SOURCES.txt
10
  openenv_python_env.egg-info/dependency_links.txt
 
15
  server/app.py
16
  server/code_review_env_environment.py
17
  server/code_review_environment.py
18
+ server/compat.py
19
  server/env.py
20
  server/env_safe.py
21
  server/grading.py
22
+ server/models.py
23
  server/python_env_environment.py
24
  server/static_review.py
25
  server/task_bank.py
26
+ server/graders/__init__.py
27
+ server/graders/common.py
28
+ server/graders/optimization.py
29
+ server/graders/pytest_runner.py
30
+ server/graders/syntax.py
31
+ server/tasks/__init__.py
32
+ server/tasks/task_bank.py
33
  tests/test_api.py
34
  tests/test_environment.py
35
  tests/test_examples.py
openenv_python_env.egg-info/entry_points.txt CHANGED
@@ -1,2 +1,2 @@
1
  [console_scripts]
2
- server = python_env.server.app:main
 
1
  [console_scripts]
2
+ server = server.app:main
openenv_python_env.egg-info/requires.txt CHANGED
@@ -1,7 +1,7 @@
1
- openenv-core[core]>=0.2.2
2
  fastapi>=0.115.0
3
  uvicorn>=0.30.0
4
  openai>=1.40.0
 
5
  pytest>=8.0.0
6
 
7
  [dev]
 
 
1
  fastapi>=0.115.0
2
  uvicorn>=0.30.0
3
  openai>=1.40.0
4
+ pydantic>=2.0.0
5
  pytest>=8.0.0
6
 
7
  [dev]
openenv_python_env.egg-info/top_level.txt CHANGED
@@ -1 +1 @@
1
- python_env
 
1
+ server
pyproject.toml CHANGED
@@ -2,18 +2,18 @@
2
  requires = ["setuptools>=45", "wheel"]
3
  build-backend = "setuptools.build_meta"
4
 
5
- [project]
6
- name = "openenv-python_env"
7
- version = "0.2.0"
8
- description = "Deterministic Python code review and repair benchmark environment for OpenEnv"
9
- requires-python = ">=3.10"
10
- dependencies = [
11
- "openenv-core[core]>=0.2.2",
12
- "fastapi>=0.115.0",
13
- "uvicorn>=0.30.0",
14
- "openai>=1.40.0",
15
- "pytest>=8.0.0",
16
- ]
17
 
18
  [project.optional-dependencies]
19
  dev = [
@@ -21,13 +21,12 @@ dev = [
21
  "pytest-cov>=4.0.0",
22
  ]
23
 
24
- [project.scripts]
25
- server = "python_env.server.app:main"
26
-
27
- [tool.setuptools]
28
- include-package-data = true
29
- packages = ["python_env", "python_env.server"]
30
- package-dir = { "python_env" = ".", "python_env.server" = "server" }
31
 
32
  [tool.pytest.ini_options]
33
  testpaths = ["tests"]
 
2
  requires = ["setuptools>=45", "wheel"]
3
  build-backend = "setuptools.build_meta"
4
 
5
+ [project]
6
+ name = "openenv-python_env"
7
+ version = "0.2.0"
8
+ description = "Deterministic Python code review and repair benchmark environment for OpenEnv"
9
+ requires-python = ">=3.10"
10
+ dependencies = [
11
+ "fastapi>=0.115.0",
12
+ "uvicorn>=0.30.0",
13
+ "openai>=1.40.0",
14
+ "pydantic>=2.0.0",
15
+ "pytest>=8.0.0",
16
+ ]
17
 
18
  [project.optional-dependencies]
19
  dev = [
 
21
  "pytest-cov>=4.0.0",
22
  ]
23
 
24
+ [project.scripts]
25
+ server = "server.app:main"
26
+
27
+ [tool.setuptools]
28
+ include-package-data = true
29
+ packages = ["server", "server.graders", "server.tasks"]
 
30
 
31
  [tool.pytest.ini_options]
32
  testpaths = ["tests"]
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi>=0.115,<1.0
2
+ uvicorn[standard]>=0.30,<1.0
3
+ pydantic>=2.0,<3.0
4
+ openai>=1.0,<3.0
5
+ pytest>=8.0,<9.0
server/Dockerfile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ ENV PYTHONDONTWRITEBYTECODE=1 \
4
+ PYTHONUNBUFFERED=1 \
5
+ HOST=0.0.0.0 \
6
+ PORT=8000 \
7
+ WORKERS=1 \
8
+ MAX_CONCURRENT_ENVS=16
9
+
10
+ WORKDIR /app
11
+
12
+ # Install system dependencies
13
+ RUN apt-get update && apt-get install -y --no-install-recommends \
14
+ curl \
15
+ && rm -rf /var/lib/apt/lists/*
16
+
17
+ # Install Python dependencies
18
+ COPY requirements.txt ./
19
+ RUN pip install --no-cache-dir --upgrade pip && \
20
+ pip install --no-cache-dir -r requirements.txt
21
+
22
+ # Copy the self-contained server package
23
+ COPY . /app/server
24
+
25
+ # Run FastAPI app
26
+ EXPOSE ${PORT}
27
+ CMD ["python", "-m", "server.app"]
uv.lock CHANGED
The diff for this file is too large to render. See raw diff