Skip to content

Commit b3e41ae

Browse files
authored
Merge pull request meta-pytorch#196 from meta-pytorch/codinv-env-upgrade
[UPGRADE] Codinv env upgrade
2 parents 2abede4 + 136d5cb commit b3e41ae

File tree

14 files changed

+280
-50
lines changed

14 files changed

+280
-50
lines changed

examples/coding_env_inference.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
from openai import OpenAI
3737

38-
from envs.coding_env import CodeAction, CodingEnv
38+
from coding_env import CodeAction, CodingEnv
3939

4040

4141
# ---------------------------------------------------------------------------
@@ -68,6 +68,7 @@
6868
# Helpers
6969
# ---------------------------------------------------------------------------
7070

71+
7172
def extract_python_code(text: str) -> str:
7273
"""Extract the first Python code block from the model output."""
7374

@@ -115,6 +116,7 @@ def build_initial_prompt(task: str) -> str:
115116
# Gameplay
116117
# ---------------------------------------------------------------------------
117118

119+
118120
def solve_coding_task(
119121
env: CodingEnv,
120122
client: OpenAI,
@@ -152,9 +154,7 @@ def solve_coding_task(
152154

153155
transcripts.append(
154156
(
155-
f"Step {step} | exit_code={obs.exit_code}\n"
156-
f"stdout:\n{obs.stdout}\n"
157-
f"stderr:\n{obs.stderr}\n"
157+
f"Step {step} | exit_code={obs.exit_code}\nstdout:\n{obs.stdout}\nstderr:\n{obs.stderr}\n"
158158
)
159159
)
160160

@@ -192,6 +192,7 @@ def solve_coding_task(
192192
# Entrypoint
193193
# ---------------------------------------------------------------------------
194194

195+
195196
def main() -> None:
196197
if not API_KEY:
197198
raise SystemExit(
@@ -222,5 +223,3 @@ def main() -> None:
222223

223224
if __name__ == "__main__":
224225
main()
225-
226-

src/envs/coding_env/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: Coding Environment Server
33
emoji: 💻
4-
colorFrom: '#007ACC'
5-
colorTo: '#1E1E1E'
4+
colorFrom: blue
5+
colorTo: blue
66
sdk: docker
77
pinned: false
88
app_port: 8000

src/envs/coding_env/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
"""Coding Environment - A Python code execution environment."""
88

9-
from .coding_env_client import CodingEnv
9+
from .client import CodingEnv
1010
from .models import CodeAction, CodeObservation, CodeState
1111

12-
__all__ = ["CodeAction", "CodeObservation", "CodeState", "CodingEnv"]
12+
__all__ = ["CodingEnv", "CodeAction", "CodeObservation", "CodeState"]

src/envs/coding_env/coding_env_client.py renamed to src/envs/coding_env/client.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@
1313

1414
from __future__ import annotations
1515

16-
from typing import Optional, TYPE_CHECKING
16+
from openenv_core.client_types import StepResult
1717

18-
from core.client_types import StepResult
18+
from openenv_core.http_env_client import HTTPEnvClient
1919

20-
from core.http_env_client import HTTPEnvClient
21-
22-
from .models import CodeAction, CodeObservation, CodeState
23-
24-
if TYPE_CHECKING:
25-
from core.containers.runtime import ContainerProvider
20+
from coding_env.models import CodeAction, CodeObservation, CodeState
2621

2722

2823
class CodingEnv(HTTPEnvClient[CodeAction, CodeObservation]):

src/envs/coding_env/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
from __future__ import annotations
88

99
from dataclasses import dataclass
10-
from typing import Any, Optional
1110

12-
from core.env_server import Action, Observation, State
11+
from openenv_core.env_server.interfaces import Action, Observation, State
1312

1413

1514
@dataclass

src/envs/coding_env/openenv.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: coding_env
2+
version: "0.1.0"
3+
description: "Coding environment for OpenEnv"
4+
action: CodingAction
5+
observation: CodingObservation

src/envs/coding_env/pyproject.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[build-system]
2+
requires = ["setuptools>=45", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "openenv-coding_env"
7+
version = "0.1.0"
8+
description = "Coding Environment for OpenEnv"
9+
requires-python = ">=3.10"
10+
dependencies = [
11+
"openenv-core>=0.1.0",
12+
"fastapi>=0.115.0",
13+
"pydantic>=2.0.0",
14+
"uvicorn>=0.24.0",
15+
"requests>=2.31.0",
16+
"smolagents>=1.22.0,<2",
17+
]
18+
19+
[project.optional-dependencies]
20+
dev = [
21+
"pytest>=8.0.0",
22+
"pytest-cov>=4.0.0",
23+
"ipykernel>=6.29.5",
24+
]
25+
26+
[project.scripts]
27+
server = "coding_env.server.app:main"
28+
29+
30+
[tool.setuptools]
31+
packages = ["coding_env", "coding_env.server"]
32+
package-dir = { "coding_env" = ".", "coding_env.server" = "server" }
33+
34+
[tool.setuptools.package-data]
35+
coding_env = ["**/*.yaml", "**/*.yml"]
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
# Copyright (c) Meta Platforms, Inc. and affiliates.
2-
# All rights reserved.
3-
#
4-
# This source code is licensed under the BSD-style license found in the
5-
# LICENSE file in the root directory of this source tree.
1+
# Base image
2+
FROM python:3.11-slim
63

7-
# Use the standard openenv base image
8-
# Built from: docker build -t openenv-base:latest -f src/core/containers/images/Dockerfile .
9-
# In GitHub Actions, this is overridden to use the GHCR base image
10-
ARG BASE_IMAGE=openenv-base:latest
11-
FROM ${BASE_IMAGE}
4+
# Set working directory
5+
WORKDIR /app/env
126

13-
# Copy only what's needed for this environment
14-
COPY src/core/ /app/src/core/
15-
COPY src/envs/coding_env/ /app/src/envs/coding_env/
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y \
9+
git \
10+
&& rm -rf /var/lib/apt/lists/*
1611

17-
# Copy README for web interface documentation
18-
COPY src/envs/coding_env/README.md /app/README.md
12+
# Copy environment files
13+
COPY . .
1914

20-
# Health check
21-
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
22-
CMD curl -f http://localhost:8000/health || exit 1
15+
# Install Python dependencies
16+
RUN pip install --no-cache-dir -e .
2317

24-
# Run the FastAPI server
25-
CMD ["uvicorn", "envs.coding_env.server.app:app", "--host", "0.0.0.0", "--port", "8000"]
18+
# Expose port
19+
EXPOSE 8000
20+
21+
# Set environment variables
22+
ENV PYTHONUNBUFFERED=1
23+
ENV ENABLE_WEB_INTERFACE=true
24+
25+
# Run the server
26+
CMD ["python", "-m", "uvicorn", "coding_env.server.app:app", "--host", "0.0.0.0", "--port", "8000"]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Use the standard openenv base image
8+
# Built from: docker build -t openenv-base:latest -f src/core/containers/images/Dockerfile .
9+
# In GitHub Actions, this is overridden to use the GHCR base image
10+
ARG BASE_IMAGE=openenv-base:latest
11+
FROM ${BASE_IMAGE}
12+
13+
# Copy only what's needed for this environment
14+
COPY src/core/ /app/src/core/
15+
COPY src/envs/coding_env/ /app/src/envs/coding_env/
16+
17+
# Copy README for web interface documentation
18+
COPY src/envs/coding_env/README.md /app/README.md
19+
20+
# Health check
21+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
22+
CMD curl -f http://localhost:8000/health || exit 1
23+
24+
# Run the FastAPI server
25+
CMD ["uvicorn", "envs.coding_env.server.app:app", "--host", "0.0.0.0", "--port", "8000"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
"""Coding environment server components."""
8+
9+
from .python_codeact_env import PythonCodeActEnv
10+
11+
__all__ = ["PythonCodeActEnv"]

0 commit comments

Comments
 (0)