Spaces:
Sleeping
Sleeping
Download sql_debug_env/client.py from Akshayaitis/sql-debug-env: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/spaces/Akshayaitis/sql-debug-env/resolve/50bf486dc5fa5f58cf1909ddd43ddf2cd44f649e/sql_debug_env/client.py
- Command line
-
hf download hf://spaces/Akshayaitis/sql-debug-env@50bf486dc5fa5f58cf1909ddd43ddf2cd44f649e/sql_debug_env/client.py
-
curl -L -o client.py https://huggingface.co/spaces/Akshayaitis/sql-debug-env/resolve/50bf486dc5fa5f58cf1909ddd43ddf2cd44f649e/sql_debug_env/client.py
1.68 kB
| """WebSocket client for talking to the SQL Debug Environment server.""" | |
| from __future__ import annotations | |
| from typing import Any, Dict | |
| from openenv.core.env_client import EnvClient, StepResult | |
| from sql_debug_env.models import SQLAction, SQLObservation, SQLState | |
| class SQLDebugEnv(EnvClient[SQLAction, SQLObservation, SQLState]): | |
| """Client for the SQL Debug Environment. | |
| Wraps the OpenEnv WebSocket protocol — handles serialization, | |
| connection management, and type parsing so you don't have to. | |
| Quick start: | |
| async with SQLDebugEnv(base_url="http://localhost:7860") as env: | |
| obs = await env.reset(task_id="fix_syntax") | |
| obs = await env.step(SQLAction(query="SELECT ...")) | |
| Or synchronously: | |
| with SQLDebugEnv(base_url="http://localhost:7860").sync() as env: | |
| obs = env.reset(task_id="fix_syntax") | |
| obs = env.step(SQLAction(query="SELECT ...")) | |
| """ | |
| def _parse_result(self, payload: Dict[str, Any]) -> StepResult[SQLObservation]: | |
| """Turn the raw JSON payload into a typed StepResult.""" | |
| obs_data = payload.get("observation", payload) | |
| observation = SQLObservation(**obs_data) | |
| return StepResult( | |
| observation=observation, | |
| reward=payload.get("reward", observation.reward), | |
| done=payload.get("done", observation.done), | |
| ) | |
| def _parse_state(self, payload: Dict[str, Any]) -> SQLState: | |
| """Deserialize a state payload.""" | |
| return SQLState(**payload) | |
| def _step_payload(self, action: SQLAction) -> Dict[str, Any]: | |
| """Serialize the action for the wire.""" | |
| return action.model_dump() | |