sravaniamere commited on
Commit
f52aed3
·
1 Parent(s): ec61b5a

match reference env pattern exactly

Browse files
Files changed (1) hide show
  1. sql_env/server.py +51 -4
sql_env/server.py CHANGED
@@ -18,9 +18,9 @@ except ImportError:
18
 
19
 
20
  class SQLCorrectionEnvironment(Environment):
 
21
 
22
  def __init__(self):
23
- super().__init__()
24
  self._difficulty = "easy"
25
  self._current_task = None
26
  self._step_count = 0
@@ -28,8 +28,12 @@ class SQLCorrectionEnvironment(Environment):
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
- actual_difficulty = task_id or difficulty or "easy"
 
 
 
 
33
  self._difficulty = actual_difficulty
34
  tasks = TASK_SETS.get(actual_difficulty, TASK_SETS["easy"])
35
  self._current_task = random.choice(tasks)
@@ -72,6 +76,50 @@ class SQLCorrectionEnvironment(Environment):
72
  done=done,
73
  )
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  def state(self) -> SQLState:
76
  if self._current_task is None:
77
  return SQLState(
@@ -145,7 +193,6 @@ app = create_app(
145
  SQLAction,
146
  SQLObservation,
147
  env_name="sql-correction-env",
148
- max_concurrent_envs=1,
149
  )
150
 
151
 
 
18
 
19
 
20
  class SQLCorrectionEnvironment(Environment):
21
+ SUPPORTS_CONCURRENT_SESSIONS = True
22
 
23
  def __init__(self):
 
24
  self._difficulty = "easy"
25
  self._current_task = None
26
  self._step_count = 0
 
28
  self._last_reward = 0.0
29
  self._rewards_history = []
30
 
31
+ def reset(self, seed=None, episode_id=None, **kwargs) -> SQLObservation:
32
+ actual_difficulty = (
33
+ kwargs.get("task_id") or
34
+ kwargs.get("difficulty") or
35
+ "easy"
36
+ )
37
  self._difficulty = actual_difficulty
38
  tasks = TASK_SETS.get(actual_difficulty, TASK_SETS["easy"])
39
  self._current_task = random.choice(tasks)
 
76
  done=done,
77
  )
78
 
79
+ @property
80
+ def state(self) -> SQLState:
81
+ if self._current_task is None:
82
+ return SQLState(
83
+ task_id="none",
84
+ difficulty="none",
85
+ step_count=0,
86
+ max_steps=0,
87
+ done=False,
88
+ last_reward=0.0,
89
+ rewards_history=[],
90
+ )
91
+ return SQLState(
92
+ task_id=self._current_task.task_id,
93
+ difficulty=self._difficulty,
94
+ step_count=self._step_count,
95
+ max_steps=self._current_task.max_steps,
96
+ done=self._done,
97
+ last_reward=self._last_reward,
98
+ rewards_history=self._rewards_history,
99
+ )
100
+ def step(self, action: SQLAction) -> SQLObservation:
101
+ if self._current_task is None:
102
+ self.reset()
103
+ self._step_count += 1
104
+ reward_obj = grade(action, self._current_task)
105
+ reward = reward_obj.value
106
+ self._last_reward = reward
107
+ self._rewards_history.append(reward)
108
+ done = (reward >= 0.95) or (self._step_count >= self._current_task.max_steps)
109
+ self._done = done
110
+ feedback = generate_feedback(action, self._current_task, reward_obj)
111
+ return SQLObservation(
112
+ task_id=self._current_task.task_id,
113
+ broken_query=self._current_task.broken_query,
114
+ schema_context=self._current_task.schema_context,
115
+ error_hint=self._current_task.error_hint,
116
+ step_number=self._step_count,
117
+ previous_attempt=action.corrected_query,
118
+ feedback=feedback,
119
+ reward=reward,
120
+ done=done,
121
+ )
122
+
123
  def state(self) -> SQLState:
124
  if self._current_task is None:
125
  return SQLState(
 
193
  SQLAction,
194
  SQLObservation,
195
  env_name="sql-correction-env",
 
196
  )
197
 
198