Skip to content

CI 评估

在你自己的 pytest 测试套件中运行 Potato 评估,并用分数阈值把关 CI,让导致智能体质量回退的提示词或模型改动像单元测试一样使构建失败。包含 expect() 断言 API 和一个 GitHub Actions 工作流示例。

在你自己的 pytest 测试套件中运行 Potato 评估,并用聚合分数阈值把关 CI,让导致质量回退的提示词或模型改动像单元测试失败一样使构建失败。这是构建在程序化评估器数据集与实验之上的"评估运维化"层。

安装

插件随 Potato 一起发布,安装后自动加载:

bash
pip install -e .          # registers the `potato_eval` pytest plugin

不安装时可显式加载:pytest -p potato.testing.pytest_plugin

编写评估测试

给测试打上 @pytest.mark.potato_eval 标记并请求 potato_eval fixture:

python
import pytest
from potato.testing import expect
 
@pytest.mark.potato_eval
@pytest.mark.parametrize("case", CASES, ids=[c["q"] for c in CASES])
def test_agent(case, potato_eval):
    out = my_agent(case["q"])
    potato_eval.log_inputs({"question": case["q"]})
    potato_eval.log_outputs(out)
    potato_eval.log_reference_outputs(case["expected"])
 
    potato_eval.log_feedback("correct", 1.0 if out == case["expected"] else 0.0)
    potato_eval.log_feedback("similarity", 1.0 - expect.edit_distance(out, case["expected"]).value)
 
    expect(out).to_contain(case["expected"])   # per-case hard assertion

expect(...) 提供 .to_equal.to_contain.to_be_less_than.to_be_greater_than.to_be_between.to_be_close_to,以及 expect.edit_distance(a, b)expect.embedding_distance(a, b)log_feedback 的分数会在所有评估测试上聚合(按 key 取均值)。

把关构建

bash
pytest tests/eval/ \
  --potato-threshold correct=0.8 \
  --potato-threshold similarity=0.7 \
  --potato-experiment agent-regression
选项效果
--potato-threshold KEY=MINmean(KEY) < MIN 时使运行失败。可重复指定。
--potato-experiment DATASET将本次运行记录为一次实验
--potato-no-sync跳过实验记录。

如果阈值被突破,运行会以非零状态退出(使 CI 作业失败)并打印 THRESHOLD FAILED: <key> = <actual> < <min>。记录的实验是普通文件($POTATO_EVAL_STORE,默认 ./eval_store),可以作为 CI 产物上传。

GitHub Actions

示例工作流位于 examples/agent-traces/ci-eval/ci_workflow_example.yml。它在每个 PR 上运行测试套件、按阈值把关,并将实验记录作为产物上传。

相关内容