Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions examples/coding_env_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

from openai import OpenAI

from envs.coding_env import CodeAction, CodingEnv
from coding_env import CodeAction, CodingEnv


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -68,6 +68,7 @@
# Helpers
# ---------------------------------------------------------------------------


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

Expand Down Expand Up @@ -115,6 +116,7 @@ def build_initial_prompt(task: str) -> str:
# Gameplay
# ---------------------------------------------------------------------------


def solve_coding_task(
env: CodingEnv,
client: OpenAI,
Expand Down Expand Up @@ -152,9 +154,7 @@ def solve_coding_task(

transcripts.append(
(
f"Step {step} | exit_code={obs.exit_code}\n"
f"stdout:\n{obs.stdout}\n"
f"stderr:\n{obs.stderr}\n"
f"Step {step} | exit_code={obs.exit_code}\nstdout:\n{obs.stdout}\nstderr:\n{obs.stderr}\n"
)
)

Expand Down Expand Up @@ -192,6 +192,7 @@ def solve_coding_task(
# Entrypoint
# ---------------------------------------------------------------------------


def main() -> None:
if not API_KEY:
raise SystemExit(
Expand Down Expand Up @@ -222,5 +223,3 @@ def main() -> None:

if __name__ == "__main__":
main()


4 changes: 2 additions & 2 deletions src/envs/coding_env/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Coding Environment Server
emoji: 💻
colorFrom: '#007ACC'
colorTo: '#1E1E1E'
colorFrom: blue
colorTo: blue
sdk: docker
pinned: false
app_port: 8000
Expand Down
4 changes: 2 additions & 2 deletions src/envs/coding_env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

from .coding_env_client import CodingEnv
from .client import CodingEnv
from .models import CodeAction, CodeObservation, CodeState

__all__ = ["CodeAction", "CodeObservation", "CodeState", "CodingEnv"]
__all__ = ["CodingEnv", "CodeAction", "CodeObservation", "CodeState"]
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@

from __future__ import annotations

from typing import Optional, TYPE_CHECKING
from openenv_core.client_types import StepResult

from core.client_types import StepResult
from openenv_core.http_env_client import HTTPEnvClient

from core.http_env_client import HTTPEnvClient

from .models import CodeAction, CodeObservation, CodeState

if TYPE_CHECKING:
from core.containers.runtime import ContainerProvider
from coding_env.models import CodeAction, CodeObservation, CodeState


class CodingEnv(HTTPEnvClient[CodeAction, CodeObservation]):
Expand Down
3 changes: 1 addition & 2 deletions src/envs/coding_env/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Optional

from core.env_server import Action, Observation, State
from openenv_core.env_server.interfaces import Action, Observation, State


@dataclass
Expand Down
5 changes: 5 additions & 0 deletions src/envs/coding_env/openenv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: coding_env
version: "0.1.0"
description: "Coding environment for OpenEnv"
action: CodingAction
observation: CodingObservation
35 changes: 35 additions & 0 deletions src/envs/coding_env/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[build-system]
requires = ["setuptools>=45", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "openenv-coding_env"
version = "0.1.0"
description = "Coding Environment for OpenEnv"
requires-python = ">=3.10"
dependencies = [
"openenv-core>=0.1.0",
"fastapi>=0.115.0",
"pydantic>=2.0.0",
"uvicorn>=0.24.0",
"requests>=2.31.0",
"smolagents>=1.22.0,<2",
]

[project.optional-dependencies]
dev = [
"pytest>=8.0.0",
"pytest-cov>=4.0.0",
"ipykernel>=6.29.5",
]

[project.scripts]
server = "coding_env.server.app:main"


[tool.setuptools]
packages = ["coding_env", "coding_env.server"]
package-dir = { "coding_env" = ".", "coding_env.server" = "server" }

[tool.setuptools.package-data]
coding_env = ["**/*.yaml", "**/*.yml"]
41 changes: 21 additions & 20 deletions src/envs/coding_env/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
# Base image
FROM python:3.11-slim

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

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

# Copy README for web interface documentation
COPY src/envs/coding_env/README.md /app/README.md
# Copy environment files
COPY . .

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

# Run the FastAPI server
CMD ["uvicorn", "envs.coding_env.server.app:app", "--host", "0.0.0.0", "--port", "8000"]
# Expose port
EXPOSE 8000

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV ENABLE_WEB_INTERFACE=true

# Run the server
CMD ["python", "-m", "uvicorn", "coding_env.server.app:app", "--host", "0.0.0.0", "--port", "8000"]
25 changes: 25 additions & 0 deletions src/envs/coding_env/server/Dockerfile.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# Use the standard openenv base image
# Built from: docker build -t openenv-base:latest -f src/core/containers/images/Dockerfile .
# In GitHub Actions, this is overridden to use the GHCR base image
ARG BASE_IMAGE=openenv-base:latest
FROM ${BASE_IMAGE}

# Copy only what's needed for this environment
COPY src/core/ /app/src/core/
COPY src/envs/coding_env/ /app/src/envs/coding_env/

# Copy README for web interface documentation
COPY src/envs/coding_env/README.md /app/README.md

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1

# Run the FastAPI server
CMD ["uvicorn", "envs.coding_env.server.app:app", "--host", "0.0.0.0", "--port", "8000"]
11 changes: 11 additions & 0 deletions src/envs/coding_env/server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""Coding environment server components."""

from .python_codeact_env import PythonCodeActEnv

__all__ = ["PythonCodeActEnv"]
17 changes: 14 additions & 3 deletions src/envs/coding_env/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
python -m envs.coding_env.server.app
"""

from core.env_server import create_app
from openenv_core.env_server import create_app

from ..models import CodeAction, CodeObservation
from .python_codeact_env import PythonCodeActEnv
from coding_env.models import CodeAction, CodeObservation
from coding_env.server.python_codeact_env import PythonCodeActEnv

# Create the environment instance
env = PythonCodeActEnv()
Expand All @@ -37,3 +37,14 @@
import uvicorn

uvicorn.run(app, host="0.0.0.0", port=8000)


def main():
"""Main entry point for running the server."""
import uvicorn

uvicorn.run(app, host="0.0.0.0", port=8000)


if __name__ == "__main__":
main()
6 changes: 3 additions & 3 deletions src/envs/coding_env/server/python_codeact_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

import uuid

from core.env_server import Action, Environment, Observation
from core.tools import PyExecutor
from openenv_core.env_server.interfaces import Action, Environment, Observation
from coding_env.server.python_executor import PyExecutor

from ..models import CodeAction, CodeObservation, CodeState
from coding_env.models import CodeAction, CodeObservation, CodeState
from .transforms import create_safe_coding_transform


Expand Down
Loading