Spaces:
Sleeping
Sleeping
Commit ·
c41f6ba
1
Parent(s): 65028b5
fix reset to accept task_id, update tasks endpoint
Browse files- sql_env/server.py +25 -25
sql_env/server.py
CHANGED
|
@@ -28,26 +28,28 @@ class SQLCorrectionEnvironment(Environment):
|
|
| 28 |
self._last_reward = 0.0
|
| 29 |
self._rewards_history = []
|
| 30 |
|
| 31 |
-
def reset(self, difficulty: str = "easy") -> SQLObservation:
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
def step(self, action: SQLAction) -> SQLObservation:
|
| 52 |
self._step_count += 1
|
| 53 |
reward_obj = grade(action, self._current_task)
|
|
@@ -111,12 +113,10 @@ from fastapi import Request
|
|
| 111 |
|
| 112 |
@app.get("/tasks")
|
| 113 |
async def list_tasks():
|
| 114 |
-
"""Return graded tasks in openenv validator format."""
|
| 115 |
-
from sql_env.grader import grade
|
| 116 |
return {
|
| 117 |
"tasks": [
|
| 118 |
-
{"id": "easy", "difficulty": "easy", "description": "Fix a single syntax error.", "steps": 5, "ideal_action": "correct_sql", "has_grader": True},
|
| 119 |
-
{"id": "medium", "difficulty": "medium", "description": "Fix multiple errors.", "steps": 5, "ideal_action": "correct_sql", "has_grader": True},
|
| 120 |
-
{"id": "hard", "difficulty": "hard", "description": "Fix complex multi-join queries.", "steps": 4, "ideal_action": "correct_sql", "has_grader": True},
|
| 121 |
]
|
| 122 |
}
|
|
|
|
| 28 |
self._last_reward = 0.0
|
| 29 |
self._rewards_history = []
|
| 30 |
|
| 31 |
+
def reset(self, difficulty: str = "easy", task_id: str = None, **kwargs) -> SQLObservation:
|
| 32 |
+
# task_id and difficulty are the same thing in our env
|
| 33 |
+
actual_difficulty = task_id or difficulty or "easy"
|
| 34 |
+
self._difficulty = actual_difficulty
|
| 35 |
+
tasks = TASK_SETS.get(actual_difficulty, TASK_SETS["easy"])
|
| 36 |
+
self._current_task = random.choice(tasks)
|
| 37 |
+
self._step_count = 0
|
| 38 |
+
self._done = False
|
| 39 |
+
self._last_reward = 0.0
|
| 40 |
+
self._rewards_history = []
|
| 41 |
+
return SQLObservation(
|
| 42 |
+
task_id=self._current_task.task_id,
|
| 43 |
+
broken_query=self._current_task.broken_query,
|
| 44 |
+
schema_context=self._current_task.schema_context,
|
| 45 |
+
error_hint=self._current_task.error_hint,
|
| 46 |
+
step_number=0,
|
| 47 |
+
previous_attempt=None,
|
| 48 |
+
feedback=None,
|
| 49 |
+
reward=0.0,
|
| 50 |
+
done=False,
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
def step(self, action: SQLAction) -> SQLObservation:
|
| 54 |
self._step_count += 1
|
| 55 |
reward_obj = grade(action, self._current_task)
|
|
|
|
| 113 |
|
| 114 |
@app.get("/tasks")
|
| 115 |
async def list_tasks():
|
|
|
|
|
|
|
| 116 |
return {
|
| 117 |
"tasks": [
|
| 118 |
+
{"id": "easy", "difficulty": "easy", "description": "Fix a single syntax error.", "steps": 5, "ideal_action": "correct_sql", "has_grader": True, "grader": "sql_env.grader.grade"},
|
| 119 |
+
{"id": "medium", "difficulty": "medium", "description": "Fix multiple errors.", "steps": 5, "ideal_action": "correct_sql", "has_grader": True, "grader": "sql_env.grader.grade"},
|
| 120 |
+
{"id": "hard", "difficulty": "hard", "description": "Fix complex multi-join queries.", "steps": 4, "ideal_action": "correct_sql", "has_grader": True, "grader": "sql_env.grader.grade"},
|
| 121 |
]
|
| 122 |
}
|