python_interpreter
Module Contents
Classes
A Python executor that can execute Python scripts. |
|
A Python executor that can execute Python scripts. |
- class lagent.actions.python_interpreter.GenericRuntime
- GLOBAL_DICT
- LOCAL_DICT = None
- HEADERS = []
- exec_code(code_piece)
- 参数:
code_piece (str) –
- 返回类型:
None
- eval_code(expr)
- 参数:
expr (str) –
- 返回类型:
Any
- class lagent.actions.python_interpreter.PythonInterpreter(answer_symbol=None, answer_expr='solution()', answer_from_stdout=False, timeout=20, description=None, parser=JsonParser)
Bases:
lagent.actions.base_action.BaseActionA Python executor that can execute Python scripts.
- 参数:
answer_symbol (str, Optional) – the answer symbol from LLM. Defaults to
None.answer_expr (str, Optional) – the answer function name of the Python script. Defaults to
'solution()'.answer_from_stdout (boolean, Optional) – whether the execution results is from stdout. Defaults to
False.timeout (int, Optional) – Upper bound of waiting time for Python script execution. Defaults to
20.description (dict, Optional) – 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.
- answer_symbol = None
- answer_expr = 'solution()'
- answer_from_stdout = False
- timeout = 20
- run(command)
用来执行Python代码。代码必须是一个函数,函数名必须得是 ‘solution’,代码对应你的思考过程。代码实例格式如下:
```python # import 依赖包 import xxx def solution():
# 初始化一些变量 variable_names_with_real_meaning = xxx # 步骤一 mid_variable = func(variable_names_with_real_meaning) # 步骤 x mid_variable = func(mid_variable) # 最后结果 final_answer = func(mid_variable) return final_answer
- 参数:
command (
str) – Python code snippet- 返回类型:
- class lagent.actions.python_interpreter.AsyncPythonInterpreter(answer_symbol=None, answer_expr='solution()', answer_from_stdout=False, timeout=20, description=None, parser=JsonParser)
Bases:
lagent.actions.base_action.AsyncActionMixin,PythonInterpreterA Python executor that can execute Python scripts.
- 参数:
answer_symbol (str, Optional) – the answer symbol from LLM. Defaults to
None.answer_expr (str, Optional) – the answer function name of the Python script. Defaults to
'solution()'.answer_from_stdout (boolean, Optional) – whether the execution results is from stdout. Defaults to
False.timeout (int, Optional) – Upper bound of waiting time for Python script execution. Defaults to
20.description (dict, Optional) – 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.
- run(command)
用来执行Python代码。代码必须是一个函数,函数名必须得是 ‘solution’,代码对应你的思考过程。代码实例格式如下:
```python # import 依赖包 import xxx def solution():
# 初始化一些变量 variable_names_with_real_meaning = xxx # 步骤一 mid_variable = func(variable_names_with_real_meaning) # 步骤 x mid_variable = func(mid_variable) # 最后结果 final_answer = func(mid_variable) return final_answer
- 参数:
command (
str) – Python code snippet- 返回类型: