Upload 3 files
Browse files- server/Dockerfile +22 -23
- server/app.py +104 -104
- server/requirements.txt +9 -9
server/Dockerfile
CHANGED
|
@@ -1,24 +1,23 @@
|
|
| 1 |
-
# Dockerfile – OpenEnv server with FastAPI and all dependencies
|
| 2 |
-
FROM python:3.10-slim
|
| 3 |
-
|
| 4 |
-
# Install system dependencies required for chromadb and sentence-transformers
|
| 5 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
-
build-essential \
|
| 7 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
-
|
| 9 |
-
WORKDIR /app
|
| 10 |
-
|
| 11 |
-
# Copy requirements and install Python dependencies
|
| 12 |
-
COPY requirements.txt .
|
| 13 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 14 |
-
|
| 15 |
-
# Copy the rest of the application
|
| 16 |
-
COPY . .
|
| 17 |
-
|
| 18 |
-
# Expose the port used by the FastAPI server
|
| 19 |
-
EXPOSE 7860
|
| 20 |
-
|
| 21 |
-
# Run the server using uvicorn
|
| 22 |
-
# Note: 'server.app:app' assumes the FastAPI app is in server/app.py
|
| 23 |
-
ENV ENABLE_WEB_INTERFACE=true
|
| 24 |
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Dockerfile – OpenEnv server with FastAPI and all dependencies
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies required for chromadb and sentence-transformers
|
| 5 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
+
build-essential \
|
| 7 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
+
|
| 9 |
+
WORKDIR /app
|
| 10 |
+
|
| 11 |
+
# Copy requirements and install Python dependencies
|
| 12 |
+
COPY requirements.txt .
|
| 13 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 14 |
+
|
| 15 |
+
# Copy the rest of the application
|
| 16 |
+
COPY . .
|
| 17 |
+
|
| 18 |
+
# Expose the port used by the FastAPI server
|
| 19 |
+
EXPOSE 7860
|
| 20 |
+
|
| 21 |
+
# Run the server using uvicorn
|
| 22 |
+
# Note: 'server.app:app' assumes the FastAPI app is in server/app.py
|
|
|
|
| 23 |
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
|
server/app.py
CHANGED
|
@@ -1,104 +1,104 @@
|
|
| 1 |
-
# server/app.py – OpenEnv HTTP server
|
| 2 |
-
import sys
|
| 3 |
-
import os
|
| 4 |
-
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
| 5 |
-
|
| 6 |
-
from fastapi import FastAPI, HTTPException
|
| 7 |
-
from environment import CodeReviewEnv
|
| 8 |
-
from models import AnyAction, Observation, Reward, State, action_adapter
|
| 9 |
-
|
| 10 |
-
app = FastAPI(title="Code Review Environment", version="1.0.0")
|
| 11 |
-
env = CodeReviewEnv()
|
| 12 |
-
|
| 13 |
-
# ----------------------------------------------------------------------
|
| 14 |
-
# Health & metadata endpoints
|
| 15 |
-
# ----------------------------------------------------------------------
|
| 16 |
-
@app.get("/")
|
| 17 |
-
def root():
|
| 18 |
-
print("[ROOT] Health check hit")
|
| 19 |
-
return {"status": "crazy good"}
|
| 20 |
-
|
| 21 |
-
@app.get("/health")
|
| 22 |
-
def health():
|
| 23 |
-
print("[HEALTH] Service is healthy")
|
| 24 |
-
return {"status": "healthy"}
|
| 25 |
-
|
| 26 |
-
@app.get("/metadata")
|
| 27 |
-
def metadata():
|
| 28 |
-
print("[METADATA] Requested")
|
| 29 |
-
return {
|
| 30 |
-
"name": "Code Review Professional Workflow",
|
| 31 |
-
"description": (
|
| 32 |
-
"Multi‑turn code review environment for professional‑level bug fixing. "
|
| 33 |
-
"The agent must inspect, test, lint, query documentation, and negotiate with "
|
| 34 |
-
"a simulated (persona‑driven) author to get a fix accepted. "
|
| 35 |
-
"Includes 25 bugs across 5 difficulty levels, AST‑based injection, "
|
| 36 |
-
"a reward‑shaping system, and curriculum learning. "
|
| 37 |
-
"Designed for RL training (PPO, DPO, or any policy‑gradient method)."
|
| 38 |
-
)
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
@app.get("/schema")
|
| 42 |
-
def schema():
|
| 43 |
-
print("[SCHEMA] Requested")
|
| 44 |
-
return {
|
| 45 |
-
"action": AnyAction.model_json_schema(),
|
| 46 |
-
"observation": Observation.model_json_schema(),
|
| 47 |
-
"state": State.model_json_schema()
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
@app.post("/mcp")
|
| 51 |
-
def mcp():
|
| 52 |
-
print("[MCP] Ping received")
|
| 53 |
-
return {"jsonrpc": "2.0", "result": None}
|
| 54 |
-
|
| 55 |
-
# ----------------------------------------------------------------------
|
| 56 |
-
# Environment endpoints
|
| 57 |
-
# ----------------------------------------------------------------------
|
| 58 |
-
@app.post("/reset")
|
| 59 |
-
def reset(task: str = "easy"):
|
| 60 |
-
try:
|
| 61 |
-
print(f"[RESET] Starting new episode | task={task}")
|
| 62 |
-
|
| 63 |
-
env.set_task(task)
|
| 64 |
-
obs = env.reset()
|
| 65 |
-
|
| 66 |
-
print(f"[RESET DONE] step={env._step_count}")
|
| 67 |
-
|
| 68 |
-
return obs.__dict__
|
| 69 |
-
except Exception as e:
|
| 70 |
-
print(f"[RESET ERROR] {e}")
|
| 71 |
-
raise HTTPException(status_code=400, detail=str(e))
|
| 72 |
-
|
| 73 |
-
@app.post("/step")
|
| 74 |
-
def step(action: dict):
|
| 75 |
-
try:
|
| 76 |
-
print(f"[STEP INPUT] {action}")
|
| 77 |
-
|
| 78 |
-
parsed_action = action_adapter.validate_python(action)
|
| 79 |
-
obs, reward, done, info = env.step(parsed_action)
|
| 80 |
-
|
| 81 |
-
print(f"[STEP OUTPUT] reward={reward.value:.4f} | done={done}")
|
| 82 |
-
|
| 83 |
-
return {
|
| 84 |
-
"observation": obs.__dict__,
|
| 85 |
-
"reward": reward.value,
|
| 86 |
-
"done": done,
|
| 87 |
-
"info": info
|
| 88 |
-
}
|
| 89 |
-
except Exception as e:
|
| 90 |
-
print(f"[STEP ERROR] {e}")
|
| 91 |
-
raise HTTPException(status_code=400, detail=str(e))
|
| 92 |
-
|
| 93 |
-
@app.get("/state")
|
| 94 |
-
def state():
|
| 95 |
-
print("[STATE] Requested")
|
| 96 |
-
return env._get_observation().__dict__
|
| 97 |
-
|
| 98 |
-
# ----------------------------------------------------------------------
|
| 99 |
-
# Main entry point (for local testing)
|
| 100 |
-
# ----------------------------------------------------------------------
|
| 101 |
-
if __name__ == "__main__":
|
| 102 |
-
import uvicorn
|
| 103 |
-
print("[SERVER START] Running on http://0.0.0.0:7860")
|
| 104 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
+
# server/app.py – OpenEnv HTTP server
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
| 5 |
+
|
| 6 |
+
from fastapi import FastAPI, HTTPException
|
| 7 |
+
from environment import CodeReviewEnv
|
| 8 |
+
from models import AnyAction, Observation, Reward, State, action_adapter
|
| 9 |
+
|
| 10 |
+
app = FastAPI(title="Code Review Environment", version="1.0.0")
|
| 11 |
+
env = CodeReviewEnv()
|
| 12 |
+
|
| 13 |
+
# ----------------------------------------------------------------------
|
| 14 |
+
# Health & metadata endpoints
|
| 15 |
+
# ----------------------------------------------------------------------
|
| 16 |
+
@app.get("/")
|
| 17 |
+
def root():
|
| 18 |
+
print("[ROOT] Health check hit")
|
| 19 |
+
return {"status": "crazy good"}
|
| 20 |
+
|
| 21 |
+
@app.get("/health")
|
| 22 |
+
def health():
|
| 23 |
+
print("[HEALTH] Service is healthy")
|
| 24 |
+
return {"status": "healthy"}
|
| 25 |
+
|
| 26 |
+
@app.get("/metadata")
|
| 27 |
+
def metadata():
|
| 28 |
+
print("[METADATA] Requested")
|
| 29 |
+
return {
|
| 30 |
+
"name": "Code Review Professional Workflow",
|
| 31 |
+
"description": (
|
| 32 |
+
"Multi‑turn code review environment for professional‑level bug fixing. "
|
| 33 |
+
"The agent must inspect, test, lint, query documentation, and negotiate with "
|
| 34 |
+
"a simulated (persona‑driven) author to get a fix accepted. "
|
| 35 |
+
"Includes 25 bugs across 5 difficulty levels, AST‑based injection, "
|
| 36 |
+
"a reward‑shaping system (full/core profiles), and curriculum learning. "
|
| 37 |
+
"Designed for RL training (PPO, DPO, or any policy‑gradient method)."
|
| 38 |
+
)
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
@app.get("/schema")
|
| 42 |
+
def schema():
|
| 43 |
+
print("[SCHEMA] Requested")
|
| 44 |
+
return {
|
| 45 |
+
"action": AnyAction.model_json_schema(),
|
| 46 |
+
"observation": Observation.model_json_schema(),
|
| 47 |
+
"state": State.model_json_schema()
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
@app.post("/mcp")
|
| 51 |
+
def mcp():
|
| 52 |
+
print("[MCP] Ping received")
|
| 53 |
+
return {"jsonrpc": "2.0", "result": None}
|
| 54 |
+
|
| 55 |
+
# ----------------------------------------------------------------------
|
| 56 |
+
# Environment endpoints
|
| 57 |
+
# ----------------------------------------------------------------------
|
| 58 |
+
@app.post("/reset")
|
| 59 |
+
def reset(task: str = "easy"):
|
| 60 |
+
try:
|
| 61 |
+
print(f"[RESET] Starting new episode | task={task}")
|
| 62 |
+
|
| 63 |
+
env.set_task(task)
|
| 64 |
+
obs = env.reset()
|
| 65 |
+
|
| 66 |
+
print(f"[RESET DONE] step={env._step_count}")
|
| 67 |
+
|
| 68 |
+
return obs.__dict__
|
| 69 |
+
except Exception as e:
|
| 70 |
+
print(f"[RESET ERROR] {e}")
|
| 71 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 72 |
+
|
| 73 |
+
@app.post("/step")
|
| 74 |
+
def step(action: dict):
|
| 75 |
+
try:
|
| 76 |
+
print(f"[STEP INPUT] {action}")
|
| 77 |
+
|
| 78 |
+
parsed_action = action_adapter.validate_python(action)
|
| 79 |
+
obs, reward, done, info = env.step(parsed_action)
|
| 80 |
+
|
| 81 |
+
print(f"[STEP OUTPUT] reward={reward.value:.4f} | done={done}")
|
| 82 |
+
|
| 83 |
+
return {
|
| 84 |
+
"observation": obs.__dict__,
|
| 85 |
+
"reward": reward.value,
|
| 86 |
+
"done": done,
|
| 87 |
+
"info": info
|
| 88 |
+
}
|
| 89 |
+
except Exception as e:
|
| 90 |
+
print(f"[STEP ERROR] {e}")
|
| 91 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 92 |
+
|
| 93 |
+
@app.get("/state")
|
| 94 |
+
def state():
|
| 95 |
+
print("[STATE] Requested")
|
| 96 |
+
return env._get_observation().__dict__
|
| 97 |
+
|
| 98 |
+
# ----------------------------------------------------------------------
|
| 99 |
+
# Main entry point (for local testing)
|
| 100 |
+
# ----------------------------------------------------------------------
|
| 101 |
+
if __name__ == "__main__":
|
| 102 |
+
import uvicorn
|
| 103 |
+
print("[SERVER START] Running on http://0.0.0.0:7860")
|
| 104 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
server/requirements.txt
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
openenv-core>=0.2.0
|
| 2 |
-
fastapi>=0.115.0
|
| 3 |
-
uvicorn>=0.24.0
|
| 4 |
-
unsloth>=2025.3.1
|
| 5 |
-
trl>=0.15.0
|
| 6 |
-
accelerate>=1.2.0
|
| 7 |
-
pylint>=3.3.0
|
| 8 |
-
sentence-transformers>=3.3.0
|
| 9 |
-
datasets>=3.3.0
|
| 10 |
chromadb>=0.5.0
|
|
|
|
| 1 |
+
openenv-core>=0.2.0
|
| 2 |
+
fastapi>=0.115.0
|
| 3 |
+
uvicorn>=0.24.0
|
| 4 |
+
unsloth>=2025.3.1
|
| 5 |
+
trl>=0.15.0
|
| 6 |
+
accelerate>=1.2.0
|
| 7 |
+
pylint>=3.3.0
|
| 8 |
+
sentence-transformers>=3.3.0
|
| 9 |
+
datasets>=3.3.0
|
| 10 |
chromadb>=0.5.0
|