valueproof 0.4.0__tar.gz → 0.5.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.
Files changed (24) hide show
  1. {valueproof-0.4.0/src/valueproof.egg-info → valueproof-0.5.0}/PKG-INFO +9 -5
  2. {valueproof-0.4.0 → valueproof-0.5.0}/README.md +8 -4
  3. {valueproof-0.4.0 → valueproof-0.5.0}/pyproject.toml +1 -1
  4. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof/__init__.py +3 -3
  5. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof/cli.py +26 -6
  6. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof/lever_runner.py +68 -4
  7. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof/starter.py +3 -2
  8. {valueproof-0.4.0 → valueproof-0.5.0/src/valueproof.egg-info}/PKG-INFO +9 -5
  9. {valueproof-0.4.0 → valueproof-0.5.0}/tests/test_runner_cli.py +33 -1
  10. {valueproof-0.4.0 → valueproof-0.5.0}/LICENSE-CODE +0 -0
  11. {valueproof-0.4.0 → valueproof-0.5.0}/setup.cfg +0 -0
  12. {valueproof-0.4.0 → valueproof-0.5.0}/src/mixed_model_cost/__init__.py +0 -0
  13. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof/claude.py +0 -0
  14. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof/gemini.py +0 -0
  15. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof/openai.py +0 -0
  16. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof/pipeline.py +0 -0
  17. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof/scout_rescue.py +0 -0
  18. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof.egg-info/SOURCES.txt +0 -0
  19. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof.egg-info/dependency_links.txt +0 -0
  20. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof.egg-info/entry_points.txt +0 -0
  21. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof.egg-info/requires.txt +0 -0
  22. {valueproof-0.4.0 → valueproof-0.5.0}/src/valueproof.egg-info/top_level.txt +0 -0
  23. {valueproof-0.4.0 → valueproof-0.5.0}/tests/test_adapters.py +0 -0
  24. {valueproof-0.4.0 → valueproof-0.5.0}/tests/test_core.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: valueproof
3
- Version: 0.4.0
3
+ Version: 0.5.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,7 +33,7 @@ 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.
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
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, correct reply cost 0.12 ¢ instead of 1.05 ¢ with Claude Opus 5.5 alone — 89% less per outcome.
38
38
  - **The trade-off:** on the support tickets, quality was 2–6% lower, and one wrong refund rule slipped past the checks. Your checks decide how much quality you keep.
39
39
 
@@ -45,6 +45,7 @@ It fits when your product sends a lot of requests to a frontier model — such a
45
45
  - data extraction
46
46
  - search and research assistants
47
47
  - document summarizers
48
+ - code translation and migration (e.g. Java to Kotlin) — the checks are exact: does it compile, do the tests pass
48
49
 
49
50
  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
51
 
@@ -191,7 +192,7 @@ outcome = scout_and_rescue(
191
192
  print(outcome.path, outcome.cost_usd) # "scout" or "rescue" - how often each runs depends on your checks
192
193
  ```
193
194
 
194
- **Install** (version 0.3, early: the API may still change; Python 3.10+, Gemini adapter 3.11+):
195
+ **Install** (version 0.5, early: the API may still change; Python 3.10+, Gemini adapter 3.11+):
195
196
 
196
197
  ```bash
197
198
  pip install "valueproof[claude]"
@@ -209,10 +210,13 @@ The core has no dependencies and works with any provider: a model is just a func
209
210
  **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
211
 
211
212
  ```bash
212
- valueproof init my_test.py # a starter test that runs straight away, with fake models
213
- valueproof compare my_test.py --live
213
+ valueproof init my_test.py # a starter test that runs straight away, with fake models
214
+ valueproof compare my_test.py --live --estimate # runs 2 requests for real, prints the projected bill
215
+ valueproof compare my_test.py --live --max-spend 5 # the full test, stops starting new requests at $5
214
216
  ```
215
217
 
218
+ After the table it lists **which check rule fired most often**, so you see whether rescues come from formatting, missing fields or stale data.
219
+
216
220
  → 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
221
 
218
222
  **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.
@@ -5,7 +5,7 @@
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.
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
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, correct reply cost 0.12 ¢ instead of 1.05 ¢ with Claude Opus 5.5 alone — 89% less per outcome.
10
10
  - **The trade-off:** on the support tickets, quality was 2–6% lower, and one wrong refund rule slipped past the checks. Your checks decide how much quality you keep.
11
11
 
@@ -17,6 +17,7 @@ It fits when your product sends a lot of requests to a frontier model — such a
17
17
  - data extraction
18
18
  - search and research assistants
19
19
  - document summarizers
20
+ - code translation and migration (e.g. Java to Kotlin) — the checks are exact: does it compile, do the tests pass
20
21
 
21
22
  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
23
 
@@ -163,7 +164,7 @@ outcome = scout_and_rescue(
163
164
  print(outcome.path, outcome.cost_usd) # "scout" or "rescue" - how often each runs depends on your checks
164
165
  ```
165
166
 
166
- **Install** (version 0.3, early: the API may still change; Python 3.10+, Gemini adapter 3.11+):
167
+ **Install** (version 0.5, early: the API may still change; Python 3.10+, Gemini adapter 3.11+):
167
168
 
168
169
  ```bash
169
170
  pip install "valueproof[claude]"
@@ -181,10 +182,13 @@ The core has no dependencies and works with any provider: a model is just a func
181
182
  **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
183
 
183
184
  ```bash
184
- valueproof init my_test.py # a starter test that runs straight away, with fake models
185
- valueproof compare my_test.py --live
185
+ valueproof init my_test.py # a starter test that runs straight away, with fake models
186
+ valueproof compare my_test.py --live --estimate # runs 2 requests for real, prints the projected bill
187
+ valueproof compare my_test.py --live --max-spend 5 # the full test, stops starting new requests at $5
186
188
  ```
187
189
 
190
+ After the table it lists **which check rule fired most often**, so you see whether rescues come from formatting, missing fields or stale data.
191
+
188
192
  → 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
193
 
190
194
  **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.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "valueproof"
7
- version = "0.4.0"
7
+ version = "0.5.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,14 @@ 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, is_outcome, print_table, run_levers, save, summarize
12
+ from .lever_runner import Report, Run, Score, estimate, is_outcome, print_table, run_levers, save, summarize
13
13
  from .pipeline import RunResult, Step, StepLog, run_pipeline
14
14
  from .scout_rescue import Check, Model, ModelResult, Outcome, handoff_prompt, scout_and_rescue
15
15
 
16
- __version__ = "0.4.0"
16
+ __version__ = "0.5.0"
17
17
 
18
18
  __all__ = [
19
19
  "Check", "Model", "ModelResult", "Outcome", "handoff_prompt", "scout_and_rescue",
20
20
  "RunResult", "Step", "StepLog", "run_pipeline",
21
- "Report", "Run", "Score", "is_outcome", "print_table", "run_levers", "save", "summarize",
21
+ "Report", "Run", "Score", "estimate", "is_outcome", "print_table", "run_levers", "save", "summarize",
22
22
  ]
@@ -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
 
@@ -28,7 +30,7 @@ from datetime import datetime
28
30
  from pathlib import Path
29
31
 
30
32
  from . import __version__
31
- from .lever_runner import print_table, run_levers, save
33
+ from .lever_runner import estimate, print_table, run_levers, save
32
34
  from .starter import STARTER
33
35
 
34
36
 
@@ -45,12 +47,25 @@ def _load(path: Path):
45
47
  return module
46
48
 
47
49
 
48
- def compare(file: str, live: bool = False, out: str | None = None, extra: list[str] | None = None) -> None:
50
+ def compare(file: str, live: bool = False, out: str | None = None, extra: list[str] | None = None,
51
+ max_spend: float | None = None, estimate_only: bool = False, sample: int = 2) -> None:
49
52
  path = Path(file).resolve()
50
53
  spec = _load(path).build(live, extra or [])
51
- cases, setups = spec["cases"], spec["setups"]
52
- print(f"{'LIVE' if live else 'OFFLINE'}: {len(cases)} cases x {len(setups)} setups")
53
- report = run_levers(cases, setups, judge=spec.get("judge"))
54
+ cases, setups, judge = spec["cases"], spec["setups"], spec.get("judge")
55
+ mode = "LIVE" if live else "OFFLINE"
56
+ if estimate_only:
57
+ print(f"{mode} ESTIMATE: running {min(sample, len(cases))} of {len(cases)} cases x {len(setups)} setups for real")
58
+ e = estimate(cases, setups, judge, sample)
59
+ print(f"\nSpent on the sample: ${e['sample_spent']:.4f} for {e['sample_cases']} cases (${e['per_case']:.4f} per case)")
60
+ print(f"Projected full run: ${e['projected_total']:.2f} for {e['cases']} cases, including the review")
61
+ print("A rough guide: hard cases and rescues cost more. Set a ceiling with --max-spend.")
62
+ return
63
+ limit = f", stops at ${max_spend:.2f}" if max_spend is not None else ""
64
+ print(f"{mode}: {len(cases)} cases x {len(setups)} setups{limit}")
65
+ report = run_levers(cases, setups, judge=judge, max_spend=max_spend)
66
+ if not report.rows:
67
+ print(f"Nothing ran: {report.stopped}")
68
+ return
54
69
  print()
55
70
  print_table(report, list(setups))
56
71
  out_dir = Path(out) if out else path.parent / "results" / datetime.now().strftime("%Y%m%d-%H%M%S")
@@ -75,11 +90,16 @@ def main(argv: list[str] | None = None) -> None:
75
90
  cmp_.add_argument("file", help="your test file, defining build(live, args)")
76
91
  cmp_.add_argument("--live", action="store_true", help="tell build() to use real models")
77
92
  cmp_.add_argument("--out", help="folder for results (default: results/<time> next to the file)")
93
+ cmp_.add_argument("--max-spend", type=float, metavar="USD",
94
+ help="stop starting new cases once this much is spent (runs + review)")
95
+ cmp_.add_argument("--estimate", action="store_true",
96
+ help="run only a small sample for real and print the projected cost of the full run")
97
+ cmp_.add_argument("--sample", type=int, default=2, help="cases to run for --estimate (default: 2)")
78
98
  ini = sub.add_parser("init", help="write a starter test file that runs offline straight away")
79
99
  ini.add_argument("file", nargs="?", default="valueproof_test.py", help="file to create (default: valueproof_test.py)")
80
100
  args, extra = parser.parse_known_args(argv)
81
101
  if args.command == "compare":
82
- compare(args.file, args.live, args.out, extra)
102
+ compare(args.file, args.live, args.out, extra, args.max_spend, args.estimate, args.sample)
83
103
  elif args.command == "init":
84
104
  init(args.file)
85
105
 
@@ -16,7 +16,9 @@ from __future__ import annotations
16
16
  import csv
17
17
  import json
18
18
  import random
19
+ import re
19
20
  import statistics
21
+ from collections import Counter
20
22
  from dataclasses import asdict, dataclass, field
21
23
  from pathlib import Path
22
24
  from typing import Any, Callable, Optional
@@ -29,6 +31,7 @@ class Run:
29
31
  seconds: float
30
32
  path: str = "single" # "scout", "rescue" or "single"
31
33
  final_check: Optional[str] = None # None if the final text passes your check
34
+ rejected_because: Optional[str] = None # why the first attempt failed its check, if it did
32
35
 
33
36
 
34
37
  @dataclass
@@ -37,6 +40,7 @@ class Score:
37
40
  max_points: int
38
41
  hard_failure: bool = False # wrong policy, invented promise, no answer ...
39
42
  note: str = ""
43
+ cost_usd: float = 0.0 # what the review itself cost, if a model did it
40
44
 
41
45
 
42
46
  @dataclass
@@ -50,6 +54,8 @@ class Row:
50
54
  @dataclass
51
55
  class Report:
52
56
  rows: list[Row] = field(default_factory=list)
57
+ spent_usd: float = 0.0 # runs plus reviews
58
+ stopped: Optional[str] = None # why the run stopped early, if it did
53
59
 
54
60
  def for_setup(self, name: str) -> list[Row]:
55
61
  return [r for r in self.rows if r.setup == name]
@@ -60,15 +66,28 @@ def run_levers(
60
66
  setups: dict[str, Callable[[Any], Run]],
61
67
  judge: Optional[Callable[[Any, str], Score]] = None,
62
68
  seed: int = 1,
69
+ max_spend: Optional[float] = None,
63
70
  ) -> Report:
71
+ """Run every setup on every case, then review blind.
72
+
73
+ max_spend (USD): stop starting new cases once runs have spent this much, and
74
+ skip the review if it would push past it. A case in progress is finished, so
75
+ the results stay paired. The table then covers the finished cases only.
76
+ """
64
77
  rng = random.Random(seed)
65
78
  report = Report()
66
79
  for i, case in enumerate(cases):
80
+ if max_spend is not None and report.spent_usd >= max_spend:
81
+ report.stopped = f"spend limit ${max_spend:.2f} reached after {i} of {len(cases)} cases"
82
+ print(f" STOPPED: {report.stopped}", flush=True)
83
+ break
67
84
  names = list(setups)
68
85
  rng.shuffle(names) # no setup always goes first
69
86
  for name in names:
70
- report.rows.append(Row(i, name, setups[name](case)))
71
- print(f" case {i + 1}/{len(cases)} done", flush=True)
87
+ run = setups[name](case)
88
+ report.spent_usd += run.cost_usd
89
+ report.rows.append(Row(i, name, run))
90
+ print(f" case {i + 1}/{len(cases)} done, ${report.spent_usd:.4f} spent", flush=True)
72
91
 
73
92
  if judge:
74
93
  # Score each distinct reply once, in random order, without the setup name.
@@ -77,19 +96,49 @@ def run_levers(
77
96
  rng.shuffle(order)
78
97
  scores = {}
79
98
  for n, (i, text) in enumerate(order, 1):
99
+ if max_spend is not None and report.spent_usd >= max_spend:
100
+ report.stopped = f"spend limit ${max_spend:.2f} reached during the review; no quality scores shown"
101
+ print(f" STOPPED: {report.stopped}", flush=True)
102
+ scores = None
103
+ break
80
104
  scores[(i, text)] = judge(cases[i], text)
105
+ report.spent_usd += scores[(i, text)].cost_usd
81
106
  print(f" reviewed {n}/{len(order)}", flush=True)
82
- for r in report.rows:
83
- r.score = scores[(r.case, r.run.text)]
107
+ if scores is not None:
108
+ for r in report.rows:
109
+ r.score = scores[(r.case, r.run.text)]
84
110
  return report
85
111
 
86
112
 
113
+ def estimate(
114
+ cases: list[Any],
115
+ setups: dict[str, Callable[[Any], Run]],
116
+ judge: Optional[Callable[[Any, str], Score]] = None,
117
+ sample: int = 2,
118
+ ) -> dict:
119
+ """Run the first `sample` cases for real and project the cost of the full run.
120
+
121
+ This spends a little money on purpose: a real call is the only reliable price.
122
+ """
123
+ trial = run_levers(cases[:sample], setups, judge)
124
+ done = len({r.case for r in trial.rows})
125
+ per_case = trial.spent_usd / done if done else 0.0
126
+ return {"sample_cases": done, "sample_spent": trial.spent_usd, "per_case": per_case,
127
+ "projected_total": per_case * len(cases), "cases": len(cases)}
128
+
129
+
87
130
  def is_outcome(row: Row) -> bool:
88
131
  """A request counts as an outcome when the final result passes your check and,
89
132
  if a judge ran, has no hard failure - the result a user could actually rely on."""
90
133
  return row.run.final_check is None and not (row.score and row.score.hard_failure)
91
134
 
92
135
 
136
+ def _reason(text: str) -> str:
137
+ """Group similar reasons: 'does not cite §1, §6' and 'does not cite §5' are the same rule."""
138
+ short = re.sub(r"[§#]?\d[\d.,§ ]*", "#", text)
139
+ return short.strip(" :,")
140
+
141
+
93
142
  def summarize(report: Report, setups: list[str]) -> list[dict]:
94
143
  """The numbers behind the table, one dict per setup.
95
144
 
@@ -115,6 +164,9 @@ def summarize(report: Report, setups: list[str]) -> list[dict]:
115
164
  "quality": sum(s.points for s in scored) if scored else None,
116
165
  "quality_max": sum(s.max_points for s in scored) if scored else None,
117
166
  "hard_fail": sum(s.hard_failure for s in scored) if scored else None,
167
+ "first_try_pass": sum(r.run.rejected_because is None and r.run.path != "rescue" for r in rows),
168
+ "first_try_rejections": Counter(_reason(r.run.rejected_because) for r in rows if r.run.rejected_because),
169
+ "final_failures": Counter(_reason(r.run.final_check) for r in rows if r.run.final_check),
118
170
  })
119
171
  return out
120
172
 
@@ -141,6 +193,18 @@ def print_table(report: Report, setups: list[str]) -> None:
141
193
  print(line)
142
194
  print("\ncost/outcome = everything spent / requests whose final result passed the check"
143
195
  + (" and had no hard failure" if has_scores else "") + ". It is the number to compare.")
196
+ reasons = [s for s in rows if s["first_try_rejections"] or s["final_failures"]]
197
+ if reasons:
198
+ print("\nWhy results were rejected (which check rule fired, most frequent first):")
199
+ for s in reasons:
200
+ print(f" {s['setup']}: first try passed {s['first_try_pass']}/{s['requests']}")
201
+ for label, counts in (("first try rejected", s["first_try_rejections"]), ("final result failed", s["final_failures"])):
202
+ if counts:
203
+ top = ", ".join(f"{why} ({n})" for why, n in counts.most_common(5))
204
+ print(f" {label}: {top}")
205
+ if report.stopped:
206
+ print(f"\nNote: {report.stopped}.")
207
+ print(f"Spent on this run: ${report.spent_usd:.4f}")
144
208
 
145
209
 
146
210
  def save(report: Report, cases: list[Any], out_dir: Path, describe: Callable[[Any], str]) -> None:
@@ -3,7 +3,8 @@
3
3
  STARTER = '''"""My cost test: compare today's setup with a cheaper one on the same requests.
4
4
 
5
5
  valueproof compare {name} # fake models: checks the wiring, no cost
6
- valueproof compare {name} --live # real models: costs money
6
+ valueproof compare {name} --live --estimate # real models, 2 cases: prints the projected bill
7
+ valueproof compare {name} --live --max-spend 5 # real models, stops once $5 is spent
7
8
 
8
9
  Edit the four parts marked EDIT, from top to bottom.
9
10
  """
@@ -69,7 +70,7 @@ def build(live: bool, args: list) -> dict:
69
70
  def scout_rescue(case) -> Run:
70
71
  t0 = time.time()
71
72
  out = scout_and_rescue(prompt_for(case), m["cheap"], m["strong"], lambda t: check(t, case))
72
- return Run(out.text, out.cost_usd, time.time() - t0, out.path, check(out.text, case))
73
+ return Run(out.text, out.cost_usd, time.time() - t0, out.path, check(out.text, case), out.rejected_because)
73
74
 
74
75
  return {{
75
76
  "cases": CASES,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: valueproof
3
- Version: 0.4.0
3
+ Version: 0.5.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,7 +33,7 @@ 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.
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
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, correct reply cost 0.12 ¢ instead of 1.05 ¢ with Claude Opus 5.5 alone — 89% less per outcome.
38
38
  - **The trade-off:** on the support tickets, quality was 2–6% lower, and one wrong refund rule slipped past the checks. Your checks decide how much quality you keep.
39
39
 
@@ -45,6 +45,7 @@ It fits when your product sends a lot of requests to a frontier model — such a
45
45
  - data extraction
46
46
  - search and research assistants
47
47
  - document summarizers
48
+ - code translation and migration (e.g. Java to Kotlin) — the checks are exact: does it compile, do the tests pass
48
49
 
49
50
  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
51
 
@@ -191,7 +192,7 @@ outcome = scout_and_rescue(
191
192
  print(outcome.path, outcome.cost_usd) # "scout" or "rescue" - how often each runs depends on your checks
192
193
  ```
193
194
 
194
- **Install** (version 0.3, early: the API may still change; Python 3.10+, Gemini adapter 3.11+):
195
+ **Install** (version 0.5, early: the API may still change; Python 3.10+, Gemini adapter 3.11+):
195
196
 
196
197
  ```bash
197
198
  pip install "valueproof[claude]"
@@ -209,10 +210,13 @@ The core has no dependencies and works with any provider: a model is just a func
209
210
  **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
211
 
211
212
  ```bash
212
- valueproof init my_test.py # a starter test that runs straight away, with fake models
213
- valueproof compare my_test.py --live
213
+ valueproof init my_test.py # a starter test that runs straight away, with fake models
214
+ valueproof compare my_test.py --live --estimate # runs 2 requests for real, prints the projected bill
215
+ valueproof compare my_test.py --live --max-spend 5 # the full test, stops starting new requests at $5
214
216
  ```
215
217
 
218
+ After the table it lists **which check rule fired most often**, so you see whether rescues come from formatting, missing fields or stale data.
219
+
216
220
  → 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
221
 
218
222
  **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.
@@ -4,7 +4,7 @@ import subprocess
4
4
  import sys
5
5
  from pathlib import Path
6
6
 
7
- from valueproof import Run, Score, print_table, run_levers, save, summarize
7
+ from valueproof import Run, Score, estimate, print_table, run_levers, save, summarize
8
8
  from valueproof.cli import main
9
9
 
10
10
  ROOT = Path(__file__).resolve().parent.parent
@@ -56,3 +56,35 @@ def test_bundled_examples_run_offline(tmp_path):
56
56
  assert r.returncode == 0, r.stderr
57
57
  for new in set(results.iterdir()) - before: # remove only what this test wrote
58
58
  shutil.rmtree(new)
59
+
60
+
61
+ def test_max_spend_stops_between_cases_and_keeps_pairs():
62
+ setups = {"a": lambda c: Run("x", 0.01, 0.1), "b": lambda c: Run("y", 0.02, 0.1)}
63
+ report = run_levers(list(range(10)), setups, max_spend=0.05)
64
+ # each case costs 0.03; after 2 cases (0.06) no new case starts
65
+ assert len({r.case for r in report.rows}) == 2 and len(report.rows) == 4
66
+ assert report.stopped and abs(report.spent_usd - 0.06) < 1e-12
67
+
68
+
69
+ def test_review_skipped_when_it_would_pass_the_limit():
70
+ setups = {"a": lambda c: Run("x" + str(c), 0.01, 0.1)}
71
+ report = run_levers([1, 2], setups, judge=lambda c, t: Score(30, 40, cost_usd=0.05), max_spend=0.04)
72
+ assert all(r.score is None for r in report.rows) and "review" in report.stopped
73
+
74
+
75
+ def test_estimate_projects_from_a_sample():
76
+ setups = {"a": lambda c: Run("x", 0.01, 0.1), "b": lambda c: Run("y", 0.03, 0.1)}
77
+ e = estimate(list(range(50)), setups, judge=lambda c, t: Score(30, 40, cost_usd=0.005), sample=2)
78
+ # per case: 0.04 runs + 2 reviews x 0.005 = 0.05 -> 50 cases = 2.50
79
+ assert e["sample_cases"] == 2 and abs(e["projected_total"] - 2.5) < 1e-9
80
+
81
+
82
+ def test_rejection_reasons_are_grouped(capsys):
83
+ reasons = ["does not cite §1", "does not cite §5, §6", None, "too short"]
84
+ setups = {"s&r": lambda c: Run("t", 0.01, 0.1, "rescue" if reasons[c] else "scout",
85
+ rejected_because=reasons[c])}
86
+ report = run_levers(list(range(4)), setups)
87
+ s = summarize(report, ["s&r"])[0]
88
+ assert s["first_try_rejections"]["does not cite #"] == 2 and s["first_try_pass"] == 1
89
+ print_table(report, ["s&r"])
90
+ assert "does not cite # (2)" in capsys.readouterr().out
File without changes
File without changes