MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / _normalized_costs

Function _normalized_costs

uncommon_route/router/selector.py:1057–1077  ·  view source on GitHub ↗

Log-scale cost normalization. Uses log(1 + cost) to prevent free models from having an absolute cost advantage. The gap between $0 and $0.30 is compressed vs linear.

(
    models: list[str],
    pricing: dict[str, ModelPricing],
)

Source from the content-addressed store, hash-verified

1055
1056
1057def _normalized_costs(
1058 models: list[str],
1059 pricing: dict[str, ModelPricing],
1060) -> dict[str, float]:
1061 """Log-scale cost normalization.
1062
1063 Uses log(1 + cost) to prevent free models from having an absolute
1064 cost advantage. The gap between $0 and $0.30 is compressed vs linear.
1065 """
1066 raw = {}
1067 for m in models:
1068 mp = _pricing_for_model(m, pricing)
1069 raw[m] = math.log1p(mp.input_price + mp.output_price)
1070 if not raw:
1071 return {}
1072 lo = min(raw.values())
1073 hi = max(raw.values())
1074 span = hi - lo
1075 if span <= 0:
1076 return {m: 0.5 for m in models}
1077 return {m: (raw[m] - lo) / span for m in models}
1078
1079
1080def _pressure_rescue_note(

Callers

nothing calls this directly

Calls 1

_pricing_for_modelFunction · 0.85

Tested by

no test coverage detected