跳至主要內容

指南

從零到你自己應用程式的裁決

你有一個回答問題的 Python 函式,想知道它是否夠好、可以發布。三個指令就能把這個函式帶到發布決策,無需手寫任何 YAML:oloproof init --system 圍繞你的函式寫入專案,oloproof check 在花費任何東西之前告訴你它能否運作,oloproof run 做出決定。一切都在你的機器上執行,無需帳戶,也不呼叫任何模型。

下面的每一段輸出都來自在所示函式上執行這些指令的結果。

1. 你的函式

任何接收一個案例並回傳答案的函式都可以。這個是 bot.py,它匯入了一個輔助模組:

from prompts import GREETING


def answer(question):
    text = question.lower()
    if "refund" in text:
        reply = "Refunds are available within 30 days of purchase."
    elif "ship" in text:
        reply = "We ship to the US and Canada."
    else:
        reply = "A support agent will follow up within one business day."
    return {"reply": f"{GREETING} {reply}", "topic": "support"}

2. 圍繞它寫入專案

在存放 bot.py 的目錄中執行:

oloproof init --system bot:answer
Initialized Oloproof project in . around bot:answer
  Each case's input is a string, read from the function's first parameter.

Fill in before a run means anything:
  data/cases.jsonl  3 placeholder cases: give each a real input and, as its expected
                    phrase, words a right answer contains. Add more: see below.
  oloproof.yaml     the check reads the whole answer; if your function returns an
                    object, add `field:` naming the key that holds the text.
  release.yaml      a placeholder bar of 0.80; set the one your release needs.

What this suite can decide, if every case is measured:
  mentions-floor (mentions_expected at least 0.8, 3 cases):
    1 or more pass: INSUFFICIENT_EVIDENCE (not established yet); 0: FAIL
    (ruled out). With 50 cases, PASS from 46; with 100, from 89.

Next: oloproof check, then oloproof run

參照會先被匯入,只有當它解析為一個函式時才會寫入任何內容;你的模組中的錯誤會在這裡中止,並指出檔案與行號。函式本身不會被呼叫。會出現三個檔案:oloproof.yaml(你的函式與一個檢查)、data/cases.jsonl(三個佔位案例)與 release.yaml(門檻)。案例的輸入是字串,因為第一個參數名為 question;名為 case、inputs、row 或註記為 dict 的參數則會得到一個物件。

這個檢查是 contains:當答案包含該案例的預期片語時,案例通過。它是確定性的檢查,因此在可以做決定之前不需要與人工標註對照衡量。測試套件指南列出了其他所有檢查與評審器。

3. 填寫案例

把佔位內容換成真實的問題,以及正確答案所包含的詞語,每行一個案例:

{"id": "refund_01", "input": "Can I get a refund?", "expected": {"phrase": "30 days"}}
{"id": "ship_01", "input": "Do you ship to Canada?", "expected": {"phrase": "US and Canada"}}
{"id": "other_01", "input": "My order is late", "expected": {"phrase": "follow up"}}

正如上面的表格所說,三個案例無法通過 0.80 的門檻:只有三個案例時,最好的結果是 INSUFFICIENT_EVIDENCE。下面的執行使用 30 個類似的案例,每個主題十個,其中 29 個通過就足夠了。

4. 執行前先檢查

oloproof check

在設定欄位之前,它的輸出是:

ok   System: callable bot:answer imports.
ok   Called on case refund_01: it answered {"reply": "Thanks for writing in. Refunds are available within 30 days of purchase.", "topic": "support"}

Evaluators on that answer (one case, not a result):
ok   mentions_expected (contains) can read the answer; it passed this case.
note   It reads the whole answer object; `field:` can name one of reply, topic.

於是在 oloproof.yaml 中該檢查下加入 field: reply,再檢查一次:

ok   System: callable bot:answer imports.
ok   Called on case refund_01: it answered {"reply": "Thanks for writing in. Refunds are available within 30 days of purchase.", "topic": "support"}

Evaluators on that answer (one case, not a result):
ok   mentions_expected (contains) can read the answer; it passed this case.

Code: the system's version hashes bot.py, prompts.py. Edit one and the next run calls the system again.

What this suite can decide, if every case is measured:
  mentions-floor (mentions_expected at least 0.8, 30 cases):
    29 or 30 pass: PASS (established); 19 to 28: INSUFFICIENT_EVIDENCE (not
    established yet); 18 or fewer: FAIL (ruled out). With 50 cases, PASS from
    46; with 100, from 89.

CI: no model key is needed for the evaluators. Keys your own function reads are not checked here.

Ready. Next: oloproof run

各部分的意義:

  • 匯入與作答:系統的建置方式與 oloproof run 完全相同,並在第一個案例上呼叫(--case ID 選擇另一個案例,--no-call 略過呼叫)。如果它拋出例外,該行會指出錯誤以及你程式碼中的檔案與行號。
  • 評估器:每個不需要模型的檢查都會在這一個答案上執行。找不到的欄位會被指出,並列出答案中有哪些欄位。這裡的通過或失敗只是一個案例,不是結果。check 從不呼叫模型評審器;它會說明這一點,由執行來呼叫。
  • 程式碼:其內容構成系統版本的檔案:它的模組與其匯入的專案模組,再加上任何 system.code_paths。在匯入或呼叫系統時載入、但不在其中的專案檔案(例如執行時依名稱匯入的模組)會被列為未雜湊:把它加入 code_paths,否則對它的修改會重用過時的答案。
  • 它能決定什麼:與 oloproof plan 相同的表格。沒有 release.yaml 時,它會說明執行只用淺白的話作答,不做任何決定。
  • CI:專案呼叫的每個模型以及 CI 工作為它需要的密鑰:ANTHROPIC_API_KEY 或 OPENAI_API_KEY,除非 api_key_env 指定了其他名稱;本機上的伺服器則不需要。

check 不儲存任何東西。當有必須修正的問題時它以 2 結束,否則以 0 結束;oloproof check --json 把相同的發現以一份文件印出。

5. 執行

oloproof run
Gate: ALLOW (exit 0)
mentions-floor:
  100.0%, range 88.4% to 100.0% (exact binomial interval); 30 of 30 cases

執行報告更長;這裡是它的裁決與該規則的那一行。30 個案例全部通過,通過率所處的範圍從 88.4% 開始,高於 0.80 的門檻,因此該規則給出 PASS,門禁允許發布。oloproof inspect latest 可以再次讀取它。

下一步

  • 把門禁加到拉取請求中:oloproof init --ci github 在此專案旁寫入工作流程(CI 指南)。
  • 當一個片語無法說明什麼是正確答案時,把檢查換成評審器(評審器指南);之後 oloproof check 會指出 CI 需要的密鑰。
  • 答案已經在檔案裡而不是函式中?oloproof eval answers.jsonl 無需任何專案即可檢查它們。