100XZX001 commited on
Commit
bcc3655
·
verified ·
1 Parent(s): 9a56f83

Upload 2 files

Browse files
Files changed (2) hide show
  1. server/__init__.py +0 -0
  2. server/app.py +79 -0
server/__init__.py ADDED
File without changes
server/app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import os
3
+ sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
4
+
5
+ from fastapi import FastAPI, HTTPException
6
+ from typing import Optional
7
+ from environment import CodeReviewEnv
8
+ from models import Action, Observation, State
9
+
10
+ app = FastAPI(title="Code Review Environment", version="1.0.0")
11
+ env = CodeReviewEnv() # default task "easy" is set in __init__
12
+
13
+ # ------------------------- OpenEnv required endpoints -------------------------
14
+
15
+ @app.get("/health")
16
+ def health():
17
+ return {"status": "healthy"}
18
+
19
+ @app.get("/metadata")
20
+ def metadata():
21
+ return {
22
+ "name": "Code Review Environment",
23
+ "description": "Simulate reviewing a PR and adding helpful comments. Three tasks with increasing difficulty."
24
+ }
25
+
26
+ @app.get("/schema")
27
+ def schema():
28
+ return {
29
+ "action": Action.model_json_schema(),
30
+ "observation": Observation.model_json_schema(),
31
+ "state": State.model_json_schema()
32
+ }
33
+
34
+ @app.post("/mcp")
35
+ def mcp():
36
+ # Minimal JSON-RPC 2.0 response
37
+ return {"jsonrpc": "2.0", "result": None}
38
+
39
+ # ------------------------- Your environment endpoints -------------------------
40
+
41
+ @app.post("/reset")
42
+ def reset(task: Optional[str] = None):
43
+ if task:
44
+ try:
45
+ env.set_task(task)
46
+ except ValueError as e:
47
+ raise HTTPException(status_code=400, detail=str(e))
48
+ obs = env.reset()
49
+ return obs.dict()
50
+
51
+ @app.post("/set_task")
52
+ def set_task(task: str):
53
+ try:
54
+ env.set_task(task)
55
+ return {"status": "ok", "task": task}
56
+ except ValueError as e:
57
+ raise HTTPException(status_code=400, detail=str(e))
58
+
59
+ @app.post("/step")
60
+ def step(action: dict):
61
+ action_obj = Action(**action)
62
+ obs, reward, done, info = env.step(action_obj)
63
+ return {
64
+ "observation": obs.dict(),
65
+ "reward": reward.value,
66
+ "done": done,
67
+ "info": info
68
+ }
69
+
70
+ @app.get("/state")
71
+ def state():
72
+ return env.state().dict()
73
+
74
+ def main():
75
+ import uvicorn
76
+ uvicorn.run(app, host="0.0.0.0", port=7860)
77
+
78
+ if __name__ == "__main__":
79
+ main()