mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-30 06:25:34 +01:00
Keep free-best members big enough for a board turn
OmniRoute caps a combo's input at its smallest member: one 32k model (SEA-LION) made every 35k pi board turn fail 'Input exceeds context window'. A member's limit is now the smaller of order.tsv's and OmniRoute's registry (/v1/models), and the combo floor is 100k. Bug-class-check: combo trusted stale order.tsv limits; registry limit now read live, floor enforced (todoImplementer T2628) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7942f7ec57
commit
4a9c2e03e9
@ -112,6 +112,17 @@ class Admin:
|
|||||||
got = self._call("/api/providers")
|
got = self._call("/api/providers")
|
||||||
return list(got.get("connections", got) if isinstance(got, dict) else got)
|
return list(got.get("connections", got) if isinstance(got, dict) else got)
|
||||||
|
|
||||||
|
def contexts(self) -> dict[str, int]:
|
||||||
|
"""Return each model's input limit as OmniRoute's registry knows it."""
|
||||||
|
got = self._call("/v1/models")
|
||||||
|
rows = got.get("data", []) if isinstance(got, dict) else got
|
||||||
|
found: dict[str, int] = {}
|
||||||
|
for row in rows:
|
||||||
|
limit = row.get("max_input_tokens") or row.get("context_length")
|
||||||
|
if isinstance(limit, int) and not isinstance(limit, bool) and row.get("id"):
|
||||||
|
found[str(row["id"])] = limit
|
||||||
|
return found
|
||||||
|
|
||||||
def combo_members(self, name: str = COMBO) -> set[str]:
|
def combo_members(self, name: str = COMBO) -> set[str]:
|
||||||
"""Return provider ids the combo routes to (empty when it is missing)."""
|
"""Return provider ids the combo routes to (empty when it is missing)."""
|
||||||
got = self._call("/api/combos")
|
got = self._call("/api/combos")
|
||||||
|
|||||||
@ -12,6 +12,7 @@ set changes, so a reconnected provider comes back by itself.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
|
import math
|
||||||
import sys
|
import sys
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
@ -21,13 +22,17 @@ from omniroute_offload import _gw_health as health
|
|||||||
from omniroute_offload import _gw_notify as note
|
from omniroute_offload import _gw_notify as note
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable, Mapping
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from omniroute_offload._gw_config import Config
|
from omniroute_offload._gw_config import Config
|
||||||
|
|
||||||
MIN_PROMPT = 16_000
|
MIN_PROMPT = 16_000
|
||||||
MIN_TETRIS = 0.85
|
MIN_TETRIS = 0.85
|
||||||
|
# OmniRoute caps a combo's input at its smallest member's limit; a board turn sends
|
||||||
|
# 35k+ tokens and grows, so one 32k member failed every turn with "Input exceeds
|
||||||
|
# context window" (todoImplementer T2628).
|
||||||
|
MIN_CONTEXT = 100_000
|
||||||
# testStatus of a login that is gone: kuhy reconnects it
|
# testStatus of a login that is gone: kuhy reconnects it
|
||||||
DEAD = frozenset({"expired", "unauthorized"})
|
DEAD = frozenset({"expired", "unauthorized"})
|
||||||
|
|
||||||
@ -42,9 +47,17 @@ def dead_providers(conns: Iterable[dict[str, Any]]) -> set[str]:
|
|||||||
return {name for name, live in usable.items() if not live}
|
return {name for name, live in usable.items() if not live}
|
||||||
|
|
||||||
|
|
||||||
def ranked_models(order: Path, dead: Iterable[str] = ()) -> list[str]:
|
def ranked_models(
|
||||||
"""Return agent-capable models from order.tsv that pass the filters, best first."""
|
order: Path,
|
||||||
gone = set(dead)
|
dead: Iterable[str] = (),
|
||||||
|
contexts: Mapping[str, int] | None = None,
|
||||||
|
floor: int = MIN_PROMPT,
|
||||||
|
) -> list[str]:
|
||||||
|
"""Return agent-capable models from order.tsv that pass the filters, best first.
|
||||||
|
|
||||||
|
A model's input limit: the smaller of order.tsv's measured one and OmniRoute's.
|
||||||
|
"""
|
||||||
|
gone, known = set(dead), contexts or {}
|
||||||
with order.open(newline="") as handle:
|
with order.open(newline="") as handle:
|
||||||
rows = list(csv.DictReader(handle, delimiter="\t"))
|
rows = list(csv.DictReader(handle, delimiter="\t"))
|
||||||
return [
|
return [
|
||||||
@ -53,7 +66,8 @@ def ranked_models(order: Path, dead: Iterable[str] = ()) -> list[str]:
|
|||||||
if row.get("tools") == "yes"
|
if row.get("tools") == "yes"
|
||||||
and row.get("tetris", "-") != "-"
|
and row.get("tetris", "-") != "-"
|
||||||
and float(row["tetris"]) >= MIN_TETRIS
|
and float(row["tetris"]) >= MIN_TETRIS
|
||||||
and float(row.get("max_prompt") or 0) >= MIN_PROMPT
|
and min(float(row.get("max_prompt") or 0), known.get(row["model"], math.inf))
|
||||||
|
>= floor
|
||||||
and row["model"].split("/", 1)[0] not in gone
|
and row["model"].split("/", 1)[0] not in gone
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -73,11 +87,13 @@ def _ranked(cfg: Config) -> bool:
|
|||||||
def _wanted(cfg: Config, admin: api.Admin) -> tuple[list[str], set[str]] | None:
|
def _wanted(cfg: Config, admin: api.Admin) -> tuple[list[str], set[str]] | None:
|
||||||
"""Return the combo and the dead providers left out; None (logged) if all dead."""
|
"""Return the combo and the dead providers left out; None (logged) if all dead."""
|
||||||
dead = dead_providers(admin.providers())
|
dead = dead_providers(admin.providers())
|
||||||
models = ranked_models(cfg.conf_dir / "order.tsv", dead)
|
models = ranked_models(
|
||||||
|
cfg.conf_dir / "order.tsv", dead, admin.contexts(), MIN_CONTEXT
|
||||||
|
)
|
||||||
if not models:
|
if not models:
|
||||||
print(
|
print(
|
||||||
"combo kept: no ranked provider has a live login"
|
f"combo kept: no ranked model has a live login and {MIN_CONTEXT} input"
|
||||||
f" ({', '.join(sorted(dead))})",
|
f" tokens (dead: {', '.join(sorted(dead)) or 'none'})",
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|||||||
@ -109,6 +109,20 @@ def test_combo_models_lists_the_combo_in_priority_order(
|
|||||||
assert adm.combo_models() == []
|
assert adm.combo_models() == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_contexts_reads_each_models_input_limit(admin: tuple[api.Admin, Net]) -> None:
|
||||||
|
adm, net = admin
|
||||||
|
rows = [
|
||||||
|
{"id": "nv/a", "context_length": 128000},
|
||||||
|
{"id": "sea/b", "context_length": 128000, "max_input_tokens": 32768},
|
||||||
|
{"id": "x/none"},
|
||||||
|
{"id": "x/flag", "context_length": True},
|
||||||
|
{"context_length": 5},
|
||||||
|
]
|
||||||
|
net.replies = [{"data": rows}, []]
|
||||||
|
assert adm.contexts() == {"nv/a": 128000, "sea/b": 32768}
|
||||||
|
assert adm.contexts() == {}
|
||||||
|
|
||||||
|
|
||||||
def test_reactivate_puts_active(admin: tuple[api.Admin, Net]) -> None:
|
def test_reactivate_puts_active(admin: tuple[api.Admin, Net]) -> None:
|
||||||
adm, net = admin
|
adm, net = admin
|
||||||
net.replies = [{}]
|
net.replies = [{}]
|
||||||
|
|||||||
@ -41,6 +41,7 @@ def cfg(tmp_path: Path) -> gwc.Config:
|
|||||||
|
|
||||||
CONNS: list[dict[str, Any]] = []
|
CONNS: list[dict[str, Any]] = []
|
||||||
CURRENT: list[str] = []
|
CURRENT: list[str] = []
|
||||||
|
CONTEXTS: dict[str, int] = {}
|
||||||
|
|
||||||
|
|
||||||
class FakeAdmin:
|
class FakeAdmin:
|
||||||
@ -54,6 +55,9 @@ class FakeAdmin:
|
|||||||
def combo_models(self, name: str = api.COMBO) -> list[str]:
|
def combo_models(self, name: str = api.COMBO) -> list[str]:
|
||||||
return CURRENT
|
return CURRENT
|
||||||
|
|
||||||
|
def contexts(self) -> dict[str, int]:
|
||||||
|
return CONTEXTS
|
||||||
|
|
||||||
def upsert_combo(self, name: str, models: list[str]) -> None:
|
def upsert_combo(self, name: str, models: list[str]) -> None:
|
||||||
self.upserts.append((name, models))
|
self.upserts.append((name, models))
|
||||||
|
|
||||||
@ -63,6 +67,7 @@ def admins(monkeypatch: pytest.MonkeyPatch) -> list[FakeAdmin]:
|
|||||||
made: list[FakeAdmin] = []
|
made: list[FakeAdmin] = []
|
||||||
CONNS.clear()
|
CONNS.clear()
|
||||||
CURRENT.clear()
|
CURRENT.clear()
|
||||||
|
CONTEXTS.clear()
|
||||||
|
|
||||||
def factory(cfg: gwc.Config, password: str) -> FakeAdmin:
|
def factory(cfg: gwc.Config, password: str) -> FakeAdmin:
|
||||||
made.append(FakeAdmin(cfg, password))
|
made.append(FakeAdmin(cfg, password))
|
||||||
@ -101,7 +106,7 @@ def test_ranked_models_without_tetris_column_keeps_nothing(tmp_path: Path) -> No
|
|||||||
def test_refresh_upserts_filtered_combo(
|
def test_refresh_upserts_filtered_combo(
|
||||||
cfg: gwc.Config, admins: list[FakeAdmin], capsys: pytest.CaptureFixture[str]
|
cfg: gwc.Config, admins: list[FakeAdmin], capsys: pytest.CaptureFixture[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
_write(cfg, HEADER + "x/one\tyes\t0.9\t20000\nx/two\tno\t0.9\t20000\n")
|
_write(cfg, HEADER + "x/one\tyes\t0.9\t128000\nx/two\tno\t0.9\t128000\n")
|
||||||
assert combo.refresh(cfg) is True
|
assert combo.refresh(cfg) is True
|
||||||
assert admins[0].pw == "pw"
|
assert admins[0].pw == "pw"
|
||||||
assert admins[0].upserts == [(api.COMBO, ["x/one"])]
|
assert admins[0].upserts == [(api.COMBO, ["x/one"])]
|
||||||
@ -161,7 +166,7 @@ def test_refresh_leaves_out_a_provider_whose_login_expired(
|
|||||||
HEADER
|
HEADER
|
||||||
+ "nv/a\tyes\t1.0\t128000\n"
|
+ "nv/a\tyes\t1.0\t128000\n"
|
||||||
+ "kilo/auto\tyes\t1.0\t128000\n"
|
+ "kilo/auto\tyes\t1.0\t128000\n"
|
||||||
+ "or/b\tyes\t0.9\t64000\n",
|
+ "or/b\tyes\t0.9\t128000\n",
|
||||||
)
|
)
|
||||||
CONNS.extend([_conn("nv"), _conn("kilo", "expired"), _conn("or")])
|
CONNS.extend([_conn("nv"), _conn("kilo", "expired"), _conn("or")])
|
||||||
assert combo.refresh(cfg) is True
|
assert combo.refresh(cfg) is True
|
||||||
@ -235,3 +240,29 @@ def test_keep_live_survives_an_unreachable_api(
|
|||||||
monkeypatch.setattr(api, "Admin", refused)
|
monkeypatch.setattr(api, "Admin", refused)
|
||||||
assert combo.keep_live(cfg) is False
|
assert combo.keep_live(cfg) is False
|
||||||
assert "combo sync skipped: refused" in capsys.readouterr().err
|
assert "combo sync skipped: refused" in capsys.readouterr().err
|
||||||
|
|
||||||
|
|
||||||
|
def test_refresh_leaves_out_a_model_under_the_context_floor(
|
||||||
|
cfg: gwc.Config, admins: list[FakeAdmin], capsys: pytest.CaptureFixture[str]
|
||||||
|
) -> None:
|
||||||
|
"""OmniRoute caps a combo at its smallest member: a 32k one failed 35k turns."""
|
||||||
|
_write(
|
||||||
|
cfg,
|
||||||
|
HEADER
|
||||||
|
+ "nv/big\tyes\t1.0\t128000\n"
|
||||||
|
+ "sea/small\tyes\t0.9\t128000\n"
|
||||||
|
+ "groq/measured\tyes\t0.9\t16000\n"
|
||||||
|
+ "or/unknown\tyes\t0.9\t128000\n",
|
||||||
|
)
|
||||||
|
CONTEXTS.update({"nv/big": 128000, "sea/small": 32768, "groq/measured": 400000})
|
||||||
|
assert combo.refresh(cfg) is True
|
||||||
|
assert admins[0].upserts == [(api.COMBO, ["nv/big", "or/unknown"])]
|
||||||
|
|
||||||
|
|
||||||
|
def test_refresh_keeps_the_combo_when_no_model_is_big_enough(
|
||||||
|
cfg: gwc.Config, admins: list[FakeAdmin], capsys: pytest.CaptureFixture[str]
|
||||||
|
) -> None:
|
||||||
|
_write(cfg, HEADER + "sea/small\tyes\t0.9\t32000\n")
|
||||||
|
assert combo.refresh(cfg) is False
|
||||||
|
assert admins[0].upserts == []
|
||||||
|
assert "dead: none" in capsys.readouterr().err
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user