utils/omniroute_offload/omniroute_offload/_gw_combo.py
Krzysztof kuhy Rudnicki 7af6afe51a
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file length / file-length (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
omniroute_offload pre-commit / pre-commit (push) Has been cancelled
palette drift / palette (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
shared gate tests / gate unit tests (push) Has been cancelled
omniroute_offload: always-on gateway ops
omniroute-gateway start|health|update|backup|combo keeps the local
OmniRoute gateway up. systemd --user timers: health every 10 min
(real free-best chat; restart <=1/30 min, reactivate providers whose
cooldown ended, notify once per outage), update weekly Sun 12:00
(backup, newest stable -web tag, rollback of image + volume on a
failed health check).

Failure modes: health/update fail loudly (exit 1 + desktop + Signal);
all providers cooling = degraded (exit 0, one notice/day); a missing
signal-bot .env logs and exits non-zero on alert paths; health skips
while update holds the lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZSdJmNjGUvLnHJ4WG
2026-11-05 13:37:35 +01:00

53 lines
1.6 KiB
Python

"""Rebuild the free-best combo from the benchmark's order.tsv in conf_dir.
Keeps tool-capable models with a big enough prompt window and Tetris score, in
the file's rank order (the combo is a priority chain).
"""
from __future__ import annotations
import csv
import sys
from typing import TYPE_CHECKING
from omniroute_offload import _gw_api as api
from omniroute_offload import _gw_health as health
if TYPE_CHECKING:
from pathlib import Path
from omniroute_offload._gw_config import Config
MIN_PROMPT = 16_000
MIN_TETRIS = 0.85
def ranked_models(order: Path) -> list[str]:
"""Return agent-capable models from order.tsv that pass the filters, best first."""
with order.open(newline="") as handle:
rows = list(csv.DictReader(handle, delimiter="\t"))
return [
row["model"]
for row in rows
if row.get("tools") == "yes"
and row.get("tetris", "-") != "-"
and float(row["tetris"]) >= MIN_TETRIS
and float(row.get("max_prompt") or 0) >= MIN_PROMPT
]
def refresh(cfg: Config) -> bool:
"""Upsert the combo; log and return False when order.tsv is missing or empty."""
order = cfg.conf_dir / "order.tsv"
if not order.exists():
print(f"combo kept: no {order}", file=sys.stderr)
return False
models = ranked_models(order)
if not models:
print(f"combo kept: no model in {order} passes the filter", file=sys.stderr)
return False
admin = api.Admin(cfg, health.secret(cfg, "admin_password"))
admin.upsert_combo(api.COMBO, models)
print(f"{api.COMBO}: {' > '.join(models)}", file=sys.stderr)
return True