File size: 1,867 Bytes
77e1e28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
"""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),
        )