Repository navigation
Expand file tree
/
Copy pathclient.py
More file actions
55 lines (46 loc) · 1.81 KB
/
Copy pathclient.py
File metadata and controls
55 lines (46 loc) · 1.81 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from typing import Dict
from openenv.core import EnvClient
from openenv.core.client_types import StepResult
from openenv.core.env_server.types import State
try:
from .models import TaskSchedulerAction, TaskSchedulerObservation
except ImportError:
from models import TaskSchedulerAction, TaskSchedulerObservation
class TaskSchedulerEnv(
EnvClient[TaskSchedulerAction, TaskSchedulerObservation, State]
):
"""
Client for the Task Scheduler Environment.
Example:
>>> with TaskSchedulerEnv(base_url="http://localhost:8000") as env:
... result = env.reset()
... result = env.step(TaskSchedulerAction(task_id=0))
... print(result.observation.message)
"""
def _step_payload(self, action: TaskSchedulerAction) -> Dict:
"""Convert TaskSchedulerAction to JSON payload."""
return {
"task_id": action.task_id,
}
def _parse_result(self, payload: Dict) -> StepResult[TaskSchedulerObservation]:
"""Parse server response into StepResult."""
obs_data = payload.get("observation", payload)
observation = TaskSchedulerObservation(
done=obs_data.get("done", False),
reward=obs_data.get("reward"),
current_step=obs_data.get("current_step", 0),
tasks=obs_data.get("tasks", []),
message=obs_data.get("message", ""),
score=obs_data.get("score", 0.0),
)
return StepResult(
observation=observation,
reward=payload.get("reward"),
done=payload.get("done", False),
)
def _parse_state(self, payload: Dict) -> State:
"""Parse server response into State."""
return State(
episode_id=payload.get("episode_id"),
step_count=payload.get("step_count", 0),
)