valueproof 0.4.0__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {valueproof-0.4.0/src/valueproof.egg-info → valueproof-0.6.0}/PKG-INFO +72 -32
- {valueproof-0.4.0 → valueproof-0.6.0}/README.md +71 -31
- {valueproof-0.4.0 → valueproof-0.6.0}/pyproject.toml +1 -1
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof/__init__.py +6 -3
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof/cli.py +56 -6
- valueproof-0.6.0/src/valueproof/lever_runner.py +383 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof/starter.py +3 -2
- {valueproof-0.4.0 → valueproof-0.6.0/src/valueproof.egg-info}/PKG-INFO +72 -32
- valueproof-0.6.0/tests/test_runner_cli.py +158 -0
- valueproof-0.4.0/src/valueproof/lever_runner.py +0 -161
- valueproof-0.4.0/tests/test_runner_cli.py +0 -58
- {valueproof-0.4.0 → valueproof-0.6.0}/LICENSE-CODE +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/setup.cfg +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/mixed_model_cost/__init__.py +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof/claude.py +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof/gemini.py +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof/openai.py +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof/pipeline.py +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof/scout_rescue.py +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof.egg-info/SOURCES.txt +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof.egg-info/dependency_links.txt +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof.egg-info/entry_points.txt +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof.egg-info/requires.txt +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/src/valueproof.egg-info/top_level.txt +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/tests/test_adapters.py +0 -0
- {valueproof-0.4.0 → valueproof-0.6.0}/tests/test_core.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: valueproof
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Prove an AI cost cut on your own traffic before you ship it: cheap and strong models working together (Scout & Rescue), measured by cost per outcome with a blind quality review.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/AndyJakob78/valueproof
|
|
@@ -33,9 +33,36 @@ Dynamic: license-file
|
|
|
33
33
|
**Prove an AI cost cut on your own traffic before you ship it. Let cheap and strong models work together, and measure cost per outcome — not cost per token.**
|
|
34
34
|
|
|
35
35
|
**In 30 seconds:**
|
|
36
|
-
- **What it is:** a method and a small Python tool. A cheap model does the work first; a strong model steps in only when a check in code rejects the result (*Scout & Rescue*). Every change is tested side by side against your current setup on your own requests, with a blind quality review.
|
|
37
|
-
- **What we measured:** on a live app's web-search step, cost per article fell from 9.7 ¢ to 4.6–7.7 ¢, and quality held in a blind review. On 40 support tickets, a usable
|
|
38
|
-
- **The trade-off:** on the support tickets, quality was 2–6% lower, and one wrong refund rule slipped past the checks.
|
|
36
|
+
- **What it is:** a method and a small Python tool that cuts what AI features cost on live user traffic, and proves output quality before you ship the change. A cheap model does the work first; a strong model steps in only when a check in code rejects the result (*Scout & Rescue*). Every change is tested side by side against your current setup on your own requests, with a blind quality review.
|
|
37
|
+
- **What we measured:** on a live app's web-search step, cost per article fell from 9.7 ¢ to 4.6–7.7 ¢, and quality held in a blind review. On 40 support tickets, a usable reply cost 82–92% less than with Claude Opus 5.5 alone, over three runs.
|
|
38
|
+
- **The trade-off:** on the support tickets, quality was 2–6% lower, and one wrong refund rule slipped past the checks. The test also showed that the cheap model alone was nearly as good there: the rescuer pays off only where failures are common and a check can catch them.
|
|
39
|
+
|
|
40
|
+
## Quick start
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install "valueproof[claude]" # or [openai], [gemini], [all]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from valueproof import scout_and_rescue
|
|
48
|
+
from valueproof.claude import claude
|
|
49
|
+
|
|
50
|
+
ticket = "Where is my order 48213?"
|
|
51
|
+
out = scout_and_rescue(
|
|
52
|
+
"Reply to this support ticket: " + ticket,
|
|
53
|
+
scout=claude("claude-haiku-5-5"), # the cheap model tries first
|
|
54
|
+
rescue=claude("claude-opus-5-5"), # the frontier model runs only if the check fails
|
|
55
|
+
check=lambda text: None if "48213" in text else "order number missing",
|
|
56
|
+
)
|
|
57
|
+
print(out.path, out.cost_usd) # "scout" or "rescue", and what it cost
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Then compare setups on your own requests — offline first, with fake models:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
valueproof init my_test.py
|
|
64
|
+
valueproof compare my_test.py
|
|
65
|
+
```
|
|
39
66
|
|
|
40
67
|
## When it fits
|
|
41
68
|
|
|
@@ -45,6 +72,7 @@ It fits when your product sends a lot of requests to a frontier model — such a
|
|
|
45
72
|
- data extraction
|
|
46
73
|
- search and research assistants
|
|
47
74
|
- document summarizers
|
|
75
|
+
- code translation and migration (e.g. Java to Kotlin) — the checks are exact: does it compile, do the tests pass
|
|
48
76
|
|
|
49
77
|
And most of those requests are routine, and a bad result can be detected in code: an empty result, a missing field, an outdated date, or an invalid format.
|
|
50
78
|
|
|
@@ -69,7 +97,7 @@ Most cost tools stop at the first row. This method measures the second before yo
|
|
|
69
97
|
| **AI Engineer** | A small Python package: Scout & Rescue, multi-model pipelines, and a test runner (`valueproof compare`) |
|
|
70
98
|
| **Prompt & Context Engineer** | A test routine that shows whether a prompt change really saves tokens — or quietly costs more |
|
|
71
99
|
| **AI Builder** | A way to test cheaper setups for an AI app on a small budget, and keep only those that hold quality |
|
|
72
|
-
| **AI Evaluation** | A blind
|
|
100
|
+
| **AI Evaluation** | A blind review (LLM-as-judge or a person) on a fixed rubric, plus a measure of how good your eval checks are |
|
|
73
101
|
| **LLMOps** | Code checks and logging that track how often the expensive model runs |
|
|
74
102
|
| **FinOps** | A clear before-and-after cost per request, and the yearly saving at your scale |
|
|
75
103
|
|
|
@@ -143,10 +171,16 @@ We then ran the support-reply step of this idea for real: 40 made-up tickets (20
|
|
|
143
171
|
|
|
144
172
|
| | Scout & Rescue | Opus 5.5 alone |
|
|
145
173
|
|---|---|---|
|
|
146
|
-
| Cost per reply | **81–
|
|
147
|
-
| Quality (blind review,
|
|
174
|
+
| Cost per reply (three runs) | **81–92% less** | — |
|
|
175
|
+
| Quality (blind review, three runs) | **2–6% lower** | — |
|
|
148
176
|
| Hard failures (run 2, 40 tickets) | 3 | 2 |
|
|
149
|
-
| **Cost per outcome** (
|
|
177
|
+
| **Cost per outcome** (three runs) | **82–92% less** | — |
|
|
178
|
+
|
|
179
|
+
**Is the rescuer worth it? Here, barely.** In a third run we added the cheap model alone: it cost 0.025 ¢ per outcome against 0.069 ¢ for Scout & Rescue and 0.92 ¢ for Opus, with nearly the same quality as Scout & Rescue. The rescuer ran on 2 of 40 tickets. On this task the saving comes from the cheap model; the rescuer is cheap insurance.
|
|
180
|
+
|
|
181
|
+
**Code checks catch form; a check by a model catches substance.** Our code checks missed every hard failure. A fourth run added a policy check by the cheap model: it caught the one hard failure, and the gap to Opus shrank from 4.7% to 3.5% — for twice the cost per reply and twice the false alarms, still 73% cheaper per outcome than Opus alone. One case is thin evidence; it shows the direction.
|
|
182
|
+
|
|
183
|
+
**Then make it cheaper again, one lever at a time.** A fifth run tested five levers on that setup, each with an estimate written down first. Sonnet as the rescuer instead of Opus: −58% cost, same quality. Lower effort, dropping an over-strict rule, and checking only the topics the product owner marks high-risk: −29% to −45% each. All three stacked: −75%, but the quality gain was gone. `valueproof compare` prints this keep-or-drop ledger itself.
|
|
150
184
|
|
|
151
185
|
**Good for cost, with a quality trade-off.** Most cheap replies were good, but some were weaker in ways no check saw, and one stated a wrong refund rule. Use it where a few percent of quality is acceptable, or where your checks catch the mistakes that matter; keep refund, money and legal answers on the strong model until they do. → [Full results, caveats and how to rerun it](https://github.com/AndyJakob78/valueproof/blob/main/docs/support-test.md)
|
|
152
186
|
|
|
@@ -176,22 +210,11 @@ flowchart LR
|
|
|
176
210
|
|
|
177
211
|
The checks decide the quality: a mistake no check catches goes straight to the user at the cheap price.
|
|
178
212
|
|
|
179
|
-
**Expect a small quality cost.** Requests that pass the check are only as good as the cheap model's answer. In our support test, Scout & Rescue cost 81–
|
|
213
|
+
**Expect a small quality cost.** Requests that pass the check are only as good as the cheap model's answer. In our support test, Scout & Rescue cost 81–92% less than the strong model alone and scored 2–6% lower in a blind review — a much stronger cost lever than tuning the strong model, with a quality trade-off you should measure for your own task. How much quality you keep depends mostly on your checks.
|
|
180
214
|
|
|
181
|
-
|
|
182
|
-
from valueproof import scout_and_rescue
|
|
183
|
-
from valueproof.claude import claude
|
|
215
|
+
The code for this is in the [quick start](#quick-start) at the top.
|
|
184
216
|
|
|
185
|
-
|
|
186
|
-
prompt, # your request
|
|
187
|
-
scout=claude("claude-haiku-5-5"),
|
|
188
|
-
rescue=claude("claude-opus-5-5"),
|
|
189
|
-
check=lambda text: None if order_id in text else "does not mention the order id", # order_id from your data
|
|
190
|
-
)
|
|
191
|
-
print(outcome.path, outcome.cost_usd) # "scout" or "rescue" - how often each runs depends on your checks
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
**Install** (version 0.3, early: the API may still change; Python 3.10+, Gemini adapter 3.11+):
|
|
217
|
+
**Install** (version 0.6, early: the API may still change; Python 3.10+, Gemini adapter 3.11+):
|
|
195
218
|
|
|
196
219
|
```bash
|
|
197
220
|
pip install "valueproof[claude]"
|
|
@@ -199,25 +222,23 @@ pip install "valueproof[claude]"
|
|
|
199
222
|
|
|
200
223
|
One name for everything: `pip install valueproof`, `import valueproof`, `valueproof compare`. (Until version 0.3 the package was called `ai-mixed-model-cost-optimization`; the old name still installs and pulls in `valueproof`.)
|
|
201
224
|
|
|
202
|
-
```python
|
|
203
|
-
from valueproof import scout_and_rescue
|
|
204
|
-
from valueproof.claude import claude # or .openai / .gemini
|
|
205
|
-
```
|
|
206
|
-
|
|
207
225
|
The core has no dependencies and works with any provider: a model is just a function `prompt -> ModelResult`. Adapters come as extras: `[claude]`, `[openai]`, `[gemini]` or `[all]`. For a local model, write a function with the same shape.
|
|
208
226
|
|
|
209
227
|
**Test a change on your own requests** with one command — it runs every setup on every request, side by side, and prints cost (average and median), rescue rate, time, check failures and blind-review quality:
|
|
210
228
|
|
|
211
229
|
```bash
|
|
212
|
-
valueproof init my_test.py
|
|
213
|
-
valueproof compare my_test.py --live
|
|
230
|
+
valueproof init my_test.py # a starter test that runs straight away, with fake models
|
|
231
|
+
valueproof compare my_test.py --live --estimate # runs 2 requests for real, prints the projected bill
|
|
232
|
+
valueproof compare my_test.py --live --max-spend 5 # the full test, stops starting new requests at $5
|
|
214
233
|
```
|
|
215
234
|
|
|
235
|
+
If your test file names its levers, it prints the **lever ledger**: each lever against the setup it changes, your estimate from before the test, and a keep-or-drop verdict. After the table it lists **which check rule fired most often**, and **how good your eval checks are**: how many of the judge's hard failures they caught, how many they missed, and how many false alarms they raised. In our own support test the answer was sobering: the code checks caught 0 of 7 hard failures. You can also **rate candidate eval checks** before you build on one: with a policy check done by a cheap model, the one hard failure in that run was caught and fixed, for about twice the cost per reply. → [Support test](https://github.com/AndyJakob78/valueproof/blob/main/docs/support-test.md)
|
|
236
|
+
|
|
216
237
|
→ How to write `my_test.py`, plus a support-ticket demo that works without an API key: [examples/](https://github.com/AndyJakob78/valueproof/blob/main/examples/). The live Claude mode was run in the [support test](https://github.com/AndyJakob78/valueproof/blob/main/docs/support-test.md).
|
|
217
238
|
|
|
218
239
|
**A second, smaller lever: lower effort on the strong model.** In the same test, running the rescuer at effort low instead of medium cost 24–25% less in two runs, with no measurable quality loss on the rescued tickets. Measured on short support replies only.
|
|
219
240
|
|
|
220
|
-
**3. Prove every change before you ship it.** Change one thing at a time. Run the old and new versions side by side on the same requests. Review quality blind
|
|
241
|
+
**3. Prove every change before you ship it.** Change one thing at a time. Run the old and new versions side by side on the same requests. Review quality blind: the reviewer never knows which setup wrote a result. Keep only what saves money *and* holds quality.
|
|
221
242
|
|
|
222
243
|
The test setup is an **eval**: a fixed set of real requests, checks in code and a blind review, built once and reused for every change. Without it you can't tell a saving from a quality loss.
|
|
223
244
|
|
|
@@ -231,6 +252,23 @@ flowchart LR
|
|
|
231
252
|
L -- "no levers left" --> S["4. Test all kept levers together,<br/>ship, keep measuring"]
|
|
232
253
|
```
|
|
233
254
|
|
|
255
|
+
**How the blind review works.** `valueproof compare` supports two reviewers, and you can use both:
|
|
256
|
+
|
|
257
|
+
- **LLM-as-judge:** you pass a `judge(case, text) -> Score` function. It gets one result at a time, in random order, and never the setup's name. Give it the reference that defines "right" (the policy, the fact sheet, the help article); without it a judge can only tell whether an answer looks usable, not whether it is correct.
|
|
258
|
+
- **A person:** every run also writes `blind_review.csv` (the results, shuffled, no setup names) and `blind_key.csv` (which setup wrote which). Score the sheet, then map it back with the key.
|
|
259
|
+
|
|
260
|
+
The rubric from our support test, as an example — four criteria, 0–10 each, plus one flag:
|
|
261
|
+
|
|
262
|
+
| Criterion | The question |
|
|
263
|
+
|---|---|
|
|
264
|
+
| Policy correct | Does the reply follow the policy exactly, with no wrong rule? |
|
|
265
|
+
| Solves | Does it answer every issue in the ticket and name the next step? |
|
|
266
|
+
| Tone | Friendly, calm, fitting the customer's mood? |
|
|
267
|
+
| Clarity | Short and clear? |
|
|
268
|
+
| **Hard failure** (yes/no) | A wrong policy rule, a promise the policy doesn't allow, an invented order number, or no answer |
|
|
269
|
+
|
|
270
|
+
Hard failures are counted separately, so no average can hide them. For scoring two results side by side as A and B by hand, see the [rubric template](https://github.com/AndyJakob78/valueproof/blob/main/templates/blind-review-rubric.md).
|
|
271
|
+
|
|
234
272
|
The full flow, with the cost breakdown and the ledger: [method.md](https://github.com/AndyJakob78/valueproof/blob/main/docs/method.md#the-flow)
|
|
235
273
|
|
|
236
274
|
→ The step-by-step method: [docs/method.md](https://github.com/AndyJakob78/valueproof/blob/main/docs/method.md) · Templates: [templates/](https://github.com/AndyJakob78/valueproof/blob/main/templates/)
|
|
@@ -259,10 +297,12 @@ We tested 12 cost-saving ideas one at a time, and **7 raised cost or lowered qua
|
|
|
259
297
|
- **Token:** the unit AI providers bill by — roughly a short word of text the model reads or writes.
|
|
260
298
|
- **Lever:** one change that should lower cost, such as a smaller model or a shorter prompt. Each lever is tested on its own.
|
|
261
299
|
- **Scout:** the cheap, fast model that tries first.
|
|
262
|
-
- **Rescuer:** the strong model that runs only when
|
|
300
|
+
- **Rescuer:** the strong model that runs only when an eval check rejects the scout's result.
|
|
301
|
+
- **Eval check:** a rule in code that judges one answer at runtime (a code-based eval): is it empty, is a field missing, is the date too old? It decides whether the cheap answer is used or the rescuer runs. The pages here also call it a "check in code" or just "check".
|
|
302
|
+
- **Check quality:** how well the eval checks agree with the blind review: caught, missed, false alarms.
|
|
263
303
|
- **Full web search:** a search tool that filters the results with code before the model reads them. Fewer pages to read, but more steps.
|
|
264
304
|
- **Simple web search:** a search tool that hands the raw results straight to the model. Fewer steps; the model reads everything it gets, which is cheap on a small model but expensive on a large one.
|
|
265
|
-
- **Blind review:** a reviewer scores
|
|
305
|
+
- **Blind review:** a reviewer scores results on a fixed rubric without knowing which setup wrote them. The reviewer can be a model (LLM-as-judge) or a person.
|
|
266
306
|
- **Eval:** the fixed test that decides whether a change is kept — real requests, checks in code and a blind review, run the same way every time.
|
|
267
307
|
- **Outcome:** a request whose final result passed your checks and, if reviewed, had no hard failure — a result a user could rely on.
|
|
268
308
|
- **Cost per outcome:** everything a setup spent, including failed and rescued attempts, divided by its outcomes. The number to compare.
|
|
@@ -5,9 +5,36 @@
|
|
|
5
5
|
**Prove an AI cost cut on your own traffic before you ship it. Let cheap and strong models work together, and measure cost per outcome — not cost per token.**
|
|
6
6
|
|
|
7
7
|
**In 30 seconds:**
|
|
8
|
-
- **What it is:** a method and a small Python tool. A cheap model does the work first; a strong model steps in only when a check in code rejects the result (*Scout & Rescue*). Every change is tested side by side against your current setup on your own requests, with a blind quality review.
|
|
9
|
-
- **What we measured:** on a live app's web-search step, cost per article fell from 9.7 ¢ to 4.6–7.7 ¢, and quality held in a blind review. On 40 support tickets, a usable
|
|
10
|
-
- **The trade-off:** on the support tickets, quality was 2–6% lower, and one wrong refund rule slipped past the checks.
|
|
8
|
+
- **What it is:** a method and a small Python tool that cuts what AI features cost on live user traffic, and proves output quality before you ship the change. A cheap model does the work first; a strong model steps in only when a check in code rejects the result (*Scout & Rescue*). Every change is tested side by side against your current setup on your own requests, with a blind quality review.
|
|
9
|
+
- **What we measured:** on a live app's web-search step, cost per article fell from 9.7 ¢ to 4.6–7.7 ¢, and quality held in a blind review. On 40 support tickets, a usable reply cost 82–92% less than with Claude Opus 5.5 alone, over three runs.
|
|
10
|
+
- **The trade-off:** on the support tickets, quality was 2–6% lower, and one wrong refund rule slipped past the checks. The test also showed that the cheap model alone was nearly as good there: the rescuer pays off only where failures are common and a check can catch them.
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install "valueproof[claude]" # or [openai], [gemini], [all]
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from valueproof import scout_and_rescue
|
|
20
|
+
from valueproof.claude import claude
|
|
21
|
+
|
|
22
|
+
ticket = "Where is my order 48213?"
|
|
23
|
+
out = scout_and_rescue(
|
|
24
|
+
"Reply to this support ticket: " + ticket,
|
|
25
|
+
scout=claude("claude-haiku-5-5"), # the cheap model tries first
|
|
26
|
+
rescue=claude("claude-opus-5-5"), # the frontier model runs only if the check fails
|
|
27
|
+
check=lambda text: None if "48213" in text else "order number missing",
|
|
28
|
+
)
|
|
29
|
+
print(out.path, out.cost_usd) # "scout" or "rescue", and what it cost
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Then compare setups on your own requests — offline first, with fake models:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
valueproof init my_test.py
|
|
36
|
+
valueproof compare my_test.py
|
|
37
|
+
```
|
|
11
38
|
|
|
12
39
|
## When it fits
|
|
13
40
|
|
|
@@ -17,6 +44,7 @@ It fits when your product sends a lot of requests to a frontier model — such a
|
|
|
17
44
|
- data extraction
|
|
18
45
|
- search and research assistants
|
|
19
46
|
- document summarizers
|
|
47
|
+
- code translation and migration (e.g. Java to Kotlin) — the checks are exact: does it compile, do the tests pass
|
|
20
48
|
|
|
21
49
|
And most of those requests are routine, and a bad result can be detected in code: an empty result, a missing field, an outdated date, or an invalid format.
|
|
22
50
|
|
|
@@ -41,7 +69,7 @@ Most cost tools stop at the first row. This method measures the second before yo
|
|
|
41
69
|
| **AI Engineer** | A small Python package: Scout & Rescue, multi-model pipelines, and a test runner (`valueproof compare`) |
|
|
42
70
|
| **Prompt & Context Engineer** | A test routine that shows whether a prompt change really saves tokens — or quietly costs more |
|
|
43
71
|
| **AI Builder** | A way to test cheaper setups for an AI app on a small budget, and keep only those that hold quality |
|
|
44
|
-
| **AI Evaluation** | A blind
|
|
72
|
+
| **AI Evaluation** | A blind review (LLM-as-judge or a person) on a fixed rubric, plus a measure of how good your eval checks are |
|
|
45
73
|
| **LLMOps** | Code checks and logging that track how often the expensive model runs |
|
|
46
74
|
| **FinOps** | A clear before-and-after cost per request, and the yearly saving at your scale |
|
|
47
75
|
|
|
@@ -115,10 +143,16 @@ We then ran the support-reply step of this idea for real: 40 made-up tickets (20
|
|
|
115
143
|
|
|
116
144
|
| | Scout & Rescue | Opus 5.5 alone |
|
|
117
145
|
|---|---|---|
|
|
118
|
-
| Cost per reply | **81–
|
|
119
|
-
| Quality (blind review,
|
|
146
|
+
| Cost per reply (three runs) | **81–92% less** | — |
|
|
147
|
+
| Quality (blind review, three runs) | **2–6% lower** | — |
|
|
120
148
|
| Hard failures (run 2, 40 tickets) | 3 | 2 |
|
|
121
|
-
| **Cost per outcome** (
|
|
149
|
+
| **Cost per outcome** (three runs) | **82–92% less** | — |
|
|
150
|
+
|
|
151
|
+
**Is the rescuer worth it? Here, barely.** In a third run we added the cheap model alone: it cost 0.025 ¢ per outcome against 0.069 ¢ for Scout & Rescue and 0.92 ¢ for Opus, with nearly the same quality as Scout & Rescue. The rescuer ran on 2 of 40 tickets. On this task the saving comes from the cheap model; the rescuer is cheap insurance.
|
|
152
|
+
|
|
153
|
+
**Code checks catch form; a check by a model catches substance.** Our code checks missed every hard failure. A fourth run added a policy check by the cheap model: it caught the one hard failure, and the gap to Opus shrank from 4.7% to 3.5% — for twice the cost per reply and twice the false alarms, still 73% cheaper per outcome than Opus alone. One case is thin evidence; it shows the direction.
|
|
154
|
+
|
|
155
|
+
**Then make it cheaper again, one lever at a time.** A fifth run tested five levers on that setup, each with an estimate written down first. Sonnet as the rescuer instead of Opus: −58% cost, same quality. Lower effort, dropping an over-strict rule, and checking only the topics the product owner marks high-risk: −29% to −45% each. All three stacked: −75%, but the quality gain was gone. `valueproof compare` prints this keep-or-drop ledger itself.
|
|
122
156
|
|
|
123
157
|
**Good for cost, with a quality trade-off.** Most cheap replies were good, but some were weaker in ways no check saw, and one stated a wrong refund rule. Use it where a few percent of quality is acceptable, or where your checks catch the mistakes that matter; keep refund, money and legal answers on the strong model until they do. → [Full results, caveats and how to rerun it](https://github.com/AndyJakob78/valueproof/blob/main/docs/support-test.md)
|
|
124
158
|
|
|
@@ -148,22 +182,11 @@ flowchart LR
|
|
|
148
182
|
|
|
149
183
|
The checks decide the quality: a mistake no check catches goes straight to the user at the cheap price.
|
|
150
184
|
|
|
151
|
-
**Expect a small quality cost.** Requests that pass the check are only as good as the cheap model's answer. In our support test, Scout & Rescue cost 81–
|
|
185
|
+
**Expect a small quality cost.** Requests that pass the check are only as good as the cheap model's answer. In our support test, Scout & Rescue cost 81–92% less than the strong model alone and scored 2–6% lower in a blind review — a much stronger cost lever than tuning the strong model, with a quality trade-off you should measure for your own task. How much quality you keep depends mostly on your checks.
|
|
152
186
|
|
|
153
|
-
|
|
154
|
-
from valueproof import scout_and_rescue
|
|
155
|
-
from valueproof.claude import claude
|
|
187
|
+
The code for this is in the [quick start](#quick-start) at the top.
|
|
156
188
|
|
|
157
|
-
|
|
158
|
-
prompt, # your request
|
|
159
|
-
scout=claude("claude-haiku-5-5"),
|
|
160
|
-
rescue=claude("claude-opus-5-5"),
|
|
161
|
-
check=lambda text: None if order_id in text else "does not mention the order id", # order_id from your data
|
|
162
|
-
)
|
|
163
|
-
print(outcome.path, outcome.cost_usd) # "scout" or "rescue" - how often each runs depends on your checks
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
**Install** (version 0.3, early: the API may still change; Python 3.10+, Gemini adapter 3.11+):
|
|
189
|
+
**Install** (version 0.6, early: the API may still change; Python 3.10+, Gemini adapter 3.11+):
|
|
167
190
|
|
|
168
191
|
```bash
|
|
169
192
|
pip install "valueproof[claude]"
|
|
@@ -171,25 +194,23 @@ pip install "valueproof[claude]"
|
|
|
171
194
|
|
|
172
195
|
One name for everything: `pip install valueproof`, `import valueproof`, `valueproof compare`. (Until version 0.3 the package was called `ai-mixed-model-cost-optimization`; the old name still installs and pulls in `valueproof`.)
|
|
173
196
|
|
|
174
|
-
```python
|
|
175
|
-
from valueproof import scout_and_rescue
|
|
176
|
-
from valueproof.claude import claude # or .openai / .gemini
|
|
177
|
-
```
|
|
178
|
-
|
|
179
197
|
The core has no dependencies and works with any provider: a model is just a function `prompt -> ModelResult`. Adapters come as extras: `[claude]`, `[openai]`, `[gemini]` or `[all]`. For a local model, write a function with the same shape.
|
|
180
198
|
|
|
181
199
|
**Test a change on your own requests** with one command — it runs every setup on every request, side by side, and prints cost (average and median), rescue rate, time, check failures and blind-review quality:
|
|
182
200
|
|
|
183
201
|
```bash
|
|
184
|
-
valueproof init my_test.py
|
|
185
|
-
valueproof compare my_test.py --live
|
|
202
|
+
valueproof init my_test.py # a starter test that runs straight away, with fake models
|
|
203
|
+
valueproof compare my_test.py --live --estimate # runs 2 requests for real, prints the projected bill
|
|
204
|
+
valueproof compare my_test.py --live --max-spend 5 # the full test, stops starting new requests at $5
|
|
186
205
|
```
|
|
187
206
|
|
|
207
|
+
If your test file names its levers, it prints the **lever ledger**: each lever against the setup it changes, your estimate from before the test, and a keep-or-drop verdict. After the table it lists **which check rule fired most often**, and **how good your eval checks are**: how many of the judge's hard failures they caught, how many they missed, and how many false alarms they raised. In our own support test the answer was sobering: the code checks caught 0 of 7 hard failures. You can also **rate candidate eval checks** before you build on one: with a policy check done by a cheap model, the one hard failure in that run was caught and fixed, for about twice the cost per reply. → [Support test](https://github.com/AndyJakob78/valueproof/blob/main/docs/support-test.md)
|
|
208
|
+
|
|
188
209
|
→ How to write `my_test.py`, plus a support-ticket demo that works without an API key: [examples/](https://github.com/AndyJakob78/valueproof/blob/main/examples/). The live Claude mode was run in the [support test](https://github.com/AndyJakob78/valueproof/blob/main/docs/support-test.md).
|
|
189
210
|
|
|
190
211
|
**A second, smaller lever: lower effort on the strong model.** In the same test, running the rescuer at effort low instead of medium cost 24–25% less in two runs, with no measurable quality loss on the rescued tickets. Measured on short support replies only.
|
|
191
212
|
|
|
192
|
-
**3. Prove every change before you ship it.** Change one thing at a time. Run the old and new versions side by side on the same requests. Review quality blind
|
|
213
|
+
**3. Prove every change before you ship it.** Change one thing at a time. Run the old and new versions side by side on the same requests. Review quality blind: the reviewer never knows which setup wrote a result. Keep only what saves money *and* holds quality.
|
|
193
214
|
|
|
194
215
|
The test setup is an **eval**: a fixed set of real requests, checks in code and a blind review, built once and reused for every change. Without it you can't tell a saving from a quality loss.
|
|
195
216
|
|
|
@@ -203,6 +224,23 @@ flowchart LR
|
|
|
203
224
|
L -- "no levers left" --> S["4. Test all kept levers together,<br/>ship, keep measuring"]
|
|
204
225
|
```
|
|
205
226
|
|
|
227
|
+
**How the blind review works.** `valueproof compare` supports two reviewers, and you can use both:
|
|
228
|
+
|
|
229
|
+
- **LLM-as-judge:** you pass a `judge(case, text) -> Score` function. It gets one result at a time, in random order, and never the setup's name. Give it the reference that defines "right" (the policy, the fact sheet, the help article); without it a judge can only tell whether an answer looks usable, not whether it is correct.
|
|
230
|
+
- **A person:** every run also writes `blind_review.csv` (the results, shuffled, no setup names) and `blind_key.csv` (which setup wrote which). Score the sheet, then map it back with the key.
|
|
231
|
+
|
|
232
|
+
The rubric from our support test, as an example — four criteria, 0–10 each, plus one flag:
|
|
233
|
+
|
|
234
|
+
| Criterion | The question |
|
|
235
|
+
|---|---|
|
|
236
|
+
| Policy correct | Does the reply follow the policy exactly, with no wrong rule? |
|
|
237
|
+
| Solves | Does it answer every issue in the ticket and name the next step? |
|
|
238
|
+
| Tone | Friendly, calm, fitting the customer's mood? |
|
|
239
|
+
| Clarity | Short and clear? |
|
|
240
|
+
| **Hard failure** (yes/no) | A wrong policy rule, a promise the policy doesn't allow, an invented order number, or no answer |
|
|
241
|
+
|
|
242
|
+
Hard failures are counted separately, so no average can hide them. For scoring two results side by side as A and B by hand, see the [rubric template](https://github.com/AndyJakob78/valueproof/blob/main/templates/blind-review-rubric.md).
|
|
243
|
+
|
|
206
244
|
The full flow, with the cost breakdown and the ledger: [method.md](https://github.com/AndyJakob78/valueproof/blob/main/docs/method.md#the-flow)
|
|
207
245
|
|
|
208
246
|
→ The step-by-step method: [docs/method.md](https://github.com/AndyJakob78/valueproof/blob/main/docs/method.md) · Templates: [templates/](https://github.com/AndyJakob78/valueproof/blob/main/templates/)
|
|
@@ -231,10 +269,12 @@ We tested 12 cost-saving ideas one at a time, and **7 raised cost or lowered qua
|
|
|
231
269
|
- **Token:** the unit AI providers bill by — roughly a short word of text the model reads or writes.
|
|
232
270
|
- **Lever:** one change that should lower cost, such as a smaller model or a shorter prompt. Each lever is tested on its own.
|
|
233
271
|
- **Scout:** the cheap, fast model that tries first.
|
|
234
|
-
- **Rescuer:** the strong model that runs only when
|
|
272
|
+
- **Rescuer:** the strong model that runs only when an eval check rejects the scout's result.
|
|
273
|
+
- **Eval check:** a rule in code that judges one answer at runtime (a code-based eval): is it empty, is a field missing, is the date too old? It decides whether the cheap answer is used or the rescuer runs. The pages here also call it a "check in code" or just "check".
|
|
274
|
+
- **Check quality:** how well the eval checks agree with the blind review: caught, missed, false alarms.
|
|
235
275
|
- **Full web search:** a search tool that filters the results with code before the model reads them. Fewer pages to read, but more steps.
|
|
236
276
|
- **Simple web search:** a search tool that hands the raw results straight to the model. Fewer steps; the model reads everything it gets, which is cheap on a small model but expensive on a large one.
|
|
237
|
-
- **Blind review:** a reviewer scores
|
|
277
|
+
- **Blind review:** a reviewer scores results on a fixed rubric without knowing which setup wrote them. The reviewer can be a model (LLM-as-judge) or a person.
|
|
238
278
|
- **Eval:** the fixed test that decides whether a change is kept — real requests, checks in code and a blind review, run the same way every time.
|
|
239
279
|
- **Outcome:** a request whose final result passed your checks and, if reviewed, had no hard failure — a result a user could rely on.
|
|
240
280
|
- **Cost per outcome:** everything a setup spent, including failed and rescued attempts, divided by its outcomes. The number to compare.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "valueproof"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.6.0"
|
|
8
8
|
description = "Prove an AI cost cut on your own traffic before you ship it: cheap and strong models working together (Scout & Rescue), measured by cost per outcome with a blind quality review."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -9,14 +9,17 @@ and measure what each change does to cost and quality before it ships.
|
|
|
9
9
|
Any provider works: a model is just a function `prompt -> ModelResult`.
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
|
-
from .lever_runner import Report, Run, Score,
|
|
12
|
+
from .lever_runner import (Report, Run, Score, check_quality, estimate, is_outcome, ledger_markdown, lever_ledger,
|
|
13
|
+
load_report, print_check_ratings, print_ledger,
|
|
14
|
+
print_table, rate_checks, run_levers, save, summarize)
|
|
13
15
|
from .pipeline import RunResult, Step, StepLog, run_pipeline
|
|
14
16
|
from .scout_rescue import Check, Model, ModelResult, Outcome, handoff_prompt, scout_and_rescue
|
|
15
17
|
|
|
16
|
-
__version__ = "0.
|
|
18
|
+
__version__ = "0.6.0"
|
|
17
19
|
|
|
18
20
|
__all__ = [
|
|
19
21
|
"Check", "Model", "ModelResult", "Outcome", "handoff_prompt", "scout_and_rescue",
|
|
20
22
|
"RunResult", "Step", "StepLog", "run_pipeline",
|
|
21
|
-
"Report", "Run", "Score", "is_outcome", "
|
|
23
|
+
"Report", "Run", "Score", "check_quality", "estimate", "is_outcome", "ledger_markdown", "lever_ledger", "load_report", "print_check_ratings", "print_ledger", "print_table",
|
|
24
|
+
"rate_checks", "run_levers", "save", "summarize",
|
|
22
25
|
]
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
valueproof compare my_test.py # run every setup on every case, print the table
|
|
5
5
|
valueproof compare my_test.py --live # your file decides what "live" means (real API calls)
|
|
6
6
|
valueproof compare my_test.py --out dir # where results and the blind review sheet go
|
|
7
|
+
valueproof compare my_test.py --live --estimate # run 2 cases, print the projected bill
|
|
8
|
+
valueproof compare my_test.py --live --max-spend 5 # stop once $5 is spent
|
|
7
9
|
|
|
8
10
|
Your test file is plain Python and defines one function:
|
|
9
11
|
|
|
@@ -12,6 +14,8 @@ Your test file is plain Python and defines one function:
|
|
|
12
14
|
"cases": [...], # your test requests
|
|
13
15
|
"setups": {"baseline": run, ...}, # name -> run(case) -> Run; first is the baseline
|
|
14
16
|
"judge": judge, # optional: judge(case, text) -> Score
|
|
17
|
+
"checks": {"my new check": fn}, # optional: candidate eval checks to rate, fn(case, text)
|
|
18
|
+
"levers": {"new": {"baseline": "baseline", "estimate": "-30% cost"}}, # optional: keep-or-drop ledger
|
|
15
19
|
"describe": lambda case: str(case), # optional: how a case shows on the review sheet
|
|
16
20
|
}
|
|
17
21
|
|
|
@@ -23,12 +27,13 @@ from __future__ import annotations
|
|
|
23
27
|
|
|
24
28
|
import argparse
|
|
25
29
|
import importlib.util
|
|
30
|
+
import json
|
|
26
31
|
import sys
|
|
27
32
|
from datetime import datetime
|
|
28
33
|
from pathlib import Path
|
|
29
34
|
|
|
30
35
|
from . import __version__
|
|
31
|
-
from .lever_runner import print_table, run_levers, save
|
|
36
|
+
from .lever_runner import estimate, ledger_markdown, lever_ledger, load_report, print_check_ratings, print_ledger, print_table, rate_checks, run_levers, save
|
|
32
37
|
from .starter import STARTER
|
|
33
38
|
|
|
34
39
|
|
|
@@ -45,16 +50,54 @@ def _load(path: Path):
|
|
|
45
50
|
return module
|
|
46
51
|
|
|
47
52
|
|
|
48
|
-
def compare(file: str, live: bool = False, out: str | None = None, extra: list[str] | None = None
|
|
53
|
+
def compare(file: str, live: bool = False, out: str | None = None, extra: list[str] | None = None,
|
|
54
|
+
max_spend: float | None = None, estimate_only: bool = False, sample: int = 2,
|
|
55
|
+
from_results: str | None = None) -> None:
|
|
49
56
|
path = Path(file).resolve()
|
|
50
57
|
spec = _load(path).build(live, extra or [])
|
|
51
|
-
cases, setups = spec["cases"], spec["setups"]
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
cases, setups, judge = spec["cases"], spec["setups"], spec.get("judge")
|
|
59
|
+
mode = "LIVE" if live else "OFFLINE"
|
|
60
|
+
if estimate_only:
|
|
61
|
+
print(f"{mode} ESTIMATE: running {min(sample, len(cases))} of {len(cases)} cases x {len(setups)} setups for real")
|
|
62
|
+
e = estimate(cases, setups, judge, sample)
|
|
63
|
+
print(f"\nSpent on the sample: ${e['sample_spent']:.4f} for {e['sample_cases']} cases (${e['per_case']:.4f} per case)")
|
|
64
|
+
print(f"Projected full run: ${e['projected_total']:.2f} for {e['cases']} cases, including the review")
|
|
65
|
+
print("A rough guide: hard cases and rescues cost more. Set a ceiling with --max-spend.")
|
|
66
|
+
return
|
|
67
|
+
if from_results: # no model runs: rate the candidate checks on saved replies
|
|
68
|
+
report = load_report(Path(from_results))
|
|
69
|
+
present = list(dict.fromkeys(r.setup for r in report.rows))
|
|
70
|
+
names = [n for n in setups if n in present] + [n for n in present if n not in setups] # first = baseline
|
|
71
|
+
print(f"{mode}: {len(report.rows)} saved results from {from_results} (no model runs)\n")
|
|
72
|
+
print_table(report, names)
|
|
73
|
+
ledger = lever_ledger(report, spec.get("levers") or {})
|
|
74
|
+
print_ledger(ledger)
|
|
75
|
+
if spec.get("checks"):
|
|
76
|
+
print_check_ratings(rate_checks(report, cases, names, spec["checks"]))
|
|
77
|
+
print(f"Spent on the checks: ${report.spent_usd:.4f}")
|
|
78
|
+
if out and ledger:
|
|
79
|
+
Path(out).mkdir(parents=True, exist_ok=True)
|
|
80
|
+
(Path(out) / "ledger.md").write_text(ledger_markdown(ledger) + "\n")
|
|
81
|
+
return
|
|
82
|
+
limit = f", stops at ${max_spend:.2f}" if max_spend is not None else ""
|
|
83
|
+
print(f"{mode}: {len(cases)} cases x {len(setups)} setups{limit}")
|
|
84
|
+
report = run_levers(cases, setups, judge=judge, max_spend=max_spend)
|
|
85
|
+
if not report.rows:
|
|
86
|
+
print(f"Nothing ran: {report.stopped}")
|
|
87
|
+
return
|
|
54
88
|
print()
|
|
55
89
|
print_table(report, list(setups))
|
|
90
|
+
ledger = lever_ledger(report, spec.get("levers") or {})
|
|
91
|
+
print_ledger(ledger)
|
|
92
|
+
ratings = rate_checks(report, cases, list(setups), spec["checks"]) if spec.get("checks") and judge else {}
|
|
93
|
+
print_check_ratings(ratings)
|
|
56
94
|
out_dir = Path(out) if out else path.parent / "results" / datetime.now().strftime("%Y%m%d-%H%M%S")
|
|
57
95
|
save(report, cases, out_dir, describe=spec.get("describe", str))
|
|
96
|
+
if ledger:
|
|
97
|
+
(out_dir / "ledger.md").write_text(ledger_markdown(ledger) + "\n")
|
|
98
|
+
if ratings:
|
|
99
|
+
(out_dir / "check_ratings.json").write_text(json.dumps(ratings, indent=2))
|
|
100
|
+
print(f"Spent including the check ratings: ${report.spent_usd:.4f}")
|
|
58
101
|
print(f"\nSaved to {out_dir}")
|
|
59
102
|
|
|
60
103
|
|
|
@@ -75,11 +118,18 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
75
118
|
cmp_.add_argument("file", help="your test file, defining build(live, args)")
|
|
76
119
|
cmp_.add_argument("--live", action="store_true", help="tell build() to use real models")
|
|
77
120
|
cmp_.add_argument("--out", help="folder for results (default: results/<time> next to the file)")
|
|
121
|
+
cmp_.add_argument("--max-spend", type=float, metavar="USD",
|
|
122
|
+
help="stop starting new cases once this much is spent (runs + review)")
|
|
123
|
+
cmp_.add_argument("--estimate", action="store_true",
|
|
124
|
+
help="run only a small sample for real and print the projected cost of the full run")
|
|
125
|
+
cmp_.add_argument("--sample", type=int, default=2, help="cases to run for --estimate (default: 2)")
|
|
126
|
+
cmp_.add_argument("--from-results", metavar="FILE",
|
|
127
|
+
help="skip the runs: rate the test file's candidate checks on a saved results.json")
|
|
78
128
|
ini = sub.add_parser("init", help="write a starter test file that runs offline straight away")
|
|
79
129
|
ini.add_argument("file", nargs="?", default="valueproof_test.py", help="file to create (default: valueproof_test.py)")
|
|
80
130
|
args, extra = parser.parse_known_args(argv)
|
|
81
131
|
if args.command == "compare":
|
|
82
|
-
compare(args.file, args.live, args.out, extra)
|
|
132
|
+
compare(args.file, args.live, args.out, extra, args.max_spend, args.estimate, args.sample, args.from_results)
|
|
83
133
|
elif args.command == "init":
|
|
84
134
|
init(args.file)
|
|
85
135
|
|