| 11 | |
| 12 | |
| 13 | class CodeInterpreter(Sandbox): |
| 14 | template = "code-interpreter-stateful" |
| 15 | |
| 16 | def __init__( |
| 17 | self, |
| 18 | template: Optional[str] = None, |
| 19 | api_key: Optional[str] = None, |
| 20 | cwd: Optional[str] = None, |
| 21 | env_vars: Optional[EnvVars] = None, |
| 22 | timeout: Optional[float] = TIMEOUT, |
| 23 | on_stdout: Optional[Callable[[ProcessMessage], Any]] = None, |
| 24 | on_stderr: Optional[Callable[[ProcessMessage], Any]] = None, |
| 25 | on_exit: Optional[Callable[[int], Any]] = None, |
| 26 | **kwargs, |
| 27 | ): |
| 28 | super().__init__( |
| 29 | template=template or self.template, |
| 30 | api_key=api_key, |
| 31 | cwd=cwd, |
| 32 | env_vars=env_vars, |
| 33 | timeout=timeout, |
| 34 | on_stdout=on_stdout, |
| 35 | on_stderr=on_stderr, |
| 36 | on_exit=on_exit, |
| 37 | **kwargs, |
| 38 | ) |
| 39 | self.notebook = JupyterExtension(self) |
| 40 | # Close all the websocket connections when the interpreter is closed |
| 41 | self._process_cleanup.append(self.notebook.close) |
| 42 | |
| 43 | |
| 44 | class JupyterExtension: |
no outgoing calls
searching dependent graphs…