File size: 1,703 Bytes
2bf987b | 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 | """v8 environment: v7's tasks behind a tool surface drawn per episode (see surface.py)."""
from .environment import WorkbenchEnvironment
from .models import CallAction, WorkbenchAction, WorkbenchObservation
from .surface import CallError, Surface
class CallEnvironment(WorkbenchEnvironment):
def reset(self, seed=None, episode_id=None, task_id=None, **kwargs):
super().reset(seed=seed, episode_id=episode_id, task_id=task_id, **kwargs)
if self._task.meta.get("grades_workspace"):
self.close()
raise ValueError(f"{task_id} edits files and is not offered with the v8 tool surface.")
self._surface = Surface(self._seed)
self._last = WorkbenchObservation(
output=f"{self._task.instruction}\n\nFiles:\n{self._listing()}\n\n{self._surface.help()}\n"
f"You have {self._last.remaining_steps} calls.",
reward=0.0,
remaining_steps=self._last.remaining_steps,
)
return self._last
def step(self, action: CallAction, timeout_s=None, **kwargs):
if self._task is None or self._done:
return super().step(action, timeout_s=timeout_s, **kwargs)
try:
op, call = self._surface.translate(action.tool, action.args)
except CallError as exc:
self._state.step_count += 1
self._done = True
self._last = WorkbenchObservation(
output=f"Error: {exc} That call does not fit the tools. Episode over. Score: 0.00",
reward=0.0, done=True, remaining_steps=0)
return self._last
return super().step(WorkbenchAction(tool=op, **call), timeout_s=timeout_s, **kwargs)
|