Item 7: a maker's classes, most capable first (sisi workers classes), as a prior between its classes below any judged record or benchmark; configurable span per difficulty; the strongest-known fallback follows it; one line asks for the order. done / next: the grid on the copy (item 6), repeat runs
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7db6584388
commit
d6bdb799c5
6 files changed
+302
-24
No files matched your search
+6
-1
@@ -18,7 +18,12 @@
|
||||
"3": 85
|
||||
},
|
||||
"price_blend_input_parts": 3,
|
||||
"supersede_guessed": true
|
||||
"supersede_guessed": true,
|
||||
"class_span": {
|
||||
"1": 100,
|
||||
"2": 70,
|
||||
"3": 35
|
||||
}
|
||||
},
|
||||
"unit": {
|
||||
"stale_hours": 12
|
||||
|
||||
@@ -20,6 +20,12 @@ or learned from judged results. The strategy is [canon/orchestration.md](../cano
|
||||
A fact without a source is refused. Ranking uses one blend of the two prices, by default three
|
||||
parts input to one part output (`route.price_blend_input_parts`); `sisi workers` shows both
|
||||
prices and the blend, and lists each benchmark standing apart from the accepted rates it prints.
|
||||
- `sisi workers fact WORKER --class NAME [--family NAME] [--maker M] [--released YYYY-MM-DD] --source S` — the
|
||||
class, line and release date the lead agent decided for a model; a recorded fact beats the parser.
|
||||
`sisi workers` lists each routable worker's maker, class (recorded, or a guess read from the id) and recency.
|
||||
- `sisi workers classes MAKER CLASS [CLASS...] --source S` — a maker's classes from most capable to least
|
||||
(`--remove` forgets them). A class is the tier word of one line (a "flash" beside the standard model) or,
|
||||
for a maker whose lines are the classes, the line's own name; `sisi workers` shows both as the class label.
|
||||
- `sisi workers avoid|prefer PATTERN --why TEXT` — the user's own routing constraints.
|
||||
- `sisi workers only PROVIDER PATTERN... --why TEXT` — only the matching models of that provider are
|
||||
routable; anything else from it (a newly discovered model, say) is passed over with the reason.
|
||||
@@ -102,6 +108,16 @@ supersede each other. A class read from the id with confidence takes part at onc
|
||||
cannot be read (no version, or a word the data does not know) never does, and `sisi route` adds one
|
||||
line asking the lead agent to record it.
|
||||
|
||||
The class order is a prior and nothing more. A worker with no judged proof and no benchmark standing,
|
||||
whose class is in its maker's recorded order, is capable when the class sits high enough for the
|
||||
difficulty: `route.class_span` (default routine work 100, ordinary 70, hard 35) is the share of the order,
|
||||
counted from the most capable class down, that each difficulty reaches. With four classes routine work
|
||||
reaches all four, ordinary work the top three, hard work the top two; the cheapest capable worker then
|
||||
wins, so routine work goes to the lowest class and hard work to the upper ones. A judged record or a
|
||||
benchmark standing always outranks the order; when nobody is proven, the strongest known worker is the
|
||||
one in the highest class. Classes of different makers are never compared. Until a maker with two or
|
||||
more classes among the usable workers has an order recorded, `sisi route` adds one line asking for it.
|
||||
|
||||
A new version starts from its predecessor's judged record: a model with no thick record of its own
|
||||
for a kind and difficulty inherits, as evidence, the thick record of the closest older version of
|
||||
its maker and class (one version back at a time), named in `--explain`. It ranks below the model's
|
||||
|
||||
+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); --learning prints only the learning report',
|
||||
'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|--standing N --source S record a price (per million tokens) or benchmark standing (0-100), with its source and date\n sisi workers fact W --class NAME [--family NAME] [--released DATE] --source S the class, line and release date you decided for a model; beats the parser\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 fact W --class NAME [--family NAME] [--released DATE] --source S the class, line and release date you decided for a model; beats the parser\n sisi workers classes MAKER CLASS... --source S | MAKER --remove the classes of a maker, most capable first (a prior between them)\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',
|
||||
|
||||
+80
-18
@@ -70,6 +70,7 @@ UNKNOWN_ALLOWANCE = 50.0 # allowance weight when a tool reports none
|
||||
STRONG_BAND = 10.0 # standing points from the best still counts as among the strongest
|
||||
EXPLORE_EVERY = 10 # about one low-stakes task in ten tries a cheaper thin-record worker
|
||||
DEFAULT_STANDING_FLOOR = {1: 0.0, 2: 60.0, 3: 85.0} # percent of the best usable standing needed
|
||||
DEFAULT_CLASS_SPAN = {1: 100.0, 2: 70.0, 3: 35.0} # how far down a maker's class order still counts as capable
|
||||
DEFAULT_PRICE_BLEND = 3.0 # parts of input price to one part of output price in a blended price
|
||||
|
||||
|
||||
@@ -121,6 +122,32 @@ def _floor_pct(floors, difficulty):
|
||||
return table[max(table)]
|
||||
|
||||
|
||||
def class_spans(configured=None):
|
||||
"""{difficulty: percent of a maker's class order, from the most capable class down, that is capable enough}.
|
||||
With four classes: routine work (100) reaches all four, ordinary work (70) the top three, hard work (35) the
|
||||
top two. The defaults are overridden by valid entries of the configured mapping (keys 1..3, values 0..100)."""
|
||||
table = dict(DEFAULT_CLASS_SPAN)
|
||||
if isinstance(configured, dict):
|
||||
for k, v in configured.items():
|
||||
try:
|
||||
d, pct = int(k), float(v)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if 1 <= d <= 3 and 0 <= pct <= 100:
|
||||
table[d] = pct
|
||||
return table
|
||||
|
||||
|
||||
def class_rank(c, opts=None):
|
||||
"""(position, count) of the model's class in its maker's recorded order (0 is the most capable), or None when
|
||||
the maker has no recorded order, the class could not be read, or the class is not in the order."""
|
||||
l = _lineage(c)
|
||||
order = ((opts or {}).get("class_orders") or {}).get(l.get("maker")) if l and l.get("key") else None
|
||||
if not order or l.get("label") not in order:
|
||||
return None
|
||||
return order.index(l["label"]), len(order)
|
||||
|
||||
|
||||
def _pattern_match(c, patterns):
|
||||
"""The (pattern, why) a candidate matches, or None. A pattern matches as a substring of the
|
||||
worker, model or tool name, case aside."""
|
||||
@@ -297,7 +324,7 @@ def _by_difficulty(stats, worker, kind):
|
||||
return own, pooled
|
||||
|
||||
|
||||
def assess(stats, worker, kind, difficulty, standing=None, best_standing=None, floors=None):
|
||||
def assess(stats, worker, kind, difficulty, standing=None, best_standing=None, floors=None, rank=None, spans=None):
|
||||
"""What the evidence says about one worker for a kind and difficulty. Returns a dict:
|
||||
tier "a", "b-higher", "b-all", "standing", "unknown" or "none"
|
||||
capable whether the evidence says it is capable enough
|
||||
@@ -307,7 +334,12 @@ def assess(stats, worker, kind, difficulty, standing=None, best_standing=None, f
|
||||
level 3 judged proof, 2 benchmark, 1 weak, 0 nothing, -1 bad: never rises with difficulty
|
||||
n, good, at the judged cell behind a, b-higher, b-all and the weak tier (and its difficulty)
|
||||
share, needed, floor for the standing tier: percent of the best, the figure needed, the floor
|
||||
Standing is compared only with the best standing; a rate only with the bar."""
|
||||
class_pos, class_n, class_share, class_allowed for the class tier (see below)
|
||||
inherited_from the worker whose record this is, when it is a predecessor's (see inherit_stats)
|
||||
The class tier is the last prior: a worker with no judged proof and no standing of its own, whose class has a
|
||||
place in its maker's recorded order (`rank`, from class_rank), is capable when that place is within the span the
|
||||
difficulty allows (`spans`, see class_spans). Standing is compared only with the best standing; a rate only with
|
||||
the bar; neither is ever compared with a class."""
|
||||
d = difficulty
|
||||
own, pooled = _by_difficulty(stats, worker, kind)
|
||||
out = {"tier": "none", "capable": False, "bad": False, "weak": False, "contradicted": False,
|
||||
@@ -350,6 +382,14 @@ def assess(stats, worker, kind, difficulty, standing=None, best_standing=None, f
|
||||
if not out["contradicted"]:
|
||||
out.update(tier="standing", capable=capable, level=2 if capable else (1 if out["weak"] else 0))
|
||||
return out
|
||||
if standing is None and rank is not None and not out["contradicted"]:
|
||||
pos, n = rank
|
||||
share = 100.0 * pos / (n - 1) if n > 1 else 0.0
|
||||
allowed = class_spans(spans).get(d, 100.0 if d is None or d < 1 else class_spans(spans)[3])
|
||||
capable = share <= allowed + 1e-9
|
||||
out.update(tier="class", capable=capable, level=1 if capable else 0, class_pos=pos, class_n=n,
|
||||
class_share=share, class_allowed=allowed)
|
||||
return out
|
||||
if standing is None and d == 1 and not out["contradicted"]:
|
||||
out.update(tier="unknown", capable=True, level=0)
|
||||
return out
|
||||
@@ -370,6 +410,8 @@ def strength(a):
|
||||
return (4, -_TIER_RANK[a["tier"]], a["measure"])
|
||||
if a["standing"] is not None and not a["contradicted"]:
|
||||
return (3, 0, float(a["standing"]))
|
||||
if a["tier"] == "class":
|
||||
return (1, 1, 1.0 - a["class_share"] / 100.0) # the maker's own order: below a weak judged record
|
||||
if a["weak"]:
|
||||
return (2, 0, a["weak_rate"])
|
||||
return (1, 0, 0.0)
|
||||
@@ -487,11 +529,13 @@ def _prepare(candidates, records, availability, now, exclude, avoid, review_of,
|
||||
return eligible, passed, stats, author_maker, superseded
|
||||
|
||||
|
||||
def _assess_all(eligible, stats, kind, difficulty, floors):
|
||||
def _assess_all(eligible, stats, kind, difficulty, floors, opts=None):
|
||||
"""({worker: assessment}, best standing among the usable workers)."""
|
||||
standings = [s for s in (_standing_of(c) for c in eligible) if s is not None]
|
||||
best = max(standings) if standings else None
|
||||
return ({c["worker"]: assess(stats, c["worker"], kind, difficulty, _standing_of(c), best, floors)
|
||||
spans = (opts or {}).get("class_span")
|
||||
return ({c["worker"]: assess(stats, c["worker"], kind, difficulty, _standing_of(c), best, floors,
|
||||
rank=class_rank(c, opts), spans=spans)
|
||||
for c in eligible}, best)
|
||||
|
||||
|
||||
@@ -555,6 +599,9 @@ def _prefer_judged(capable, assessments, difficulty):
|
||||
own = [c for c in capable if assessments[c["worker"]]["tier"] in tiers]
|
||||
if own:
|
||||
return own, True
|
||||
benchmarked = [c for c in capable if assessments[c["worker"]]["tier"] == "standing"]
|
||||
if benchmarked and len(benchmarked) < len(capable):
|
||||
return benchmarked, False # a benchmark standing outranks a class's place in its maker's order
|
||||
return list(capable), False
|
||||
|
||||
|
||||
@@ -574,7 +621,7 @@ def _select(eligible, assessments, difficulty):
|
||||
return weak, "weak"
|
||||
top = max(strength(assessments[c["worker"]]) for c in live)
|
||||
pool = [c for c in live if strength(assessments[c["worker"]]) == top]
|
||||
return pool, ("nothing" if top[0] <= 1 else "strongest")
|
||||
return pool, ("nothing" if top[:2] <= (1, 0) else "strongest")
|
||||
|
||||
|
||||
def choose(candidates, records, availability, kind, difficulty, review_of=None, now=0.0, exclude=(),
|
||||
@@ -585,7 +632,7 @@ def choose(candidates, records, availability, kind, difficulty, review_of=None,
|
||||
now = float(now or 0)
|
||||
eligible, passed, stats, author_maker, superseded = _prepare(candidates, records, availability, now, exclude,
|
||||
avoid, review_of, opts)
|
||||
assessments, best = _assess_all(eligible, inherit_stats(candidates, stats, opts), kind, difficulty, floors)
|
||||
assessments, best = _assess_all(eligible, inherit_stats(candidates, stats, opts), kind, difficulty, floors, opts)
|
||||
key, rate, load_ratio, recency = _make_key(stats, kind, difficulty, prefer, recency_order(eligible))
|
||||
|
||||
pool, basis = _select(eligible, assessments, difficulty) if eligible else ([], "none")
|
||||
@@ -652,22 +699,27 @@ def choose(candidates, records, availability, kind, difficulty, review_of=None,
|
||||
"load_ratios": {c["worker"]: load_ratio(c) for c in candidates},
|
||||
"assessments": assessments, "basis": basis, "capable_count": capable_n, "judged_first": judged_first,
|
||||
"best_standing": best, "passed_detail": detail, "floors": floors,
|
||||
"superseded": superseded, "class_ask": class_ask(eligible),
|
||||
"superseded": superseded, "class_ask": class_ask(eligible, opts),
|
||||
"kind": kind, "difficulty": difficulty}
|
||||
|
||||
|
||||
def class_ask(eligible):
|
||||
"""What the lead agent should be asked to record, because it is about to matter: {"classify": [workers]}.
|
||||
A worker whose class could not be read from its id, when another usable worker has the same maker (the two
|
||||
may be versions of one class). A class read from the id with confidence is not asked about; a recorded one
|
||||
never is."""
|
||||
makers = {}
|
||||
def class_ask(eligible, opts=None):
|
||||
"""What the lead agent should be asked to record, because it is about to matter:
|
||||
{"classify": [workers], "order": [(maker, [class labels])]}.
|
||||
classify: a worker whose class could not be read from its id, when another usable worker has the same maker (the
|
||||
two may be versions of one class). A class read from the id with confidence is not asked about; a recorded one
|
||||
never is. order: a maker with two or more classes among the usable workers and no recorded class order."""
|
||||
makers, labels = {}, {}
|
||||
for c in eligible:
|
||||
l = _lineage(c)
|
||||
if l:
|
||||
makers.setdefault(l.get("maker"), []).append(c["worker"])
|
||||
if l.get("key"):
|
||||
labels.setdefault(l.get("maker"), set()).add(l.get("label"))
|
||||
recorded = (opts or {}).get("class_orders") or {}
|
||||
return {"classify": sorted(c["worker"] for c in eligible if _lineage(c)
|
||||
and _lineage(c).get("source") == "unknown" and len(makers.get(_lineage(c).get("maker"), [])) > 1)}
|
||||
and _lineage(c).get("source") == "unknown" and len(makers.get(_lineage(c).get("maker"), [])) > 1),
|
||||
"order": [(m, sorted(ls)) for m, ls in sorted(labels.items()) if len(ls) > 1 and m not in recorded]}
|
||||
|
||||
|
||||
def _why_not(a, difficulty, basis, cheaper):
|
||||
@@ -683,9 +735,14 @@ def _why_not(a, difficulty, basis, cheaper):
|
||||
if a["tier"] == "b-all":
|
||||
return (lead + "its only judged proof is across other kinds, and a worker with a judged record "
|
||||
"for this kind is usable", None)
|
||||
return (lead + "capable only by benchmark standing or as an exploration; above difficulty 1 a worker "
|
||||
"with a judged record is preferred to a benchmark",
|
||||
return (lead + "capable only by benchmark standing, its class's place in its maker's order, or as an "
|
||||
"exploration; above difficulty 1 a worker with a judged record is preferred to a benchmark, and a "
|
||||
"benchmark to a class order",
|
||||
("standing %g" % a["standing"]) if a["standing"] is not None else None)
|
||||
if a["tier"] == "class":
|
||||
return (lead + "not capable enough for difficulty %d: its class is place %d of %d in its maker's recorded order, "
|
||||
"and difficulty %d reaches only the top %g%% of it" % (difficulty, a["class_pos"] + 1, a["class_n"],
|
||||
difficulty, a["class_allowed"]), None)
|
||||
if a.get("below"):
|
||||
return (lead + "not capable enough for difficulty %d: benchmark standing under the %g needed "
|
||||
"(%g%% of the best usable standing, %g)" % (difficulty, a["needed"], a["floor"], a["best"]),
|
||||
@@ -720,7 +777,7 @@ def retry_choice(candidates, records, availability, kind, difficulty, rejected,
|
||||
eligible, passed, stats, author_maker, _superseded = _prepare(candidates, records, availability, now, exclude,
|
||||
avoid, review_of, opts)
|
||||
eff = inherit_stats(candidates, stats, opts)
|
||||
assessments, best = _assess_all(eligible, eff, kind, difficulty, floors)
|
||||
assessments, best = _assess_all(eligible, eff, kind, difficulty, floors, opts)
|
||||
key, _rate, _load, _recency = _make_key(stats, kind, difficulty, prefer, recency_order(eligible))
|
||||
out = {"choice": None, "step": None, "passed_over": passed, "stats": stats, "author_maker": author_maker,
|
||||
"assessments": assessments, "best_standing": best, "kind": kind, "difficulty": difficulty,
|
||||
@@ -736,7 +793,8 @@ def retry_choice(candidates, records, availability, kind, difficulty, rejected,
|
||||
return out
|
||||
gone = next((c for c in candidates if c["worker"] == rejected), None)
|
||||
floor = (strength(assessments[rejected]) if mine is not None else
|
||||
strength(assess(eff, rejected, kind, difficulty, _standing_of(gone) if gone else None, best, floors)))
|
||||
strength(assess(eff, rejected, kind, difficulty, _standing_of(gone) if gone else None, best, floors,
|
||||
rank=class_rank(gone, opts) if gone else None, spans=(opts or {}).get("class_span"))))
|
||||
better = [c for c in others if assessments[c["worker"]]["capable"] and strength(assessments[c["worker"]]) > floor]
|
||||
better = _prefer_judged(better, assessments, difficulty)[0]
|
||||
if better:
|
||||
@@ -800,6 +858,10 @@ def _evidence_line(a, kind, difficulty, choice, basis):
|
||||
return ("evidence (c), benchmark standing only: %g (%s, %s), the strongest known; it is under the %g "
|
||||
"needed for difficulty %d" % (a["standing"], src, choice.get("standing_date") or "no date stated",
|
||||
a["needed"], difficulty))
|
||||
if tier == "class":
|
||||
return ("evidence (class order): place %d of %d in its maker's recorded class order, which reaches the top %g%% "
|
||||
"for difficulty %d; no judged record or benchmark decides" % (a["class_pos"] + 1, a["class_n"],
|
||||
a["class_allowed"], difficulty))
|
||||
if tier == "unknown":
|
||||
return "evidence (d): nothing is known about this worker yet; it is an exploration on low-stakes work"
|
||||
if a.get("weak"):
|
||||
|
||||
+61
-4
@@ -597,10 +597,15 @@ def model_words():
|
||||
|
||||
|
||||
def route_opts():
|
||||
"""Routing options from the config: `route.supersede_guessed` (default true) lets a class read from the id with
|
||||
confidence, not yet recorded by the lead agent, take part in the rule that the newest version of a class wins."""
|
||||
"""Routing options: `route.supersede_guessed` (default true) lets a class read from the id with confidence, not yet
|
||||
recorded by the lead agent, take part in the rule that the newest version of a class wins; the maker class orders
|
||||
the lead agent recorded (`sisi workers classes`); and `route.class_span`, how far down an order each difficulty
|
||||
reaches."""
|
||||
v = route_cfg().get("supersede_guessed")
|
||||
return {"supersede_guessed": v if isinstance(v, bool) else True}
|
||||
orders = {m: [str(x) for x in e["order"]] for m, e in load_model_facts()[1].items()
|
||||
if isinstance(e, dict) and isinstance(e.get("order"), list)}
|
||||
return {"supersede_guessed": v if isinstance(v, bool) else True, "class_orders": orders,
|
||||
"class_span": route_cfg().get("class_span")}
|
||||
|
||||
|
||||
def route_floors():
|
||||
@@ -1461,6 +1466,8 @@ def cmd_workers(args=()):
|
||||
return _cmd_only(args[1:])
|
||||
if args[:1] == ["note"]:
|
||||
return _cmd_note(args[1:])
|
||||
if args[:1] == ["classes"]:
|
||||
return _cmd_classes(args[1:])
|
||||
if args[:1] == ["down"]:
|
||||
return _cmd_down(args[1:])
|
||||
if args[:1] == ["up"]:
|
||||
@@ -1519,6 +1526,9 @@ def cmd_workers(args=()):
|
||||
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"))
|
||||
for maker, e in sorted(load_model_facts()[1].items()):
|
||||
if isinstance(e, dict):
|
||||
print(_classes_line(maker, e))
|
||||
routable, cold, _excluded = routable_candidates(build_candidates(disc, records), records)
|
||||
if routable and not cold:
|
||||
print("Model lines (the class of each routable worker; a guess is read from the id alone: confirm it "
|
||||
@@ -1586,7 +1596,12 @@ def _route_setup(args):
|
||||
|
||||
def class_line(result):
|
||||
"""The one line asking the lead agent to determine a class sisi cannot read from the id, or None."""
|
||||
names = (result.get("class_ask") or {}).get("classify") or []
|
||||
ask = result.get("class_ask") or {}
|
||||
names = ask.get("classify") or []
|
||||
if not names and ask.get("order"):
|
||||
maker, labels = ask["order"][0]
|
||||
return ("sisi: classify %s's models and record the order, most capable first: `sisi workers classes %s %s --source S` "
|
||||
"(classes seen: %s)" % (maker, maker, " ".join(labels), ", ".join(labels)))
|
||||
if not names:
|
||||
return None
|
||||
return ("sisi: the class of %s%s cannot be read from its id: decide it and record it with "
|
||||
@@ -2096,6 +2111,48 @@ def _model_fact_args(args):
|
||||
return out
|
||||
|
||||
|
||||
def _cmd_classes(args):
|
||||
"""`sisi workers classes MAKER CLASS [CLASS...] --source S` records a maker's classes, most capable first;
|
||||
`sisi workers classes MAKER --remove` forgets them; no arguments lists them."""
|
||||
usage = ("usage: sisi workers classes MAKER CLASS [CLASS...] --source S [--date YYYY-MM-DD] (most capable class first)\n"
|
||||
" sisi workers classes MAKER --remove")
|
||||
data = read_json(models_path())
|
||||
classes = data.get("classes") if isinstance(data.get("classes"), dict) else {}
|
||||
pos = _positional(args, ("--source", "--date"))
|
||||
if not pos:
|
||||
for maker, e in sorted(classes.items()):
|
||||
print(_classes_line(maker, e))
|
||||
return 0 if classes else (print("no class order recorded yet.\n" + usage) or 0)
|
||||
maker, names = pos[0].strip().lower(), [x.strip().lower() for x in pos[1:]]
|
||||
if "--remove" in args:
|
||||
if names or maker not in classes:
|
||||
print(usage if names else "sisi: no class order is recorded for %s" % maker, file=sys.stderr)
|
||||
return 1
|
||||
del classes[maker]
|
||||
data["classes"] = classes
|
||||
write_json(models_path(), data)
|
||||
print("removed the class order of %s" % maker)
|
||||
return 0
|
||||
source = _opt(args, "--source")
|
||||
if not names or not source:
|
||||
print(usage, file=sys.stderr)
|
||||
return 1
|
||||
if any(not _NAME.fullmatch(x) for x in [maker] + names) or len(set(names)) != len(names):
|
||||
print("sisi: a maker and each class is one short name (letters, digits, hyphens), none repeated", file=sys.stderr)
|
||||
return 1
|
||||
entry = {"order": names, "source": source, "date": _opt(args, "--date") or time.strftime("%Y-%m-%d", time.localtime())}
|
||||
classes[maker] = entry
|
||||
data["classes"] = classes
|
||||
write_json(models_path(), data)
|
||||
print(_classes_line(maker, entry).strip().replace("Classes of", "recorded the classes of", 1))
|
||||
return 0
|
||||
|
||||
|
||||
def _classes_line(maker, e):
|
||||
return "Classes of %s, most capable first: %s (%s, %s)" % (maker, ", ".join(e.get("order") or []),
|
||||
e.get("source") or "no source stated", e.get("date") or "no date stated")
|
||||
|
||||
|
||||
def _cmd_pref(kind, args):
|
||||
prefs = load_prefs()
|
||||
if not args:
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
"""A maker's classes, most capable first: a prior between classes of that maker where nothing better exists, never
|
||||
above a judged record or a benchmark standing. Invented ids: for this maker each class is a named line.
|
||||
Requirement ids: R-7.2-1, R-7.2-2, R-7.2-3."""
|
||||
import json, os, random, unittest
|
||||
from support import *
|
||||
from sisi import routing
|
||||
from test_model_supersession import cand, attempts, pick, NOW
|
||||
from test_worker_models import ModelCase
|
||||
|
||||
ORDER = {"abc": ["fable", "opus", "sonnet", "haiku"]}
|
||||
COST = {"fable": 9.0, "opus": 6.0, "sonnet": 3.0, "haiku": 1.0}
|
||||
|
||||
|
||||
def fleet(**extra):
|
||||
return [cand("prov/abc-%s-5" % c, **dict({"cost": COST[c]}, **extra.get(c, {}))) for c in ("fable", "opus", "sonnet", "haiku")]
|
||||
|
||||
|
||||
def best(cands, difficulty, records=(), **kw):
|
||||
opts = {"class_orders": ORDER}
|
||||
opts.update(kw.pop("opts", {}))
|
||||
return pick(cands, records, difficulty, opts=opts, **kw)
|
||||
|
||||
|
||||
class ClassOrderTests(unittest.TestCase):
|
||||
def test_routine_work_goes_to_the_lowest_class_and_hard_work_to_the_upper_ones(self):
|
||||
"""Nothing judged, no benchmark: the order is the prior and the cheapest capable class wins."""
|
||||
cands = fleet()
|
||||
self.assertEqual(best(cands, 1)[0], "prov/abc-haiku-5")
|
||||
self.assertEqual(best(cands, 2)[0], "prov/abc-sonnet-5")
|
||||
who, r = best(cands, 3)
|
||||
self.assertEqual(who, "prov/abc-opus-5")
|
||||
self.assertEqual(r["assessments"]["prov/abc-opus-5"]["tier"], "class")
|
||||
self.assertFalse(r["assessments"]["prov/abc-sonnet-5"]["capable"])
|
||||
|
||||
def test_the_mapping_is_configurable(self):
|
||||
cands = fleet()
|
||||
self.assertEqual(best(cands, 3, opts={"class_span": {"3": 0}})[0], "prov/abc-fable-5")
|
||||
self.assertEqual(best(cands, 3, opts={"class_span": {"3": 100}})[0], "prov/abc-haiku-5")
|
||||
self.assertEqual(routing.class_spans({"2": "x", "9": 50, "1": 101})[1], 100.0)
|
||||
|
||||
def test_without_a_recorded_order_a_class_is_no_evidence(self):
|
||||
who, r = pick(fleet(), (), 3)
|
||||
self.assertEqual(r["basis"], "nothing")
|
||||
self.assertFalse(any(a["tier"] == "class" for a in r["assessments"].values()))
|
||||
|
||||
def test_a_judged_record_outranks_the_order(self):
|
||||
records = attempts("prov/abc-haiku-5", 12, 12, difficulty=3)
|
||||
who, r = best(fleet(), 3, records)
|
||||
self.assertEqual(who, "prov/abc-haiku-5")
|
||||
self.assertEqual(r["assessments"]["prov/abc-haiku-5"]["tier"], "a")
|
||||
|
||||
def test_a_benchmark_standing_outranks_the_order(self):
|
||||
cands = fleet(haiku={"standing": 80.0, "cost": 5.0})
|
||||
who, r = best(cands, 2)
|
||||
self.assertEqual(who, "prov/abc-haiku-5") # sonnet is capable by class and cheaper than none, but the standing is preferred
|
||||
self.assertEqual(r["assessments"]["prov/abc-haiku-5"]["tier"], "standing")
|
||||
self.assertTrue(any("benchmark" in why for w, why in r["passed_over"] if w == "prov/abc-sonnet-5"))
|
||||
|
||||
def test_when_nobody_is_proven_the_strongest_known_means_the_highest_class(self):
|
||||
cands = [c for c in fleet() if c["worker"] in ("prov/abc-sonnet-5", "prov/abc-haiku-5")]
|
||||
who, r = best(cands, 3)
|
||||
self.assertEqual((who, r["basis"]), ("prov/abc-sonnet-5", "strongest"))
|
||||
|
||||
def test_another_makers_models_are_not_placed_by_this_order(self):
|
||||
other = cand("prov/xyz-opus-5", cost=0.1, maker="xyz")
|
||||
who, r = best(fleet() + [other], 3)
|
||||
self.assertEqual(who, "prov/abc-opus-5")
|
||||
self.assertNotEqual(r["assessments"]["prov/xyz-opus-5"]["tier"], "class")
|
||||
|
||||
def test_a_class_missing_from_the_order_is_not_placed(self):
|
||||
extra = cand("prov/abc-ember-1", cost=0.1)
|
||||
who, r = best(fleet() + [extra], 3)
|
||||
self.assertNotEqual(r["assessments"]["prov/abc-ember-1"]["tier"], "class")
|
||||
|
||||
def test_the_asking_line_wants_the_order_of_a_maker_with_several_classes(self):
|
||||
r = pick(fleet(), (), 3)[1]
|
||||
self.assertEqual(r["class_ask"]["order"], [("abc", ["fable", "haiku", "opus", "sonnet"])])
|
||||
r = best(fleet(), 3)[1]
|
||||
self.assertEqual(r["class_ask"]["order"], [])
|
||||
one = pick([cand("prov/abc-opus-5"), cand("prov/abc-opus-6")], (), 3)[1]
|
||||
self.assertEqual(one["class_ask"]["order"], []) # one class only: nothing to order
|
||||
|
||||
def test_property_the_order_never_outranks_a_record_or_a_standing(self):
|
||||
rng = random.Random(9)
|
||||
for _ in range(300 * ITERS):
|
||||
cands = [cand("prov/abc-%s-5" % c, cost=rng.choice([1.0, 2.0, 5.0]),
|
||||
standing=rng.choice([None, None, 40.0, 90.0])) for c in rng.sample(list(COST), rng.randint(2, 4))]
|
||||
records = []
|
||||
for c in cands:
|
||||
for d in (1, 2, 3):
|
||||
if rng.random() < 0.4:
|
||||
n = rng.choice([3, 10, 12])
|
||||
records += attempts(c["worker"], n, rng.randint(0, n), difficulty=d)
|
||||
d = rng.choice([2, 3])
|
||||
who, r = best(cands, d, records)
|
||||
if who is None or r["basis"] != "capable":
|
||||
continue
|
||||
tiers = {w: a["tier"] for w, a in r["assessments"].items() if a["capable"]}
|
||||
if any(t in ("a", "b-higher", "b-all") for t in tiers.values()):
|
||||
self.assertIn(tiers[who], ("a", "b-higher", "b-all"))
|
||||
elif any(t == "standing" for t in tiers.values()):
|
||||
self.assertEqual(tiers[who], "standing")
|
||||
|
||||
|
||||
class ClassesCommandTests(ModelCase):
|
||||
def test_a_makers_classes_are_recorded_shown_and_removed(self):
|
||||
self.seed([("prov/abc-5.3", 9, 9)])
|
||||
r = self.sisi("workers", "classes", "abc", "fable", "opus", "sonnet", "haiku", "--source", "owner, in his words", env=self.env())
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
stored = json.load(open(os.path.join(self.data, "worker-models.json")))["classes"]["abc"]
|
||||
self.assertEqual((stored["order"], stored["source"]), (["fable", "opus", "sonnet", "haiku"], "owner, in his words"))
|
||||
self.assertIn("Classes of abc, most capable first: fable, opus, sonnet, haiku (owner, in his words", self.listing())
|
||||
self.assertEqual(self.sisi("workers", "classes", "abc", "--remove", env=self.env()).returncode, 0)
|
||||
self.assertNotIn("Classes of abc", self.listing())
|
||||
|
||||
def test_bad_input_is_refused(self):
|
||||
for args in (("abc", "opus"), ("abc", "--source", "x"), ("abc", "o pus", "--source", "x"), ("abc", "opus", "opus", "--source", "x")):
|
||||
r = self.sisi("workers", "classes", *args, env=self.env())
|
||||
self.assertEqual(r.returncode, 1, args)
|
||||
self.assertFalse(os.path.exists(os.path.join(self.data, "worker-models.json")))
|
||||
|
||||
def test_route_uses_the_recorded_order_and_asks_for_it_until_then(self):
|
||||
models = ("abc-fable-5", "abc-opus-5", "abc-sonnet-5", "abc-haiku-5")
|
||||
for m in models:
|
||||
self.sisi("workers", "fact", "muse/" + m, "--price", str(COST[m.split("-")[1]]), "--source", "fixture", env=self.env(models))
|
||||
first = self.route(3, models=models)
|
||||
self.assertIn("record the order", first.stdout)
|
||||
self.assertLessEqual(len(first.stdout.splitlines()), 7, first.stdout)
|
||||
self.sisi("workers", "classes", "abc", "fable", "opus", "sonnet", "haiku", "--source", "owner", env=self.env(models))
|
||||
after = self.route(3, "--explain", models=models)
|
||||
self.assertEqual(after.stdout.splitlines()[0], "muse/abc-opus-5", after.stdout)
|
||||
self.assertNotIn("record the order", after.stdout)
|
||||
self.assertIn("class order", after.stdout)
|
||||
self.assertEqual(self.route(1, models=models).stdout.splitlines()[0], "muse/abc-haiku-5")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user