diff --git a/surfsense_backend/app/config/__init__.py b/surfsense_backend/app/config/__init__.py index 1ff41bad2..d690c1d7d 100644 --- a/surfsense_backend/app/config/__init__.py +++ b/surfsense_backend/app/config/__init__.py @@ -434,7 +434,10 @@ def initialize_llm_router(): router_settings = config.ROUTER_SETTINGS if not all_configs: - print("Info: No global LLM configs found, Auto mode will not be available") + print( + "Info: No global LLM configs found; global Auto pool is unavailable. " + "Auto can still use enabled BYOK models." + ) return try: diff --git a/surfsense_backend/app/routes/model_connections_routes.py b/surfsense_backend/app/routes/model_connections_routes.py index 6db9aa9f3..1fd2e1e8e 100644 --- a/surfsense_backend/app/routes/model_connections_routes.py +++ b/surfsense_backend/app/routes/model_connections_routes.py @@ -105,6 +105,15 @@ def _apply_model_facts(model: Model, facts: dict) -> None: model.supports_image_generation = facts.get("supports_image_generation") +def _complete_selection_facts(conn: Connection, selection: ModelSelection) -> dict: + facts = selection.model_dump() + derived = derive_capabilities(conn, selection.model_id.strip(), selection.metadata) + for key, value in derived.items(): + if facts.get(key) is None: + facts[key] = value + return facts + + def _selection_to_model(conn: Connection, selection: ModelSelection) -> Model: source = ( selection.source @@ -120,7 +129,7 @@ def _selection_to_model(conn: Connection, selection: ModelSelection) -> Model: enabled=selection.enabled, catalog=selection.metadata, ) - _apply_model_facts(model, selection.model_dump()) + _apply_model_facts(model, _complete_selection_facts(conn, selection)) return model diff --git a/surfsense_backend/app/services/auto_model_pin_service.py b/surfsense_backend/app/services/auto_model_pin_service.py index a5122bcac..b4f1bafc9 100644 --- a/surfsense_backend/app/services/auto_model_pin_service.py +++ b/surfsense_backend/app/services/auto_model_pin_service.py @@ -541,12 +541,13 @@ async def resolve_or_get_pinned_llm_config_id( premium_eligible = ( False if force_repin_free else await _is_premium_eligible(session, user_id) ) + byok_candidates = [c for c in candidates if _tier_of(c) == "byok"] if premium_eligible: premium_candidates = [c for c in candidates if _tier_of(c) == "premium"] preferred_premium = [ c for c in premium_candidates if _is_preferred_premium_auto_config(c) ] - eligible = preferred_premium or premium_candidates + eligible = preferred_premium or premium_candidates or byok_candidates else: eligible = [c for c in candidates if _tier_of(c) != "premium"]