APIGenExecutionChecker¶
执行生成的函数调用。
此步骤检查由 APIGenGenerator
生成的模型给出的答案是否可以针对给定库(由 libpath
给定,这是一个指向包含函数的 python .py 文件的字符串)执行。
属性¶
-
libpath: 我们将在其中检索函数的库的路径。它也可以指向包含函数的文件夹。在这种情况下,文件夹布局应为包含 .py 文件的文件夹,每个文件包含单个函数,函数名称与文件名相同。
-
check_is_dangerous: 用于排除一些潜在危险函数的布尔值,它包含在测试中找到的一些启发式方法。这些函数可以运行子进程、处理操作系统或进行其他潜在的危险操作。默认为 True。
输入和输出列¶
graph TD
subgraph Dataset
subgraph Columns
ICOL0[answers]
end
subgraph New columns
OCOL0[keep_row_after_execution_check]
OCOL1[execution_result]
end
end
subgraph APIGenExecutionChecker
StepInput[Input Columns: answers]
StepOutput[Output Columns: keep_row_after_execution_check, execution_result]
end
ICOL0 --> StepInput
StepOutput --> OCOL0
StepOutput --> OCOL1
StepInput --> StepOutput
输入¶
- answers (
str
): 要传递给函数的参数列表,从字典列表转储为字符串。应使用json.loads
加载。
输出¶
-
keep_row_after_execution_check (
bool
): 函数在执行检查后是否应保留。 -
execution_result (
str
): 执行函数的结果。
示例¶
使用来自 LLM 的答案执行给定库中的函数¶
from distilabel.steps.tasks import APIGenExecutionChecker
# For the libpath you can use as an example the file at the tests folder:
# ../distilabel/tests/unit/steps/tasks/apigen/_sample_module.py
task = APIGenExecutionChecker(
libpath="../distilabel/tests/unit/steps/tasks/apigen/_sample_module.py",
)
task.load()
res = next(
task.process(
[
{
"answers": [
{
"arguments": {
"initial_velocity": 0.2,
"acceleration": 0.1,
"time": 0.5,
},
"name": "final_velocity",
}
],
}
]
)
)
res
#[{'answers': [{'arguments': {'initial_velocity': 0.2, 'acceleration': 0.1, 'time': 0.5}, 'name': 'final_velocity'}], 'keep_row_after_execution_check': True, 'execution_result': ['0.25']}]