指南
从零到你自己应用的裁决
你有一个回答问题的 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:answerInitialized 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 runGate: 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 可以再次读取它。