File size: 1,169 Bytes
cd7277c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from openenv.core.env_server import create_app

from models import PersonaAction, PersonaObservation
from .persona_env_environment import PersonaEnvironment


# = create one env instance we control (for debug visibility)
_env = PersonaEnvironment()

# = create the OpenEnv app (keeps /reset, /step, /schema, etc working)
app = create_app(
    PersonaEnvironment,
    PersonaAction,
    PersonaObservation,
    env_name="persona_env",
)

# = add a debug endpoint that reflects the live env state we control
@app.get("/debug_state")
def debug_state():
    return _env.state


# Optional: also step/reset the debug env using the same action schema
@app.post("/debug_reset")
def debug_reset():
    obs = _env.reset()
    return {"observation": obs, "reward": getattr(obs, "reward", 0.0), "done": getattr(obs, "done", False)}


@app.post("/debug_step")
def debug_step(payload: dict):
    # payload format matches your /step envelope: {"action": {...}}
    action_dict = payload.get("action", {})
    action = PersonaAction(**action_dict)
    obs = _env.step(action)
    return {"observation": obs, "reward": getattr(obs, "reward", 0.0), "done": getattr(obs, "done", False)}