feat: add detect_byok() public utility to cloud_session, bump v0.16.1
Some checks failed
CI / test (push) Waiting to run
Mirror / mirror (push) Has been cancelled
Release — PyPI / release (push) Has been cancelled

Extracted from kiwi/avocet where it was duplicated. Reads llm.yaml via
the same path LLMRouter uses — products can now import detect_byok from
cf-core instead of maintaining their own copy.
This commit is contained in:
pyr0ball 2026-04-25 16:01:05 -07:00
parent b52c578911
commit b21d6acc8e
2 changed files with 27 additions and 1 deletions

View file

@ -1,4 +1,4 @@
__version__ = "0.16.0"
__version__ = "0.16.1"
try:
from circuitforge_core.community import CommunityDB, CommunityPost, SharedStore

View file

@ -312,3 +312,29 @@ class CloudSessionFactory:
return session
return _check
# ── BYOK detection ────────────────────────────────────────────────────────────
def detect_byok(config_path: Path | None = None) -> bool:
"""Return True if at least one enabled non-vision LLM backend is configured.
Reads the shared llm.yaml that LLMRouter uses. Local (Ollama, vLLM) and
API-key backends both count the policy is "user is supplying compute",
regardless of where that compute lives.
Args:
config_path: Override the default config location. Useful in tests.
"""
import yaml
if config_path is None:
config_path = Path.home() / ".config" / "circuitforge" / "llm.yaml"
try:
with open(config_path) as f:
cfg = yaml.safe_load(f) or {}
return any(
b.get("enabled", True) and b.get("type") != "vision_service"
for b in cfg.get("backends", {}).values()
)
except Exception:
return False