Spaces:
Sleeping
Sleeping
| """Drug Target Validation Environment Client. | |
| Provides the ``DrugTargetEnv`` class that communicates with the | |
| environment server over WebSocket / HTTP using the OpenEnv protocol. | |
| """ | |
| from typing import Dict | |
| from openenv.core.client_types import StepResult | |
| from openenv.core.env_server.types import State | |
| from openenv.core import EnvClient | |
| try: # pragma: no cover - package import path | |
| from .models import DrugTargetAction, ValidationObservation | |
| except ImportError: # pragma: no cover - direct module import path | |
| from models import DrugTargetAction, ValidationObservation | |
| class DrugTargetEnv( | |
| EnvClient[DrugTargetAction, ValidationObservation, State] | |
| ): | |
| """Client for the Drug Target Validation Environment. | |
| Example: | |
| >>> with DrugTargetEnv(base_url="http://localhost:8000") as env: | |
| ... result = env.reset() | |
| ... print(result.observation.target_gene) | |
| ... result = env.step(DrugTargetAction( | |
| ... action_type="query_expression", | |
| ... parameters={"database": "GTEx"}, | |
| ... reasoning="baseline expression survey", | |
| ... )) | |
| ... print(result.observation.latest_output.summary) | |
| """ | |
| def _step_payload(self, action: DrugTargetAction) -> Dict: | |
| return action.model_dump() | |
| def _parse_result( | |
| self, payload: Dict | |
| ) -> StepResult[ValidationObservation]: | |
| obs_data = payload.get("observation", {}) | |
| observation = ValidationObservation(**obs_data) | |
| return StepResult( | |
| observation=observation, | |
| reward=payload.get("reward"), | |
| done=payload.get("done", False), | |
| ) | |
| def _parse_state(self, payload: Dict) -> State: | |
| return State( | |
| episode_id=payload.get("episode_id"), | |
| step_count=payload.get("step_count", 0), | |
| ) | |