Update server/app.py
Browse files- server/app.py +20 -1
server/app.py
CHANGED
|
@@ -15,21 +15,25 @@ env = CodeReviewEnv()
|
|
| 15 |
# ----------------------------------------------------------------------
|
| 16 |
@app.get("/")
|
| 17 |
def root():
|
|
|
|
| 18 |
return {"status": "ok"}
|
| 19 |
|
| 20 |
@app.get("/health")
|
| 21 |
def health():
|
|
|
|
| 22 |
return {"status": "healthy"}
|
| 23 |
|
| 24 |
@app.get("/metadata")
|
| 25 |
def metadata():
|
|
|
|
| 26 |
return {
|
| 27 |
"name": "Code Review Environment",
|
| 28 |
-
"description": "Multi
|
| 29 |
}
|
| 30 |
|
| 31 |
@app.get("/schema")
|
| 32 |
def schema():
|
|
|
|
| 33 |
return {
|
| 34 |
"action": AnyAction.model_json_schema(),
|
| 35 |
"observation": Observation.model_json_schema(),
|
|
@@ -38,6 +42,7 @@ def schema():
|
|
| 38 |
|
| 39 |
@app.post("/mcp")
|
| 40 |
def mcp():
|
|
|
|
| 41 |
return {"jsonrpc": "2.0", "result": None}
|
| 42 |
|
| 43 |
# ----------------------------------------------------------------------
|
|
@@ -46,17 +51,28 @@ def mcp():
|
|
| 46 |
@app.post("/reset")
|
| 47 |
def reset(task: str = "easy"):
|
| 48 |
try:
|
|
|
|
|
|
|
| 49 |
env.set_task(task)
|
| 50 |
obs = env.reset()
|
|
|
|
|
|
|
|
|
|
| 51 |
return obs.__dict__
|
| 52 |
except Exception as e:
|
|
|
|
| 53 |
raise HTTPException(status_code=400, detail=str(e))
|
| 54 |
|
| 55 |
@app.post("/step")
|
| 56 |
def step(action: dict):
|
| 57 |
try:
|
|
|
|
|
|
|
| 58 |
parsed_action = action_adapter.validate_python(action)
|
| 59 |
obs, reward, done, info = env.step(parsed_action)
|
|
|
|
|
|
|
|
|
|
| 60 |
return {
|
| 61 |
"observation": obs.__dict__,
|
| 62 |
"reward": reward.value,
|
|
@@ -64,10 +80,12 @@ def step(action: dict):
|
|
| 64 |
"info": info
|
| 65 |
}
|
| 66 |
except Exception as e:
|
|
|
|
| 67 |
raise HTTPException(status_code=400, detail=str(e))
|
| 68 |
|
| 69 |
@app.get("/state")
|
| 70 |
def state():
|
|
|
|
| 71 |
s = env.state()
|
| 72 |
return s.__dict__
|
| 73 |
|
|
@@ -76,4 +94,5 @@ def state():
|
|
| 76 |
# ----------------------------------------------------------------------
|
| 77 |
if __name__ == "__main__":
|
| 78 |
import uvicorn
|
|
|
|
| 79 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 15 |
# ----------------------------------------------------------------------
|
| 16 |
@app.get("/")
|
| 17 |
def root():
|
| 18 |
+
print("[ROOT] Health check hit")
|
| 19 |
return {"status": "ok"}
|
| 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 Environment",
|
| 31 |
+
"description": "Multi-turn code review with AST injection, DPO training, and author negotiation."
|
| 32 |
}
|
| 33 |
|
| 34 |
@app.get("/schema")
|
| 35 |
def schema():
|
| 36 |
+
print("[SCHEMA] Requested")
|
| 37 |
return {
|
| 38 |
"action": AnyAction.model_json_schema(),
|
| 39 |
"observation": Observation.model_json_schema(),
|
|
|
|
| 42 |
|
| 43 |
@app.post("/mcp")
|
| 44 |
def mcp():
|
| 45 |
+
print("[MCP] Ping received")
|
| 46 |
return {"jsonrpc": "2.0", "result": None}
|
| 47 |
|
| 48 |
# ----------------------------------------------------------------------
|
|
|
|
| 51 |
@app.post("/reset")
|
| 52 |
def reset(task: str = "easy"):
|
| 53 |
try:
|
| 54 |
+
print(f"[RESET] Starting new episode | task={task}")
|
| 55 |
+
|
| 56 |
env.set_task(task)
|
| 57 |
obs = env.reset()
|
| 58 |
+
|
| 59 |
+
print(f"[RESET DONE] step={env._step_count}")
|
| 60 |
+
|
| 61 |
return obs.__dict__
|
| 62 |
except Exception as e:
|
| 63 |
+
print(f"[RESET ERROR] {e}")
|
| 64 |
raise HTTPException(status_code=400, detail=str(e))
|
| 65 |
|
| 66 |
@app.post("/step")
|
| 67 |
def step(action: dict):
|
| 68 |
try:
|
| 69 |
+
print(f"[STEP INPUT] {action}")
|
| 70 |
+
|
| 71 |
parsed_action = action_adapter.validate_python(action)
|
| 72 |
obs, reward, done, info = env.step(parsed_action)
|
| 73 |
+
|
| 74 |
+
print(f"[STEP OUTPUT] reward={reward.value:.4f} | done={done}")
|
| 75 |
+
|
| 76 |
return {
|
| 77 |
"observation": obs.__dict__,
|
| 78 |
"reward": reward.value,
|
|
|
|
| 80 |
"info": info
|
| 81 |
}
|
| 82 |
except Exception as e:
|
| 83 |
+
print(f"[STEP ERROR] {e}")
|
| 84 |
raise HTTPException(status_code=400, detail=str(e))
|
| 85 |
|
| 86 |
@app.get("/state")
|
| 87 |
def state():
|
| 88 |
+
print("[STATE] Requested")
|
| 89 |
s = env.state()
|
| 90 |
return s.__dict__
|
| 91 |
|
|
|
|
| 94 |
# ----------------------------------------------------------------------
|
| 95 |
if __name__ == "__main__":
|
| 96 |
import uvicorn
|
| 97 |
+
print("[SERVER START] Running on http://0.0.0.0:7860")
|
| 98 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|