Item 2: benchmark standing and accepted rate are separate things: stored score facts become standing (sources kept), shown under their own names, session line compares standing only. done / next: item 3, prices as published
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
14ac903a65
commit
4a04997869
4 files changed
+222
-38
No files matched your search
+1
-1
@@ -31,7 +31,7 @@ LONG = {
|
||||
'status': ' sisi status [--json] [--learning] recent units with their scorecards, then trends by project, risk profile, model and policy version (median and p95; no single score)',
|
||||
'verifiers': ' sisi verifiers [WORDS] [--lang L] [--kind K] [--rung N] [--section S] [--installed] [--json]\n list ways to know work is correct, by section\n sisi verifiers show ID [--trace] one entry in full, and whether its tool is installed here; --trace also prints where each folded lesson lives in it\n sisi verifiers for "<claim>" best-matching verifiers for a claim or piece of work\n sisi verifiers doctor | lint which tools are installed; validate the library',
|
||||
'done': ' sisi done [ID] [--trace] recipes: which checks make a kind of work done; --trace also prints where each folded lesson lives in the recipe\n sisi done for "<work>" best-matching recipe',
|
||||
'workers': ' sisi workers [--refresh] the agent tools and models found here, what is usable now and why not, allowance and price where known, delegations waiting for a judgement, and the judged record as three tables\n sisi workers fact W --price N|--score N --source S record a price (per million tokens) or benchmark standing (0-100), with its source and date\n sisi workers avoid|prefer PATTERN --why TEXT your own routing constraints, honoured by `sisi route`\n sisi workers only PROVIDER PATTERN... --why TEXT | --remove make only the matching models of that provider routable\n sisi workers note PATTERN \"TEXT\" --why SOURCE | --remove a standing fact about workers matching PATTERN, shown with route results\n sisi workers down W --reason limit|auth|missing|error [--until DATE|TIME] | up W mark a worker unavailable / available again\n sisi workers import FILE merge another ledger file into the delegation ledger (row counts printed; safe to repeat)',
|
||||
'workers': ' sisi workers [--refresh] the agent tools and models found here, what is usable now and why not, allowance and price where known, delegations waiting for a judgement, and the judged record as three tables\n sisi workers fact W --price N|--standing N --source S record a price (per million tokens) or benchmark standing (0-100), with its source and date\n sisi workers avoid|prefer PATTERN --why TEXT your own routing constraints, honoured by `sisi route`\n sisi workers only PROVIDER PATTERN... --why TEXT | --remove make only the matching models of that provider routable\n sisi workers note PATTERN \"TEXT\" --why SOURCE | --remove a standing fact about workers matching PATTERN, shown with route results\n sisi workers down W --reason limit|auth|missing|error [--until DATE|TIME] | up W mark a worker unavailable / available again\n sisi workers import FILE merge another ledger file into the delegation ledger (row counts printed; safe to repeat)',
|
||||
'route': ' sisi route --kind K --difficulty N [--review-of W] [--explain]\n the most affordable usable worker for this kind and difficulty, and the mechanism to start it with (host subagents, host cross-provider delegation, or sisi delegate); --explain says why',
|
||||
'delegate': ' sisi delegate brief | check FILE | guide the delegation-contract template (eight parts); which parts a brief lacks; the orchestration playbook\n sisi delegate --kind K --difficulty N --brief FILE [--worker W] [--review-of W] [--cwd DIR]\n run one brief on the chosen worker unattended; prints only its final report, the transcript path, and the judge command; a brief without outcome, acceptance or files it may change is refused\n sisi delegate judge ID --outcome accepted|rejected --check none|diffstat|tests|read|review [--minutes N]\n record your judgement of a delegation run, so the next choice learns from it; judge work run any other way with --worker W --type K --difficulty N instead of ID\n sisi delegate amend ID | recent [-n N] [--project P] mark a judged delegation that later proved wrong; list recent judgements to find an id',
|
||||
'eval': ' sisi eval list|add|run|compare|shadow|judge|status|import\n the evaluation harness: benchmark cases from real work, isolated\n replay, policy comparison and independent judging (see docs/evaluation.md);\n `sisi eval` alone prints status; run without --tasks replays check cases only',
|
||||
|
||||
+65
-36
@@ -16,8 +16,9 @@ Personal files (all in the personal data folder):
|
||||
{"plan": "flat"|"per-use", "cost_per_million_tokens": number,
|
||||
"maker": name, "source": text, "date": "YYYY-MM-DD"}},
|
||||
"tools": {"<tool>": same shape}}, written by `sisi workers fact`
|
||||
model-strength.json worker facts (benchmark standing): {"models": {"<model or worker>":
|
||||
{"score": 0..100, "source": text, "date": "YYYY-MM-DD"}}}
|
||||
model-strength.json worker facts (benchmark standing, a published figure; never the measured
|
||||
accepted rate): {"models": {"<model or worker>":
|
||||
{"standing": 0..100, "source": text, "date": "YYYY-MM-DD"}}}
|
||||
worker-prefs.json the user's own routing constraints: {"avoid": [{"pattern", "why"}],
|
||||
"prefer": [...], "only": [{"provider", "patterns", "why"}]}, written by
|
||||
`sisi workers avoid|prefer|only`
|
||||
@@ -519,6 +520,28 @@ def load_strength_prior():
|
||||
return models if isinstance(models, dict) else {}
|
||||
|
||||
|
||||
def migrate_standing_facts():
|
||||
"""Facts recorded before standing had its own name store it as "score". Rename each to "standing",
|
||||
keeping its source, date and maker. Returns how many moved; repeating it moves none."""
|
||||
path = strength_path()
|
||||
data = read_json(path)
|
||||
models = data.get("models")
|
||||
if not isinstance(models, dict):
|
||||
return 0
|
||||
moved = 0
|
||||
for key, entry in list(models.items()):
|
||||
if isinstance(entry, dict) and "score" in entry:
|
||||
rest = {k: v for k, v in entry.items() if k not in ("score", "standing")}
|
||||
models[key] = dict({"standing": entry["standing"] if "standing" in entry else entry["score"]}, **rest)
|
||||
moved += 1
|
||||
if moved:
|
||||
try:
|
||||
write_json(path, data)
|
||||
except OSError:
|
||||
return 0
|
||||
return moved
|
||||
|
||||
|
||||
def route_cfg():
|
||||
cfg = store.config().get("route")
|
||||
return cfg if isinstance(cfg, dict) else {}
|
||||
@@ -823,7 +846,7 @@ def facts_line(now=None):
|
||||
return ("sisi: %s: ask a fast, cheap worker to research current prices and "
|
||||
"software-engineering benchmark standing for the workers found here (`sisi workers`) "
|
||||
"and record each with its source: `sisi workers fact WORKER --price N --source S` "
|
||||
"and `sisi workers fact WORKER --score N --source S`. Until then routing "
|
||||
"and `sisi workers fact WORKER --standing N --source S`. Until then routing "
|
||||
"goes by the judged record alone." % what)
|
||||
|
||||
|
||||
@@ -905,7 +928,7 @@ def digest_lines(records=None, days=None, now=None):
|
||||
% (days, len(attempts), routing.MIN_ATTEMPTS)]
|
||||
if not attempts:
|
||||
lines.append(" No judged delegations yet. Judge each result with `sisi delegate judge`; "
|
||||
"until then routing goes on price and benchmark prior alone.")
|
||||
"until then routing goes on price and benchmark standing alone.")
|
||||
return lines
|
||||
cells = {}
|
||||
for a in attempts:
|
||||
@@ -923,10 +946,10 @@ def digest_lines(records=None, days=None, now=None):
|
||||
rows = rows[:MAX_DIGEST_ROWS]
|
||||
rows.sort(key=lambda r: (str(r["type"]), r["diff"] or 0, -(r["ok"] / r["n"] if r["n"] else 0), -r["n"]))
|
||||
lines += ["", "Workers by task", "",
|
||||
"Accepted counts results that passed the check and were not reported wrong later. "
|
||||
"Accepted rate counts results that passed the check and were not reported wrong later. "
|
||||
"Checked well is the share of those verified by tests, a read, or a second reviewer; "
|
||||
"the rest were accepted on a lighter check.", "",
|
||||
"| Type | Diff | Worker | Attempts | Accepted | Checked well | Later wrong | Median min |",
|
||||
"| Type | Diff | Worker | Attempts | Accepted rate | Checked well | Later wrong | Median min |",
|
||||
"|---|---|---|---|---|---|---|---|"]
|
||||
for r in rows:
|
||||
thin = " (thin)" if r["n"] < routing.MIN_ATTEMPTS else ""
|
||||
@@ -1193,29 +1216,21 @@ def run_delegation(candidates, kind, difficulty, prompt, cwd, explicit=None, rev
|
||||
# ---------------------------------------------------------------- strength and session lines
|
||||
|
||||
|
||||
def strength_scores(candidates, records):
|
||||
"""{worker: (score, how)} from the judged record where it is thick enough, else from the
|
||||
stored prior (model-strength.json, each figure with its source and date). No shipped ranking:
|
||||
a model with neither is simply absent here, and its strength is unknown."""
|
||||
def strength_scores(candidates):
|
||||
"""{worker: (standing, how)} from the stored benchmark standing (model-strength.json, each figure with
|
||||
its source and date). Only standings are here: the accepted rate measured from judged delegations is a
|
||||
different scale and is never mixed in. No shipped ranking: a model with no stored standing is simply
|
||||
absent, and its strength is unknown."""
|
||||
prior = load_strength_prior()
|
||||
stats = routing.candidate_stats(candidates, records)
|
||||
out = {}
|
||||
for c in candidates:
|
||||
cells = stats.get(c["worker"], {}).get("by_cell", {})
|
||||
n = sum(v["n"] for v in cells.values())
|
||||
good = sum(v["good"] for v in cells.values())
|
||||
if n >= routing.MIN_ATTEMPTS:
|
||||
out[c["worker"]] = (100.0 * good / n, "measured from %d judged delegations" % n)
|
||||
continue
|
||||
entry = None
|
||||
for key in [c["worker"], c.get("model")] + list(c.get("aliases") or []):
|
||||
if key and isinstance(prior.get(key), dict):
|
||||
standing = standing_of(prior.get(key)) if key else None
|
||||
if standing is not None:
|
||||
entry = prior[key]
|
||||
out[c["worker"]] = (standing, "benchmark standing (%s, %s)" % (entry.get("source") or "no source stated",
|
||||
entry.get("date") or "no date stated"))
|
||||
break
|
||||
if entry and isinstance(entry.get("score"), (int, float)):
|
||||
how = "stored prior (%s, %s)" % (entry.get("source") or "no source stated",
|
||||
entry.get("date") or "no date stated")
|
||||
out[c["worker"]] = (float(entry["score"]), how)
|
||||
return out
|
||||
|
||||
|
||||
@@ -1257,14 +1272,14 @@ def session_lines(model, payload=None):
|
||||
suffix = " One delegation is waiting for a judgement: run `sisi workers`, then `sisi delegate judge`."
|
||||
elif waiting:
|
||||
suffix = " %d delegations are waiting for a judgement: run `sisi workers` to see, then `sisi delegate judge`." % waiting
|
||||
scores = strength_scores(candidates, records) if candidates else {}
|
||||
scores = strength_scores(candidates) if candidates else {}
|
||||
cand = resolve_worker(model, candidates) if candidates else None
|
||||
own = scores.get(cand["worker"]) if cand else None
|
||||
if own is None:
|
||||
prior = load_strength_prior().get(model)
|
||||
if isinstance(prior, dict) and isinstance(prior.get("score"), (int, float)):
|
||||
own = (float(prior["score"]), "stored prior (%s, %s)" % (prior.get("source") or "no source stated",
|
||||
prior.get("date") or "no date stated"))
|
||||
if standing_of(prior) is not None:
|
||||
own = (standing_of(prior), "benchmark standing (%s, %s)" % (prior.get("source") or "no source stated",
|
||||
prior.get("date") or "no date stated"))
|
||||
lines = []
|
||||
if own is not None:
|
||||
best_score = max([s for s, _h in scores.values()] + [own[0]])
|
||||
@@ -1347,6 +1362,7 @@ def cmd_workers(args=()):
|
||||
return _cmd_up(args[1:])
|
||||
if args[:1] == ["import"]:
|
||||
return _cmd_import(args[1:])
|
||||
migrate_standing_facts()
|
||||
disc = discover(force="--refresh" in args)
|
||||
records = read_records()
|
||||
avail = read_availability()
|
||||
@@ -1384,6 +1400,14 @@ def cmd_workers(args=()):
|
||||
print(" price: flat-rate plan (the tool reports an allowance, so one more task costs nothing extra)")
|
||||
if missing:
|
||||
print("Not found on PATH: %s" % ", ".join(missing))
|
||||
standings = sorted(((standing_of(e), k, e) for k, e in load_strength_prior().items() if standing_of(e) is not None),
|
||||
key=lambda t: (-t[0], t[1]))
|
||||
if standings:
|
||||
print("Benchmark standing (a published figure; routing compares it only with other workers' standing, "
|
||||
"never with the accepted rate measured below):")
|
||||
for standing, worker, entry in standings:
|
||||
print(" benchmark standing %g - %s: %s (%s)" % (standing, worker, entry.get("source") or "no source stated",
|
||||
entry.get("date") or "no date stated"))
|
||||
down_now = [(k, v) for k, v in sorted(avail.items()) if isinstance(v, dict)]
|
||||
for k, v in down_now:
|
||||
if k in {t["name"] for t in disc.get("tools") or []}:
|
||||
@@ -1819,7 +1843,7 @@ def _cmd_import(args):
|
||||
|
||||
def _cmd_fact(args):
|
||||
usage = ("usage: sisi workers fact WORKER --price N [--plan flat|per-use] [--maker M] --source S [--date YYYY-MM-DD]\n"
|
||||
" sisi workers fact WORKER --score 0..100 --source S [--date YYYY-MM-DD]")
|
||||
" sisi workers fact WORKER --standing 0..100 --source S [--date YYYY-MM-DD] (--score is the old name)")
|
||||
if not args:
|
||||
print(usage)
|
||||
return 1
|
||||
@@ -1827,13 +1851,19 @@ def _cmd_fact(args):
|
||||
source = _opt(args, "--source")
|
||||
date = _opt(args, "--date") or time.strftime("%Y-%m-%d", time.localtime())
|
||||
price, price_ok = _number_opt(args, "--price")
|
||||
score, score_ok = _number_opt(args, "--score")
|
||||
if not price_ok or not score_ok or (price is None and score is None):
|
||||
standing, standing_ok = _number_opt(args, "--standing")
|
||||
old_name, old_ok = _number_opt(args, "--score")
|
||||
if standing is None:
|
||||
standing = old_name
|
||||
if not price_ok or not standing_ok or not old_ok or (price is None and standing is None):
|
||||
print(usage)
|
||||
return 1
|
||||
if not source:
|
||||
print("sisi: a fact needs its --source (where the figure came from); nothing recorded", file=sys.stderr)
|
||||
return 1
|
||||
if standing is not None and not (0 <= standing <= 100):
|
||||
print("sisi: --standing wants a number from 0 to 100", file=sys.stderr)
|
||||
return 1
|
||||
if price is not None:
|
||||
plan = _opt(args, "--plan")
|
||||
if plan is not None and plan not in ("flat", "per-use"):
|
||||
@@ -1852,21 +1882,20 @@ def _cmd_fact(args):
|
||||
prices["models"] = models
|
||||
write_json(prices_path(), prices)
|
||||
print("recorded price for %s: %g per million tokens (from %s, %s)" % (worker, price, source, date))
|
||||
if score is not None:
|
||||
if not (0 <= score <= 100):
|
||||
print("sisi: --score wants a number from 0 to 100", file=sys.stderr)
|
||||
return 1
|
||||
if standing is not None:
|
||||
migrate_standing_facts()
|
||||
data = read_json(strength_path())
|
||||
models = data.get("models") if isinstance(data.get("models"), dict) else {}
|
||||
entry = dict(models.get(worker) or {})
|
||||
entry.update({"score": score, "source": source, "date": date})
|
||||
entry.pop("score", None)
|
||||
entry.update({"standing": standing, "source": source, "date": date})
|
||||
maker = _opt(args, "--maker")
|
||||
if maker:
|
||||
entry["maker"] = maker
|
||||
models[worker] = entry
|
||||
data["models"] = models
|
||||
write_json(strength_path(), data)
|
||||
print("recorded benchmark standing for %s: %g (from %s, %s)" % (worker, score, source, date))
|
||||
print("recorded benchmark standing for %s: %g (from %s, %s)" % (worker, standing, source, date))
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
@@ -237,7 +237,8 @@ class FactsTests(OrchCase):
|
||||
"--source", "test fixture benchmark", env=self.env())
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
prior = json.load(open(os.path.join(self.data, "model-strength.json")))
|
||||
self.assertEqual(prior["models"]["muse/beta-1"]["score"], 70)
|
||||
self.assertEqual(prior["models"]["muse/beta-1"]["standing"], 70)
|
||||
self.assertNotIn("score", prior["models"]["muse/beta-1"])
|
||||
|
||||
def test_avoid_and_prefer_are_honoured(self):
|
||||
"""A user's own avoid/prefer constraints shape the recommendation."""
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
"""Two scales kept apart (benchmark standing, measured accepted rate) and prices as published (input and output,
|
||||
blended for ranking). Requirement ids: R-7.2-1, R-7.2-2, R-7.2-3, R-7.3-1. Workers are host-native (bare ids from
|
||||
the ledger) so no command-line tool is needed."""
|
||||
import json, os, time, unittest
|
||||
from support import *
|
||||
|
||||
|
||||
class FactsCase(SisiCase):
|
||||
def seed(self, workers, kind="read", difficulty=1, n=1):
|
||||
os.makedirs(self.data, exist_ok=True)
|
||||
with open(os.path.join(self.data, "delegations.jsonl"), "a") as f:
|
||||
for w in workers:
|
||||
for i in range(n):
|
||||
f.write(json.dumps({"kind": "attempt", "id": "%s-%d-%s-%d" % (w, i, kind, difficulty), "ts": round(time.time()) - i,
|
||||
"project": "p", "type": kind, "difficulty": difficulty, "worker": w,
|
||||
"outcome": "accepted", "check": "tests", "minutes": 1}) + "\n")
|
||||
|
||||
def run_sisi(self, *args):
|
||||
r = self.sisi(*args, env=dict(PATH=""))
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
return r
|
||||
|
||||
def stored(self, name):
|
||||
return json.load(open(os.path.join(self.data, name)))
|
||||
|
||||
|
||||
class StandingFieldTests(FactsCase):
|
||||
LEGACY = {"models": {"wk-a": {"score": 64.5, "source": "fixture board https://example.test/x read 2000-01-01", "date": "2000-01-01"},
|
||||
"wk-b": {"score": 40, "source": "fixture board", "date": "2000-01-02", "maker": "mk"}}}
|
||||
|
||||
def write_legacy(self):
|
||||
os.makedirs(self.data, exist_ok=True)
|
||||
json.dump(self.LEGACY, open(os.path.join(self.data, "model-strength.json"), "w"))
|
||||
|
||||
def test_existing_score_facts_move_to_standing_with_their_sources(self):
|
||||
"""R-7.2-3: `sisi workers` renames each stored score to standing, keeping source, date and maker; repeating it
|
||||
changes nothing."""
|
||||
self.seed(["wk-a", "wk-b"])
|
||||
self.write_legacy()
|
||||
self.run_sisi("workers")
|
||||
got = self.stored("model-strength.json")["models"]
|
||||
self.assertEqual(got["wk-a"], {"standing": 64.5, "source": self.LEGACY["models"]["wk-a"]["source"], "date": "2000-01-01"})
|
||||
self.assertEqual(got["wk-b"], {"standing": 40, "source": "fixture board", "date": "2000-01-02", "maker": "mk"})
|
||||
before = open(os.path.join(self.data, "model-strength.json")).read()
|
||||
self.run_sisi("workers")
|
||||
self.assertEqual(open(os.path.join(self.data, "model-strength.json")).read(), before)
|
||||
|
||||
def test_routing_reads_an_unmigrated_score_fact(self):
|
||||
"""Nothing is lost if `sisi route` runs before the migration: the old field is read as standing."""
|
||||
self.seed(["wk-a", "wk-b"])
|
||||
self.write_legacy()
|
||||
self.run_sisi("workers", "fact", "wk-a", "--price", "9", "--source", "fixture")
|
||||
self.run_sisi("workers", "fact", "wk-b", "--price", "1", "--source", "fixture")
|
||||
# restore the legacy file: fact above may have migrated it
|
||||
self.write_legacy()
|
||||
r = self.run_sisi("route", "--kind", "read", "--difficulty", "3", "--explain")
|
||||
self.assertEqual(r.stdout.splitlines()[0], "wk-a") # 40 is under 85 percent of 64.5
|
||||
self.assertIn("benchmark standing", r.stdout)
|
||||
|
||||
def test_fact_standing_and_the_old_score_flag_both_store_standing(self):
|
||||
"""R-7.2-3: the stored fact has its own name; --score stays as an alias."""
|
||||
self.run_sisi("workers", "fact", "wk-a", "--standing", "70", "--source", "fixture board")
|
||||
self.run_sisi("workers", "fact", "wk-b", "--score", "55", "--source", "fixture board")
|
||||
got = self.stored("model-strength.json")["models"]
|
||||
self.assertEqual(got["wk-a"]["standing"], 70)
|
||||
self.assertEqual(got["wk-b"]["standing"], 55)
|
||||
self.assertNotIn("score", got["wk-a"])
|
||||
self.assertNotIn("score", got["wk-b"])
|
||||
bad = self.sisi("workers", "fact", "wk-a", "--standing", "101", "--source", "x", env=dict(PATH=""))
|
||||
self.assertNotEqual(bad.returncode, 0)
|
||||
|
||||
def test_workers_shows_standing_and_accepted_rate_under_their_own_names(self):
|
||||
self.seed(["wk-a"], kind="read", difficulty=1, n=9)
|
||||
self.run_sisi("workers", "fact", "wk-a", "--standing", "64.5", "--source", "fixture board", "--date", "2000-01-01")
|
||||
out = self.run_sisi("workers").stdout
|
||||
self.assertIn("benchmark standing 64.5", out)
|
||||
self.assertIn("fixture board", out)
|
||||
self.assertIn("Accepted rate", out)
|
||||
self.assertNotIn("score", out.lower().replace("scorecard", ""))
|
||||
|
||||
def test_the_session_line_compares_standing_with_standing_only(self):
|
||||
"""A worker measured at 100 percent accepted with a low standing is not 'among the strongest' on the strength
|
||||
of that rate; a worker with a record but no standing has no standing to compare."""
|
||||
from sisi import routing, workers
|
||||
cands = [{"worker": "wk-a", "model": "wk-a", "standing": 40.0, "aliases": ["wk-a"]},
|
||||
{"worker": "wk-b", "model": "wk-b", "standing": 60.0, "aliases": ["wk-b"]},
|
||||
{"worker": "wk-c", "model": "wk-c", "standing": None, "aliases": ["wk-c"]}]
|
||||
recs = [{"kind": "attempt", "id": "r%d" % i, "type": "read", "difficulty": 1, "worker": w, "outcome": "accepted"}
|
||||
for w in ("wk-a", "wk-c") for i in range(20)]
|
||||
os.makedirs(self.data, exist_ok=True)
|
||||
json.dump({"models": {"wk-a": {"standing": 40, "source": "s"}, "wk-b": {"standing": 60, "source": "s"}}},
|
||||
open(os.path.join(self.data, "model-strength.json"), "w"))
|
||||
got = workers.strength_scores(cands)
|
||||
self.assertEqual({w: s for w, (s, _how) in got.items()}, {"wk-a": 40.0, "wk-b": 60.0})
|
||||
self.assertIn("benchmark standing", got["wk-a"][1])
|
||||
|
||||
|
||||
class PriceTests(FactsCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.seed(["wk-a", "wk-b"])
|
||||
|
||||
def route(self, difficulty="1"):
|
||||
return self.run_sisi("route", "--kind", "read", "--difficulty", difficulty, "--explain").stdout
|
||||
|
||||
def test_input_and_output_prices_are_stored_as_published(self):
|
||||
"""R-7.3-1."""
|
||||
self.run_sisi("workers", "fact", "wk-a", "--price-in", "1", "--price-out", "9", "--source", "fixture price list")
|
||||
e = self.stored("worker-prices.json")["models"]["wk-a"]
|
||||
self.assertEqual((e["price_in"], e["price_out"], e["source"]), (1, 9, "fixture price list"))
|
||||
self.assertNotIn("cost_per_million_tokens", e)
|
||||
bad = self.sisi("workers", "fact", "wk-a", "--price-in", "1", "--source", "x", env=dict(PATH=""))
|
||||
self.assertNotEqual(bad.returncode, 0) # both or neither
|
||||
both = self.sisi("workers", "fact", "wk-a", "--price", "2", "--price-in", "1", "--price-out", "9", "--source", "x", env=dict(PATH=""))
|
||||
self.assertNotEqual(both.returncode, 0)
|
||||
|
||||
def test_a_single_blended_price_still_works_and_replaces_an_input_output_pair(self):
|
||||
self.run_sisi("workers", "fact", "wk-a", "--price-in", "1", "--price-out", "9", "--source", "s")
|
||||
self.run_sisi("workers", "fact", "wk-a", "--price", "2", "--source", "s")
|
||||
e = self.stored("worker-prices.json")["models"]["wk-a"]
|
||||
self.assertEqual(e["cost_per_million_tokens"], 2)
|
||||
self.assertNotIn("price_in", e)
|
||||
|
||||
def test_ranking_uses_the_blend_three_input_to_one_output(self):
|
||||
"""wk-a: 1 in, 9 out blends to 3 at 3:1; wk-b: a single blended 3.5. wk-a is cheaper by the default ratio."""
|
||||
self.run_sisi("workers", "fact", "wk-a", "--price-in", "1", "--price-out", "9", "--source", "s")
|
||||
self.run_sisi("workers", "fact", "wk-b", "--price", "3.5", "--source", "s")
|
||||
self.assertEqual(self.route().splitlines()[0], "wk-a")
|
||||
|
||||
def test_the_blend_ratio_is_configurable(self):
|
||||
"""At 1:1 wk-a blends to 5, dearer than wk-b's 3.5."""
|
||||
self.run_sisi("workers", "fact", "wk-a", "--price-in", "1", "--price-out", "9", "--source", "s")
|
||||
self.run_sisi("workers", "fact", "wk-b", "--price", "3.5", "--source", "s")
|
||||
json.dump({"route": {"price_blend_input_parts": 1}}, open(os.path.join(self.data, "config.json"), "w"))
|
||||
self.assertEqual(self.route().splitlines()[0], "wk-b")
|
||||
|
||||
def test_workers_shows_both_prices_and_the_blend(self):
|
||||
self.run_sisi("workers", "fact", "wk-a", "--price-in", "2", "--price-out", "10", "--source", "fixture price list")
|
||||
out = self.run_sisi("workers").stdout
|
||||
self.assertIn("wk-a", out)
|
||||
self.assertIn("2 in", out)
|
||||
self.assertIn("10 out", out)
|
||||
self.assertIn("blended 4", out)
|
||||
|
||||
def test_estimated_cost_uses_the_blend(self):
|
||||
from sisi import workers
|
||||
self.assertEqual(workers.estimate_cost(2000000, {"price_in": 1, "price_out": 9}), 6.0)
|
||||
self.assertEqual(workers.estimate_cost(2000000, {"cost_per_million_tokens": 2}), 4.0)
|
||||
self.assertEqual(workers.estimate_cost(2000000, {"cost": 3}), 6.0)
|
||||
self.assertIsNone(workers.estimate_cost(2000000, {"price_in": 1}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user