fix: limit OmniRoute free model probing
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-10-08 13:12:16 -06:00
parent 3963b33128
commit 74206d787e
2 changed files with 64 additions and 21 deletions

View File

@ -29,9 +29,14 @@ Secrets:
- Jeannie also generates persistent local-only OmniRoute management secrets in - Jeannie also generates persistent local-only OmniRoute management secrets in
that env file, logs in against `127.0.0.1`, and creates provider connections that env file, logs in against `127.0.0.1`, and creates provider connections
through OmniRoute's management API. Secret values are never printed. through OmniRoute's management API. Secret values are never printed.
- Jeannie discovers currently free OpenRouter models and NVIDIA catalog models, - Jeannie builds `agent-fast-free` and `agent-smart-free` OmniRoute combos from
creates `agent-fast-free` and `agent-smart-free` OmniRoute combos, and writes a small curated OpenRouter free-model candidate list, validates candidates
`/data/homelab-ai-stack/models.env` for smoke tests and local tools. with real chat-completion calls, and writes `/data/homelab-ai-stack/models.env`
for smoke tests and local tools. Override the candidate list with
`LAB_AI_STACK_OPENROUTER_MODELS`. NVIDIA catalog models are not used in
Holmes/agent combos by default because catalog discovery can include models
that are not chat-completion compatible; opt in with
`LAB_AI_STACK_NVIDIA_MODELS` or `LAB_AI_STACK_ENABLE_NVIDIA_DISCOVERY=true`.
- `deploy-ai-tools` writes `/data/homelab-ai-stack/ai-tools.env` and creates - `deploy-ai-tools` writes `/data/homelab-ai-stack/ai-tools.env` and creates
`jeannie-goose`, `jeannie-holmes`, and `jeannie-hermes` wrappers in `jeannie-goose`, `jeannie-holmes`, and `jeannie-hermes` wrappers in
`~/.local/bin` so each tool uses the local OmniRoute endpoint and generated `~/.local/bin` so each tool uses the local OmniRoute endpoint and generated

View File

@ -11,9 +11,12 @@ OPENROUTER_URL="${LAB_AI_STACK_OPENROUTER_URL:-https://openrouter.ai/api/v1}"
NVIDIA_URL="${LAB_AI_STACK_NVIDIA_URL:-https://integrate.api.nvidia.com/v1}" NVIDIA_URL="${LAB_AI_STACK_NVIDIA_URL:-https://integrate.api.nvidia.com/v1}"
MODEL_ROUTES_FILE="${LAB_AI_STACK_MODEL_ROUTES_FILE:-${INSTALL_DIR}/models.env}" MODEL_ROUTES_FILE="${LAB_AI_STACK_MODEL_ROUTES_FILE:-${INSTALL_DIR}/models.env}"
OMNIROUTE_BOOTSTRAP_TMP_DIR="" OMNIROUTE_BOOTSTRAP_TMP_DIR=""
OMNIROUTE_MODEL_VALIDATE_ATTEMPTS="${LAB_AI_STACK_MODEL_VALIDATE_ATTEMPTS:-24}" OMNIROUTE_MODEL_VALIDATE_ATTEMPTS="${LAB_AI_STACK_MODEL_VALIDATE_ATTEMPTS:-4}"
OMNIROUTE_FAST_MODEL_TARGET="${LAB_AI_STACK_FAST_MODEL_TARGET:-4}" OMNIROUTE_FAST_MODEL_TARGET="${LAB_AI_STACK_FAST_MODEL_TARGET:-1}"
OMNIROUTE_SMART_MODEL_TARGET="${LAB_AI_STACK_SMART_MODEL_TARGET:-6}" OMNIROUTE_SMART_MODEL_TARGET="${LAB_AI_STACK_SMART_MODEL_TARGET:-2}"
OMNIROUTE_OPENROUTER_MODELS="${LAB_AI_STACK_OPENROUTER_MODELS:-openrouter/apodex/apodex-1.1-mini:free,openrouter/cohere/north-mini-code:free,openrouter/google/gemma-4-26b-a4b-it:free,openrouter/google/gemma-4-31b-it:free}"
OMNIROUTE_NVIDIA_MODELS="${LAB_AI_STACK_NVIDIA_MODELS:-}"
OMNIROUTE_ENABLE_NVIDIA_DISCOVERY="${LAB_AI_STACK_ENABLE_NVIDIA_DISCOVERY:-false}"
if [[ ! -s "${ENV_FILE}" ]]; then if [[ ! -s "${ENV_FILE}" ]]; then
echo "Missing ${ENV_FILE}; run seed-secrets.sh first." >&2 echo "Missing ${ENV_FILE}; run seed-secrets.sh first." >&2
@ -242,7 +245,14 @@ discover_model_routes() {
local nvidia_key="$2" local nvidia_key="$2"
local output_json="$3" local output_json="$3"
OPENROUTER_KEY="${openrouter_key}" NVIDIA_KEY="${nvidia_key}" OPENROUTER_URL="${OPENROUTER_URL}" NVIDIA_URL="${NVIDIA_URL}" python3 - "${output_json}" <<'PY' OPENROUTER_KEY="${openrouter_key}" \
NVIDIA_KEY="${nvidia_key}" \
OPENROUTER_URL="${OPENROUTER_URL}" \
NVIDIA_URL="${NVIDIA_URL}" \
OPENROUTER_MODELS="${OMNIROUTE_OPENROUTER_MODELS}" \
NVIDIA_MODELS="${OMNIROUTE_NVIDIA_MODELS}" \
ENABLE_NVIDIA_DISCOVERY="${OMNIROUTE_ENABLE_NVIDIA_DISCOVERY}" \
python3 - "${output_json}" <<'PY'
import json import json
import os import os
import sys import sys
@ -254,6 +264,23 @@ openrouter_key = os.environ.get("OPENROUTER_KEY", "")
nvidia_key = os.environ.get("NVIDIA_KEY", "") nvidia_key = os.environ.get("NVIDIA_KEY", "")
openrouter_url = os.environ["OPENROUTER_URL"].rstrip("/") openrouter_url = os.environ["OPENROUTER_URL"].rstrip("/")
nvidia_url = os.environ["NVIDIA_URL"].rstrip("/") nvidia_url = os.environ["NVIDIA_URL"].rstrip("/")
preferred_openrouter = os.environ.get("OPENROUTER_MODELS", "")
preferred_nvidia = os.environ.get("NVIDIA_MODELS", "")
enable_nvidia_discovery = os.environ.get("ENABLE_NVIDIA_DISCOVERY", "").lower() in ("1", "true", "yes", "on")
def csv_models(value):
return [item.strip() for item in value.split(",") if item.strip()]
def unique(values):
seen = set()
result = []
for value in values:
if value and value not in seen:
seen.add(value)
result.append(value)
return result
def fetch_json(url, token=""): def fetch_json(url, token=""):
@ -278,12 +305,15 @@ def as_float(value):
def priority(model): def priority(model):
lower = model.lower() lower = model.lower()
scores = [ scores = [
("qwen", 0), ("apodex", 0),
("llama-3.1-8b", 1), ("north-mini-code", 1),
("llama-3", 2), ("gemma-4", 2),
("mistral", 3), ("gemma", 3),
("gemma", 4), ("llama-3.1-8b", 4),
("deepseek", 5), ("llama-3", 5),
("mistral", 6),
("deepseek", 7),
("qwen", 90),
] ]
for needle, score in scores: for needle, score in scores:
if needle in lower: if needle in lower:
@ -292,6 +322,7 @@ def priority(model):
openrouter_models = [] openrouter_models = []
openrouter_discovered = []
if openrouter_key: if openrouter_key:
for item in fetch_json(f"{openrouter_url}/models", openrouter_key).get("data", []) or []: for item in fetch_json(f"{openrouter_url}/models", openrouter_key).get("data", []) or []:
model_id = item.get("id") model_id = item.get("id")
@ -302,21 +333,28 @@ if openrouter_key:
completion = as_float(pricing.get("completion")) completion = as_float(pricing.get("completion"))
zero_priced = prompt == 0.0 and completion == 0.0 zero_priced = prompt == 0.0 and completion == 0.0
if model_id.endswith(":free") or zero_priced: if model_id.endswith(":free") or zero_priced:
openrouter_models.append(f"openrouter/{model_id}") openrouter_discovered.append(f"openrouter/{model_id}")
openrouter_models = sorted(set(openrouter_models), key=lambda value: (priority(value), value)) preferred_openrouter_models = csv_models(preferred_openrouter)
openrouter_models = unique(
preferred_openrouter_models
+ sorted(set(openrouter_discovered), key=lambda value: (priority(value), value))
)
nvidia_models = [] nvidia_discovered = []
if nvidia_key: if nvidia_key and enable_nvidia_discovery:
for item in fetch_json(f"{nvidia_url}/models", nvidia_key).get("data", []) or []: for item in fetch_json(f"{nvidia_url}/models", nvidia_key).get("data", []) or []:
model_id = item.get("id") model_id = item.get("id")
if isinstance(model_id, str) and model_id: if isinstance(model_id, str) and model_id:
nvidia_models.append(model_id if model_id.startswith("nvidia/") else f"nvidia/{model_id}") nvidia_discovered.append(model_id if model_id.startswith("nvidia/") else f"nvidia/{model_id}")
nvidia_models = sorted(set(nvidia_models), key=lambda value: (priority(value), value)) nvidia_models = unique(
csv_models(preferred_nvidia)
+ sorted(set(nvidia_discovered), key=lambda value: (priority(value), value))
)
fast = (openrouter_models[:4] + nvidia_models[:2])[:6] fast = openrouter_models[:4] + nvidia_models[:1]
smart = (nvidia_models[:4] + openrouter_models[:4])[:8] smart = openrouter_models[:4] + nvidia_models[:2]
with open(output_path, "w", encoding="utf-8") as fh: with open(output_path, "w", encoding="utf-8") as fh:
json.dump({ json.dump({