ipython_interpreter
Module Contents
Classes
A IPython executor that can execute Python scripts in a jupyter manner. |
|
A IPython executor that can execute Python scripts in a jupyter manner. |
Functions
|
|
|
|
|
|
|
|
|
Attributes
- lagent.actions.ipython_interpreter.START_CODE = Multiline-String
Show Value
""" def input(*args, **kwargs): raise NotImplementedError('Python input() function is disabled.') get_ipython().system = lambda *args: print('Assume we have this package, ! is disabled!') {} """
- exception lagent.actions.ipython_interpreter.TimeoutError
Bases:
ExceptionCommon base class for all non-exit exceptions.
- exception lagent.actions.ipython_interpreter.KernelDeath
Bases:
ExceptionCommon base class for all non-exit exceptions.
- async lagent.actions.ipython_interpreter.async_run_code(km, code, *, interrupt_after=30, iopub_timeout=40, wait_for_ready_timeout=60, shutdown_kernel=True)
- 参数:
km (jupyter_client.AsyncKernelManager) –
- class lagent.actions.ipython_interpreter.IPythonInterpreter(timeout=20, user_data_dir='ENV', work_dir='./work_dir/tmp_dir', description=None, parser=JsonParser)
Bases:
lagent.actions.base_action.BaseActionA IPython executor that can execute Python scripts in a jupyter manner.
- 参数:
timeout (int) – Upper bound of waiting time for Python script execution. Defaults to 20.
user_data_dir (str, optional) – Specified the user data directory for files loading. If set to ENV, use USER_DATA_DIR environment variable. Defaults to ENV.
work_dir (str, optional) – Specify which directory to save output images to. Defaults to
'./work_dir/tmp_dir'.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 = 20
- user_data_dir = 'ENV'
- work_dir = './work_dir/tmp_dir'
- static start_kernel()
- initialize()
- reset()
- run(command, timeout=None)
When you send a message containing Python code to python, it will be executed in a stateful Jupyter notebook environment. python will respond with the output of the execution or time out after 60.0 seconds. The drive at ‘/mnt/data’ can be used to save and persist user files. Internet access for this session is disabled. Do not make external web requests or API calls as they will fail.
- 参数:
command (
str) – Python codetimeout (
Optional[int]) – Upper bound of waiting time for Python script execution.
- 返回类型:
- class lagent.actions.ipython_interpreter.AsyncIPythonInterpreter(timeout=20, user_data_dir='ENV', work_dir=os.path.join(tempfile.gettempdir(), 'tmp_dir'), max_kernels=None, reuse_kernel=True, startup_rate=32, connection_dir=tempfile.gettempdir(), description=None, parser=JsonParser)
Bases:
lagent.actions.base_action.AsyncActionMixin,IPythonInterpreterA IPython executor that can execute Python scripts in a jupyter manner.
- 参数:
timeout (int) – Upper bound of waiting time for Python script execution. Defaults to 20.
user_data_dir (str, optional) – Specified the user data directory for files loading. If set to ENV, use USER_DATA_DIR environment variable. Defaults to ENV.
work_dir (str, optional) – Specify which directory to save output images to. Defaults to
'./work_dir/tmp_dir'.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.max_kernels (Optional[int]) –
reuse_kernel (bool) –
startup_rate (bool) –
connection_dir (str) –
- async initialize(session_id)
- 参数:
session_id (str) –
- async reset(session_id)
- 参数:
session_id (str) –
- async shutdown(session_id)
- 参数:
session_id (str) –
- async close_session(session_id)
- 参数:
session_id (str) –
- async run(command, timeout=None, session_id=None)
When you send a message containing Python code to python, it will be executed in a stateful Jupyter notebook environment. python will respond with the output of the execution or time out after 60.0 seconds. The drive at ‘/mnt/data’ can be used to save and persist user files. Internet access for this session is disabled. Do not make external web requests or API calls as they will fail.
- 参数:
command (
str) – Python codetimeout (
Optional[int]) – Upper bound of waiting time for Python script execution.session_id (Optional[str]) –
- 返回类型:
- lagent.actions.ipython_interpreter.extract_code(text)
- lagent.actions.ipython_interpreter.escape_ansi(line)
- lagent.actions.ipython_interpreter.publish_image_to_local(image_base64, work_dir='./work_dir/tmp_dir')
- 参数:
image_base64 (str) –
- lagent.actions.ipython_interpreter.get_multiline_input(hint)
- lagent.actions.ipython_interpreter.code_interpreter