100XZX001 commited on
Commit
d25d2e1
·
verified ·
1 Parent(s): ba7c2bc

Upload 2 files

Browse files
Files changed (2) hide show
  1. server/__init__.py +2 -0
  2. server/app.py +77 -0
server/__init__.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # This file marks the 'server' folder as a Python package.
2
+ # It can be empty, but is required for Python to recognize the directory as a package.
server/app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
12
+
13
+
14
+ @app.get("/health")
15
+ def health():
16
+ return {"status": "healthy"}
17
+
18
+ @app.get("/metadata")
19
+ def metadata():
20
+ return {
21
+ "name": "Code Review Environment",
22
+ "description": "Simulate reviewing a PR and adding helpful comments. Three tasks with increasing difficulty."
23
+ }
24
+
25
+ @app.get("/schema")
26
+ def schema():
27
+ return {
28
+ "action": Action.model_json_schema(),
29
+ "observation": Observation.model_json_schema(),
30
+ "state": State.model_json_schema()
31
+ }
32
+
33
+ @app.post("/mcp")
34
+ def mcp():
35
+ return {"jsonrpc": "2.0", "result": None}
36
+
37
+
38
+ @app.post("/reset")
39
+ def reset(task: Optional[str] = None):
40
+ if task:
41
+ try:
42
+ env.set_task(task)
43
+ except ValueError as e:
44
+ raise HTTPException(status_code=400, detail=str(e))
45
+ obs = env.reset()
46
+ return obs.dict()
47
+
48
+ @app.post("/set_task")
49
+ def set_task(task: str):
50
+ try:
51
+ env.set_task(task)
52
+ return {"status": "ok", "task": task}
53
+ except ValueError as e:
54
+ raise HTTPException(status_code=400, detail=str(e))
55
+
56
+ @app.post("/step")
57
+ def step(action: dict):
58
+ action_obj = Action(**action)
59
+ obs, reward, done, info = env.step(action_obj)
60
+ return {
61
+ "observation": obs.dict(),
62
+ "reward": reward.value,
63
+ "done": done,
64
+ "info": info
65
+ }
66
+
67
+ @app.get("/state")
68
+ def state():
69
+ return env.state().dict()
70
+
71
+ def main():
72
+ print(".............app.py made by yuvraj is working correctly – server starting.............")
73
+ import uvicorn
74
+ uvicorn.run(app, host="0.0.0.0", port=7860)
75
+
76
+ if __name__ == "__main__":
77
+ main()