padmapriyagosakan commited on
Commit
f352609
·
1 Parent(s): 279779a

fix: add client.py and outputs/ for openenv push structure validation

Browse files
Files changed (2) hide show
  1. client.py +53 -0
  2. outputs/.gitkeep +0 -0
client.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """PayOps Environment Client."""
2
+
3
+ from typing import Dict, Any
4
+
5
+ from openenv.core import EnvClient
6
+ from openenv.core.client_types import StepResult
7
+ from openenv.core.env_server.types import State
8
+
9
+ from payops_env.models import PayOpsAction, PayOpsObservation
10
+
11
+
12
+ class PayOpsEnv(EnvClient[PayOpsAction, PayOpsObservation]):
13
+ """
14
+ Client for the PayOps Payment Operations Incident Response Environment.
15
+
16
+ Maintains a persistent WebSocket connection to the environment server,
17
+ enabling efficient multi-step interactions.
18
+
19
+ Example::
20
+
21
+ with PayOpsEnv(base_url="http://localhost:7860") as client:
22
+ result = client.reset()
23
+ while not result.done:
24
+ action = PayOpsAction(
25
+ action_type="approve",
26
+ transaction_id=result.observation.transaction_id,
27
+ )
28
+ result = client.step(action)
29
+ print("Score:", result.observation.cumulative_reward)
30
+ """
31
+
32
+ def _step_payload(self, action: PayOpsAction) -> Dict[str, Any]:
33
+ """Convert PayOpsAction to the official openenv wire format."""
34
+ return {
35
+ "action": action.model_dump(exclude_none=True),
36
+ }
37
+
38
+ def _parse_result(self, payload: Dict[str, Any]) -> StepResult[PayOpsObservation]:
39
+ """Parse server response into StepResult[PayOpsObservation]."""
40
+ obs_data = payload.get("observation", payload) # support wrapped or flat
41
+ observation = PayOpsObservation(**obs_data)
42
+ return StepResult(
43
+ observation=observation,
44
+ reward=payload.get("reward", obs_data.get("reward")),
45
+ done=payload.get("done", obs_data.get("done", False)),
46
+ )
47
+
48
+ def _parse_state(self, payload: Dict[str, Any]) -> State:
49
+ """Parse server state response into State object."""
50
+ return State(
51
+ episode_id=payload.get("episode_id"),
52
+ step_count=payload.get("step_count", 0),
53
+ )
outputs/.gitkeep ADDED
File without changes