Spaces:
Sleeping
Sleeping
Download _compat.py from Code-Father/store: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/spaces/Code-Father/store/resolve/main/_compat.py
- Command line
-
hf download hf://spaces/Code-Father/store/_compat.py
-
curl -L -o _compat.py https://huggingface.co/spaces/Code-Father/store/resolve/main/_compat.py
1.88 kB
| """Compatibility helpers for local development without openenv-core.""" | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from typing import Any, Generic, TypeVar | |
| from pydantic import BaseModel, Field | |
| ActionT = TypeVar("ActionT") | |
| ObservationT = TypeVar("ObservationT") | |
| StateT = TypeVar("StateT") | |
| try: # pragma: no cover - exercised when openenv-core is installed | |
| from openenv.core import EnvClient | |
| from openenv.core.client_types import StepResult | |
| from openenv.core.env_server.interfaces import Environment | |
| from openenv.core.env_server.types import Action, Observation, State | |
| OPENENV_AVAILABLE = True | |
| except ImportError: # pragma: no cover - local fallback for unit tests | |
| OPENENV_AVAILABLE = False | |
| class Action(BaseModel): | |
| """Fallback action model.""" | |
| class Observation(BaseModel): | |
| """Fallback observation model.""" | |
| reward: float | None = None | |
| done: bool = False | |
| metadata: dict[str, Any] = Field(default_factory=dict) | |
| class State(BaseModel): | |
| """Fallback transport state.""" | |
| episode_id: str | None = None | |
| step_count: int = 0 | |
| class Environment(Generic[ObservationT, ActionT]): | |
| """Fallback environment interface.""" | |
| SUPPORTS_CONCURRENT_SESSIONS: bool = False | |
| class StepResult(Generic[ObservationT]): | |
| """Fallback step result container.""" | |
| observation: ObservationT | |
| reward: float | None = None | |
| done: bool = False | |
| class EnvClient(Generic[ActionT, ObservationT, StateT]): | |
| """Fallback client base class used only for local parsing tests.""" | |
| def __init__(self, *args: Any, **kwargs: Any) -> None: | |
| self._base_url = kwargs.get("base_url") | |
| def close(self) -> None: | |
| """Mirror the real client close method.""" | |
| return None | |