-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
60 lines (50 loc) · 2.26 KB
/
client.py
File metadata and controls
60 lines (50 loc) · 2.26 KB
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
56
57
58
59
60
"""Client for connecting to the SQL Query environment server."""
from typing import Dict
from openenv.core import EnvClient
from openenv.core.client_types import StepResult
from openenv.core.env_server.types import State
from .models import SqlQueryAction, SqlQueryObservation
class SqlQueryEnv(
EnvClient[SqlQueryAction, SqlQueryObservation, State]
):
"""
WebSocket client for the SQL Query environment.
Example usage::
async with SqlQueryEnv(base_url="http://localhost:8000") as client:
result = await client.reset()
result = await client.step(SqlQueryAction(query="SELECT ..."))
"""
def _step_payload(self, action: SqlQueryAction) -> Dict:
return {"query": action.query}
def _parse_result(self, payload: Dict) -> StepResult[SqlQueryObservation]:
obs_data = payload.get("observation", {})
observation = SqlQueryObservation(
task_id=obs_data.get("task_id", ""),
difficulty=obs_data.get("difficulty", "easy"),
database_domain=obs_data.get("database_domain", ""),
question=obs_data.get("question", ""),
schema_description=obs_data.get("schema_description", ""),
query_result=obs_data.get("query_result", ""),
query_error=obs_data.get("query_error"),
feedback=obs_data.get("feedback", ""),
diagnostics=obs_data.get("diagnostics", []),
efficiency_notes=obs_data.get("efficiency_notes", []),
expected_row_count=obs_data.get("expected_row_count", 0),
expected_columns=obs_data.get("expected_columns", []),
steps_remaining=obs_data.get("steps_remaining", 0),
current_score=obs_data.get("current_score", 0.0),
history=obs_data.get("history", []),
done=payload.get("done", False),
reward=payload.get("reward"),
metadata=obs_data.get("metadata", {}),
)
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),
)