Skip to content

Commit

Permalink
Add back code
Browse files Browse the repository at this point in the history
  • Loading branch information
humpydonkey committed Jul 22, 2024
1 parent f4c38f7 commit b2c621b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion vision_agent/utils/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def close(self, *args: Any, **kwargs: Any) -> None:
)

def restart_kernel(self) -> None:
self._check_sandbox_liveness()
self.interpreter.notebook.restart_kernel()

@tenacity.retry(
Expand All @@ -473,6 +474,7 @@ def restart_kernel(self) -> None:
after=tenacity.after_log(_LOGGER, logging.INFO),
)
def exec_cell(self, code: str) -> Execution:
self._check_sandbox_liveness()
self.interpreter.set_timeout(_SESSION_TIMEOUT) # Extend the life of the sandbox
try:
_LOGGER.info(f"Start code execution in remote sandbox {self.interpreter.sandbox_id}. Timeout: {_SESSION_TIMEOUT}. Code hash: {hash(code)}")
Expand All @@ -485,6 +487,7 @@ def exec_cell(self, code: str) -> Execution:
) from e

def upload_file(self, file: Union[str, Path]) -> str:
self._check_sandbox_liveness()
file_name = Path(file).name
remote_path = f"/home/user/{file_name}"
with open(file, "rb") as f:
Expand All @@ -493,6 +496,7 @@ def upload_file(self, file: Union[str, Path]) -> str:
return remote_path

def download_file(self, file_path: str) -> Path:
self._check_sandbox_liveness()
with tempfile.NamedTemporaryFile(mode="w+b", delete=False) as file:
file.write(self.interpreter.files.read(path=file_path, format="bytes"))
_LOGGER.info(f"File ({file_path}) is downloaded to: {file.name}")
Expand All @@ -514,7 +518,7 @@ def _check_sandbox_liveness(self) -> None:
@staticmethod
def _new_e2b_interpreter_impl(*args, **kwargs) -> E2BCodeInterpreterImpl: # type: ignore
template_name = os.environ.get("E2B_TEMPLATE_NAME", "va-sandbox")
_LOGGER.info(f"Creating a new E2BCodeInterpreter instance using template: {template_name}")
_LOGGER.info(f"Creating a new E2BCodeInterpreter using template: {template_name}")
return E2BCodeInterpreterImpl(template=template_name, *args, **kwargs)


Expand Down

0 comments on commit b2c621b

Please sign in to comment.