Spaces:
Running
Running
File size: 1,464 Bytes
877add7 | 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 | """OpenEnv-friendly HTTP client for the PolyGuard environment."""
from __future__ import annotations
from typing import Any
import requests
class PolyGuardOpenEnvClient:
def __init__(self, base_url: str = "http://127.0.0.1:8100") -> None:
self.base_url = base_url.rstrip("/")
def reset(self, **kwargs: Any) -> dict[str, Any]:
response = requests.post(f"{self.base_url}/reset", json=kwargs, timeout=30)
response.raise_for_status()
return response.json()
def step(self, action: dict[str, Any]) -> dict[str, Any]:
response = requests.post(f"{self.base_url}/step", json=action, timeout=30)
response.raise_for_status()
return response.json()
def state(self) -> dict[str, Any]:
response = requests.get(f"{self.base_url}/state", timeout=30)
response.raise_for_status()
return response.json()
def metadata(self) -> dict[str, Any]:
response = requests.get(f"{self.base_url}/metadata", timeout=30)
response.raise_for_status()
return response.json()
def schema(self) -> dict[str, Any]:
response = requests.get(f"{self.base_url}/schema", timeout=30)
response.raise_for_status()
return response.json()
def mcp(self, payload: dict[str, Any]) -> dict[str, Any]:
response = requests.post(f"{self.base_url}/mcp", json=payload, timeout=30)
response.raise_for_status()
return response.json()
|