Upload 3 files
Browse filesFiles changed (3)
- server/Dockerfile+22-23
- server/app.py+104-104
- server/requirements.txt+9-9
123456789101112131415161718192021222324# Dockerfile – OpenEnv server with FastAPI and all dependenciesFROM python:3.10-slim# Install system dependencies required for chromadb and sentence-transformersRUN apt-get update && apt-get install -y --no-install-recommends \build-essential \&& rm -rf /var/lib/apt/lists/*WORKDIR /app# Copy requirements and install Python dependenciesCOPY requirements.txt .RUN pip install --no-cache-dir -r requirements.txt# Copy the rest of the applicationCOPY . .# Expose the port used by the FastAPI serverEXPOSE 7860# Run the server using uvicorn# Note: 'server.app:app' assumes the FastAPI app is in server/app.pyENV ENABLE_WEB_INTERFACE=trueCMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]1234567891011121314151617181920212223# Dockerfile – OpenEnv server with FastAPI and all dependenciesFROM python:3.10-slim# Install system dependencies required for chromadb and sentence-transformersRUN apt-get update && apt-get install -y --no-install-recommends \build-essential \&& rm -rf /var/lib/apt/lists/*WORKDIR /app# Copy requirements and install Python dependenciesCOPY requirements.txt .RUN pip install --no-cache-dir -r requirements.txt# Copy the rest of the applicationCOPY . .# Expose the port used by the FastAPI serverEXPOSE 7860# Run the server using uvicorn# Note: 'server.app:app' assumes the FastAPI app is in server/app.pyCMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104# server/app.py – OpenEnv HTTP serverimport sysimport ossys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))from fastapi import FastAPI, HTTPExceptionfrom environment import CodeReviewEnvfrom models import AnyAction, Observation, Reward, State, action_adapterapp = FastAPI(title="Code Review Environment", version="1.0.0")env = CodeReviewEnv()# ----------------------------------------------------------------------# Health & metadata endpoints# ----------------------------------------------------------------------@app.get("/")def root():print("[ROOT] Health check hit")return {"status": "crazy good"}@app.get("/health")def health():print("[HEALTH] Service is healthy")return {"status": "healthy"}@app.get("/metadata")def metadata():print("[METADATA] Requested")return {"name": "Code Review Professional Workflow","description": ("Multi‑turn code review environment for professional‑level bug fixing. ""The agent must inspect, test, lint, query documentation, and negotiate with ""a simulated (persona‑driven) author to get a fix accepted. ""Includes 25 bugs across 5 difficulty levels, AST‑based injection, ""a reward‑shaping system, and curriculum learning. ""Designed for RL training (PPO, DPO, or any policy‑gradient method).")}@app.get("/schema")def schema():print("[SCHEMA] Requested")return {"action": AnyAction.model_json_schema(),"observation": Observation.model_json_schema(),"state": State.model_json_schema()}@app.post("/mcp")def mcp():print("[MCP] Ping received")return {"jsonrpc": "2.0", "result": None}# ----------------------------------------------------------------------# Environment endpoints# ----------------------------------------------------------------------@app.post("/reset")def reset(task: str = "easy"):try:print(f"[RESET] Starting new episode | task={task}")env.set_task(task)obs = env.reset()print(f"[RESET DONE] step={env._step_count}")return obs.__dict__except Exception as e:print(f"[RESET ERROR] {e}")raise HTTPException(status_code=400, detail=str(e))@app.post("/step")def step(action: dict):try:print(f"[STEP INPUT] {action}")parsed_action = action_adapter.validate_python(action)obs, reward, done, info = env.step(parsed_action)print(f"[STEP OUTPUT] reward={reward.value:.4f} | done={done}")return {"observation": obs.__dict__,"reward": reward.value,"done": done,"info": info}except Exception as e:print(f"[STEP ERROR] {e}")raise HTTPException(status_code=400, detail=str(e))@app.get("/state")def state():print("[STATE] Requested")return env._get_observation().__dict__# ----------------------------------------------------------------------# Main entry point (for local testing)# ----------------------------------------------------------------------if __name__ == "__main__":import uvicornprint("[SERVER START] Running on http://0.0.0.0:7860")uvicorn.run(app, host="0.0.0.0", port=7860)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104# server/app.py – OpenEnv HTTP serverimport sysimport ossys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))from fastapi import FastAPI, HTTPExceptionfrom environment import CodeReviewEnvfrom models import AnyAction, Observation, Reward, State, action_adapterapp = FastAPI(title="Code Review Environment", version="1.0.0")env = CodeReviewEnv()# ----------------------------------------------------------------------# Health & metadata endpoints# ----------------------------------------------------------------------@app.get("/")def root():print("[ROOT] Health check hit")return {"status": "crazy good"}@app.get("/health")def health():print("[HEALTH] Service is healthy")return {"status": "healthy"}@app.get("/metadata")def metadata():print("[METADATA] Requested")return {"name": "Code Review Professional Workflow","description": ("Multi‑turn code review environment for professional‑level bug fixing. ""The agent must inspect, test, lint, query documentation, and negotiate with ""a simulated (persona‑driven) author to get a fix accepted. ""Includes 25 bugs across 5 difficulty levels, AST‑based injection, ""a reward‑shaping system (full/core profiles), and curriculum learning. ""Designed for RL training (PPO, DPO, or any policy‑gradient method).")}@app.get("/schema")def schema():print("[SCHEMA] Requested")return {"action": AnyAction.model_json_schema(),"observation": Observation.model_json_schema(),"state": State.model_json_schema()}@app.post("/mcp")def mcp():print("[MCP] Ping received")return {"jsonrpc": "2.0", "result": None}# ----------------------------------------------------------------------# Environment endpoints# ----------------------------------------------------------------------@app.post("/reset")def reset(task: str = "easy"):try:print(f"[RESET] Starting new episode | task={task}")env.set_task(task)obs = env.reset()print(f"[RESET DONE] step={env._step_count}")return obs.__dict__except Exception as e:print(f"[RESET ERROR] {e}")raise HTTPException(status_code=400, detail=str(e))@app.post("/step")def step(action: dict):try:print(f"[STEP INPUT] {action}")parsed_action = action_adapter.validate_python(action)obs, reward, done, info = env.step(parsed_action)print(f"[STEP OUTPUT] reward={reward.value:.4f} | done={done}")return {"observation": obs.__dict__,"reward": reward.value,"done": done,"info": info}except Exception as e:print(f"[STEP ERROR] {e}")raise HTTPException(status_code=400, detail=str(e))@app.get("/state")def state():print("[STATE] Requested")return env._get_observation().__dict__# ----------------------------------------------------------------------# Main entry point (for local testing)# ----------------------------------------------------------------------if __name__ == "__main__":import uvicornprint("[SERVER START] Running on http://0.0.0.0:7860")uvicorn.run(app, host="0.0.0.0", port=7860)
12345678910openenv-core>=0.2.0fastapi>=0.115.0uvicorn>=0.24.0unsloth>=2025.3.1trl>=0.15.0accelerate>=1.2.0pylint>=3.3.0sentence-transformers>=3.3.0datasets>=3.3.0chromadb>=0.5.012345678910openenv-core>=0.2.0fastapi>=0.115.0uvicorn>=0.24.0unsloth>=2025.3.1trl>=0.15.0accelerate>=1.2.0pylint>=3.3.0sentence-transformers>=3.3.0datasets>=3.3.0chromadb>=0.5.0
server/Dockerfile+22-23
server/app.py+104-104
server/requirements.txt+9-9