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 上執行測試套件、按閾值把關,並將實驗記錄作為產物上傳。

相關內容