anvisinghh commited on
Commit
cb00897
·
verified ·
1 Parent(s): 493fd7b

Update env.py

Browse files
Files changed (1) hide show
  1. env.py +20 -6
env.py CHANGED
@@ -1,7 +1,8 @@
1
  import asyncio
2
- from typing import Optional
3
  from types import SimpleNamespace
4
- from openenv.core.env_server import Environment, serve
 
5
  from models import MyEnvV4Observation, MyEnvV4Action
6
 
7
  class MyEnvV4Env(Environment):
@@ -82,9 +83,22 @@ class MyEnvV4Env(Environment):
82
 
83
 
84
 
85
- # 1. Create your environment instance
86
  my_env = MyEnvV4Env()
87
 
88
- # 2. Wrap it in an EnvServer to create the FastAPI app
89
- # This is what Docker/Uvicorn is looking for!
90
- app = serve(my_env)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import asyncio
2
+ from typing import Optional, List
3
  from types import SimpleNamespace
4
+ from fastapi import FastAPI
5
+ from openenv.core.env_server import Environment
6
  from models import MyEnvV4Observation, MyEnvV4Action
7
 
8
  class MyEnvV4Env(Environment):
 
83
 
84
 
85
 
86
+ # Create the environment instance
87
  my_env = MyEnvV4Env()
88
 
89
+ # defining the FastAPI app and routes
90
+ app = FastAPI()
91
+
92
+ @app.get("/reset")
93
+ async def reset():
94
+ result = await my_env.reset()
95
+ return {"observation": result.observation, "reward": result.reward, "done": result.done}
96
+
97
+ @app.post("/step")
98
+ async def step(action: MyEnvV4Action):
99
+ result = await my_env.step(action)
100
+ return {"observation": result.observation, "reward": result.reward, "done": result.done}
101
+
102
+ @app.get("/state")
103
+ async def state():
104
+ return await my_env.state()