Spaces:
Sleeping
Sleeping
File size: 977 Bytes
761f203 | 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 | from __future__ import annotations
from dataclasses import dataclass
from typing import Any
import requests
from env.models import FlakySleuthAction
@dataclass
class FlakySleuthClient:
base_url: str
timeout_s: float = 30.0
def reset(self) -> dict[str, Any]:
response = requests.post(f"{self.base_url.rstrip('/')}/reset", timeout=self.timeout_s)
response.raise_for_status()
return response.json()
def step(self, action: FlakySleuthAction) -> dict[str, Any]:
payload = {"action": action.model_dump()}
response = requests.post(
f"{self.base_url.rstrip('/')}/step",
json=payload,
timeout=self.timeout_s,
)
response.raise_for_status()
return response.json()
def state(self) -> dict[str, Any]:
response = requests.get(f"{self.base_url.rstrip('/')}/state", timeout=self.timeout_s)
response.raise_for_status()
return response.json()
|