Team Ai
Apppublic

openenv/coding_env

sourceHugging Faceupdated 3mo agoView on Hugging Face
21likes
client.py57 linesDownload Raw Back to root
1"""2CodingEnv3---------4Client-side wrapper for the Coding environment server.5 6This client maintains a persistent WebSocket connection to the environment7server, enabling efficient multi-step interactions with lower latency.8 9- users instantiate CodingEnv with a base_url provided by the higher-level10  vector/orchestration layer.11- Environment authors ship the Docker image that serves the API.12 13(Seeds, episode IDs, request IDs, capabilities can be added later in the payloads.)14"""15 16from __future__ import annotations17 18from openenv.core.client_types import StepResult19from openenv.core.env_client import EnvClient20 21from .models import CodeAction, CodeObservation, CodeState22 23 24class CodingEnv(EnvClient[CodeAction, CodeObservation, CodeState]):25    # --- HTTPEnvClient abstract hooks ---26 27    def _step_payload(self, action: CodeAction) -> dict:28        # Shape expected by the server's /step endpoint under "action"29        return {30            "code": action.code,31        }32 33    def _parse_result(self, payload: dict) -> StepResult[CodeObservation]:34        # Expecting: { "observation": {...}, "reward": <float|null>, "done": <bool>, "info": {...} }35        obs = CodeObservation(**payload["observation"])36        return StepResult(37            observation=obs,38            reward=payload.get("reward"),39            done=bool(payload.get("done", False)),40        )41 42    def _parse_state(self, payload: dict) -> CodeState:43        """44        Parse server response into CodeState object.45 46        Args:47            payload: JSON response from /state endpoint48 49        Returns:50            CodeState object with episode_id, step_count, and last_exit_code51        """52        return CodeState(53            episode_id=payload.get("episode_id"),54            step_count=payload.get("step_count", 0),55            last_exit_code=payload.get("last_exit_code", 0),56        )57