JupyterKernelInterpreter

class JupyterKernelInterpreter(BaseInterpreter):

A class for executing code strings in a Jupyter Kernel.

Parameters:

  • require_confirm (bool, optional): If True, prompt user before running code strings for security. Defaults to True.
  • print_stdout (bool, optional): If True, print the standard output of the executed code. Defaults to False.
  • print_stderr (bool, optional): If True, print the standard error of the executed code. Defaults to True.

init

def __init__(
    self,
    require_confirm: bool = True,
    print_stdout: bool = False,
    print_stderr: bool = True
):

del

def __del__(self):

Clean up the kernel and client.

_initialize_if_needed

def _initialize_if_needed(self):

Initialize the kernel manager and client if they are not already initialized.

_clean_ipython_output

def _clean_ipython_output(output: str):

Remove ANSI escape sequences from the output.

_execute

def _execute(self, code: str, timeout: float):

Execute the code in the Jupyter kernel and return the result.

run

def run(self, code: str, code_type: str):

Executes the given code in the Jupyter kernel.

Parameters:

  • code (str): The code string to execute.
  • code_type (str): The type of code to execute (e.g., ‘python’, ‘bash’).

Returns:

str: A string containing the captured result of the executed code.

supported_code_types

def supported_code_types(self):

Returns:

List[str]: Supported code types.

update_action_space

def update_action_space(self, action_space: Dict[str, Any]):

Updates the action space for the interpreter.

Parameters:

  • action_space (Dict[str, Any]): A dictionary representing the new or updated action space.