new tasks, model pricing, auto quantisation, etc...
This commit is contained in:
@@ -46,6 +46,24 @@ from .gossip import NodeGossip
|
||||
from .raft import RaftNode
|
||||
|
||||
|
||||
def _preset_price_keys(name: str, preset: dict) -> set[str]:
|
||||
"""All model strings a client may bill under for one preset.
|
||||
|
||||
``BillingLedger.price_for`` is keyed by the raw ``model`` string in the
|
||||
request, so the preset price must be registered under the preset name,
|
||||
its ``hf_repo``, and every alias — otherwise ``unsloth/Qwen…`` style
|
||||
requests silently fall back to the default rate.
|
||||
"""
|
||||
keys = {name}
|
||||
hf_repo = preset.get("hf_repo")
|
||||
if isinstance(hf_repo, str) and hf_repo:
|
||||
keys.add(hf_repo)
|
||||
for alias in preset.get("aliases") or []:
|
||||
if isinstance(alias, str) and alias:
|
||||
keys.add(alias)
|
||||
return keys
|
||||
|
||||
|
||||
def derive_relay_url_from_public_tracker_url(url: str | None) -> str | None:
|
||||
"""Return wss://host/ws when url is a public HTTPS tracker origin."""
|
||||
if not url:
|
||||
@@ -4065,9 +4083,10 @@ class TrackerServer:
|
||||
db_path = DEFAULT_BILLING_DB_PATH
|
||||
if db_path:
|
||||
preset_prices = {
|
||||
name: float(preset["price_per_1k_tokens"])
|
||||
key: float(preset["price_per_1k_tokens"])
|
||||
for name, preset in self._model_presets.items()
|
||||
if isinstance(preset, dict) and "price_per_1k_tokens" in preset
|
||||
for key in _preset_price_keys(name, preset)
|
||||
}
|
||||
billing = BillingLedger(db_path=db_path, prices=preset_prices)
|
||||
self._billing: BillingLedger | None = billing
|
||||
@@ -4332,7 +4351,8 @@ class TrackerServer:
|
||||
continue
|
||||
if result is None:
|
||||
continue
|
||||
billing.set_price(name, result["new_price_per_1k"])
|
||||
for key in _preset_price_keys(name, preset):
|
||||
billing.set_price(key, result["new_price_per_1k"])
|
||||
preset["hf_last_price_per_1k"] = result["new_price_per_1k"]
|
||||
preset["hf_last_updated"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
|
||||
if self._hf_pricing_log is not None:
|
||||
|
||||
Reference in New Issue
Block a user