best_engine_ai_helper.cloud_catalog module
cloud_catalog — pick the best PAID model for a task, the cloud counterpart of
best_engine_ai_helper.score.
Local mode (score, recommend) auto-picks the best model from a
catalog by weighing benchmark quality against memory fit — free, since the
hardware is already paid for. Cloud mode auto-picks the best model from a
different catalog by weighing benchmark quality against price: every
candidate fits on any machine (the provider owns the hardware), so cost is
the resource being budgeted instead of memory.
The catalog is pricing.yaml at the package root: the same table
best_engine_ai_helper.observe already reads to price a completed call,
extended with provider, kind (llm/vlm), structured_output,
and benchmarks per entry. One file, two consumers — pricing after the
call, ranking before it — so cost and quality can never drift apart into two
different numbers for the same model.
- best_engine_ai_helper.cloud_catalog.blended_price_per_1m(entry)[source]
A single $/1M-token comparability figure for one catalog entry.
A real workload’s input/output ratio varies by task (a long-document summary is input-heavy; an open-ended generation is output-heavy), so this is a simple average of the two list prices, not a workload-specific estimate — the same “rough estimate, not a bill” honesty
pricing.yamlalready documents for the ledger side.- Parameters:
entry (dict[str, Any]) – A catalog entry with
input_per_1m/output_per_1m(USD).- Returns:
(input_per_1m + output_per_1m) / 2.0.0when both are absent.- Return type:
Examples
>>> blended_price_per_1m({"input_per_1m": 2.0, "output_per_1m": 10.0}) 6.0
- best_engine_ai_helper.cloud_catalog.load_cloud_catalog(path=None)[source]
Load the bundled paid-model catalog (
pricing.yaml).- Parameters:
path (Path or None) – Override the catalog file (tests use a fixture). Defaults to the bundled
pricing.yamlnext topyproject.toml.- Returns:
One dict per model, each carrying its YAML key as
idplusprovider,kind,structured_output,benchmarks,input_per_1m,output_per_1m.- Return type:
- Raises:
FileNotFoundError – If
pathis given explicitly and does not exist.
Examples
>>> entries = load_cloud_catalog() >>> all({"id", "provider", "kind"} <= e.keys() for e in entries) True
- best_engine_ai_helper.cloud_catalog.pick_cloud(catalog, kind, application=None, quality_vs_cost=0.7, provider=None)[source]
Return the single best paid candidate, or None if nothing matches.
Thin wrapper over
rank_cloud()—rank_cloud(...)[0], or None on an empty ranking, so callers do not need anIndexErrorguard.- Parameters:
catalog (see
rank_cloud().)kind (see
rank_cloud().)application (see
rank_cloud().)quality_vs_cost (see
rank_cloud().)provider (see
rank_cloud().)
- Returns:
The top-ranked entry, or None when no candidate matches
kind(andprovider, if given).- Return type:
Examples
>>> catalog = [{"id": "m", "provider": "p", "kind": "llm", ... "structured_output": True, "benchmarks": {"general": 80}, ... "input_per_1m": 1.0, "output_per_1m": 2.0}] >>> pick_cloud(catalog, "llm")["id"] 'm' >>> pick_cloud(catalog, "vlm") is None True
- best_engine_ai_helper.cloud_catalog.rank_cloud(catalog, kind, application=None, quality_vs_cost=0.7, provider=None)[source]
Rank paid catalog candidates by a quality/price trade-off.
Mirrors
score.rank()’s shape (structured-output capability first, then a combined score), so the local and cloud pickers read the same way. Each candidate getsscore(raw benchmark),price_per_1m(blended_price_per_1m()), andcombined— a 0..1 blend of min-max-normalized quality and (inverted) price across the candidate pool.- Parameters:
catalog (list[dict[str, Any]]) – Entries from
load_cloud_catalog().kind ({'llm', 'vlm'}) –
vlmkeeps only vision-capable entries;llmkeeps bothllmandvlmentries (a VLM answers text-only prompts too — same rule asscore.rank()).application (str or None) – Benchmark axis keyword (
"code","math","ocr","vision","chat","generalist"), forwarded toscore._benchmark_score().Noneuses the default kind-based rule (vision axis for a VLM, general for an LLM).quality_vs_cost (float) – 0..1 weight on quality vs. price; clamped into range.
1.0picks purely on benchmark score (price ignored);0.0picks purely on price (quality ignored, subject to the structured-output gate). Defaults toDEFAULT_QUALITY_VS_COST.provider (str or None) – Restrict candidates to one provider (e.g.
"openai"), case- insensitive.Noneranks across every provider in the catalog.
- Returns:
Candidates sorted best-first. Empty when nothing matches
kind(andprovider, if given).- Return type:
Examples
>>> catalog = [ ... {"id": "cheap", "provider": "p", "kind": "llm", "structured_output": True, ... "benchmarks": {"general": 70}, "input_per_1m": 0.1, "output_per_1m": 0.1}, ... {"id": "strong", "provider": "p", "kind": "llm", "structured_output": True, ... "benchmarks": {"general": 90}, "input_per_1m": 5.0, "output_per_1m": 15.0}, ... ] >>> rank_cloud(catalog, "llm", quality_vs_cost=1.0)[0]["id"] # quality only 'strong' >>> rank_cloud(catalog, "llm", quality_vs_cost=0.0)[0]["id"] # price only 'cheap'