at0day commited on
Commit
b7258fe
·
verified ·
1 Parent(s): 7a5c26f

Upload 2 files

Browse files
Files changed (2) hide show
  1. openenv/__init__.py +0 -0
  2. openenv/serve.py +41 -0
openenv/__init__.py ADDED
File without changes
openenv/serve.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ OpenEnv FastAPI Server for SOC Analyst Environment
3
+ ---------------------------------------------------
4
+ Provides HTTP endpoints for environment interaction.
5
+ Compliant with OpenEnv 2026 specification.
6
+ """
7
+ from fastapi import FastAPI
8
+ from env.environment import SOCEnv
9
+ from env.models import Action
10
+
11
+ app = FastAPI()
12
+ env = SOCEnv()
13
+
14
+ @app.post("/reset")
15
+ def reset(data: dict):
16
+ """Reset environment and return initial observation."""
17
+ task = data.get("task", "easy")
18
+ obs = env.reset(task)
19
+ return obs.model_dump()
20
+
21
+ @app.post("/step")
22
+ def step(action: Action):
23
+ """Execute action and return (observation, reward, done, info)."""
24
+ obs, reward, done, info = env.step(action)
25
+ return {
26
+ "observation": obs.model_dump(),
27
+ "reward": reward,
28
+ "done": done,
29
+ "info": info
30
+ }
31
+
32
+ @app.get("/state")
33
+ def state():
34
+ """Get current environment state for grading."""
35
+ return env.state()
36
+
37
+ @app.post("/close")
38
+ def close():
39
+ """Reset environment."""
40
+ env.reset()
41
+ return {"status": "closed"}