ipython_interactive

Module Contents

Classes

Status

Execution status.

ExecutionResult

Execution result.

IPythonInteractive

An interactive IPython shell for code execution.

AsyncIPythonInteractive

An interactive IPython shell for code execution.

class lagent.actions.ipython_interactive.Status

Bases: str, enum.Enum

Execution status.

SUCCESS = 'success'
FAILURE = 'failure'
class lagent.actions.ipython_interactive.ExecutionResult

Execution result.

status: Status
value: str | None = None
msg: str | None = None
class lagent.actions.ipython_interactive.IPythonInteractive(timeout=30, max_out_len=8192, use_signals=True, description=None, parser=JsonParser)

Bases: lagent.actions.base_action.BaseAction

An interactive IPython shell for code execution.

参数:
  • timeout (int) – Upper bound of waiting time for Python script execution. Defaults to 20.

  • max_out_len (int) – maximum output length. No truncation occurs if negative. Defaults to 2048.

  • use_signals (bool) – whether signals should be used for timing function out or the multiprocessing. Set to False when not running in the main thread, e.g. web applications. Defaults to True

  • description (dict) – The description of the action. Defaults to None.

  • parser (Type[BaseParser]) – The parser class to process the action’s inputs and outputs. Defaults to JsonParser.

timeout = 30
reset()

Clear the context.

run(command, timeout=None)

Launch an IPython Interactive Shell to execute code.

参数:
  • command (str) – Python code snippet

  • timeout (Optional[int]) – timeout for execution. This argument only works in the main thread. Defaults to None.

返回类型:

lagent.schema.ActionReturn

exec(code)

Run Python scripts in IPython shell.

参数:

code (str) – code block

返回:

execution result

返回类型:

ExecutionResult

static create_shell()
static extract_code(text)

Extract Python code from markup languages.

参数:

text (str) – Markdown-formatted text

返回:

Python code

返回类型:

str

static wrap_code_with_timeout(code, timeout)
参数:
  • code (str) –

  • timeout (int) –

返回类型:

str

class lagent.actions.ipython_interactive.AsyncIPythonInteractive(timeout=30, max_out_len=8192, use_signals=True, description=None, parser=JsonParser)

Bases: lagent.actions.base_action.AsyncActionMixin, IPythonInteractive

An interactive IPython shell for code execution.

参数:
  • timeout (int) – Upper bound of waiting time for Python script execution. Defaults to 20.

  • max_out_len (int) – maximum output length. No truncation occurs if negative. Defaults to 2048.

  • use_signals (bool) – whether signals should be used for timing function out or the multiprocessing. Set to False when not running in the main thread, e.g. web applications. Defaults to True

  • description (dict) – The description of the action. Defaults to None.

  • parser (Type[BaseParser]) – The parser class to process the action’s inputs and outputs. Defaults to JsonParser.

async run(command, timeout=None)

Launch an IPython Interactive Shell to execute code.

参数:
  • command (str) – Python code snippet

  • timeout (Optional[int]) – timeout for execution. This argument only works in the main thread. Defaults to None.

返回类型:

lagent.schema.ActionReturn

async exec(code, timeout=None)

Asynchronously run Python scripts in IPython shell.

参数:
  • code (str) – code block

  • timeout (int) – max waiting time for code execution

返回:

execution result

返回类型:

ExecutionResult