auxiliary_local_runtime.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """Managed llama.cpp endpoint for auxiliary and fallback client resolution.
  2. A bare ``llamacpp`` / ``llama.cpp`` / ``llama-cpp`` alias (no base_url, no configured provider of
  3. that name) means "the local server Hermes manages for this profile" — exactly what the main ladder
  4. resolves in ``hermes_cli.runtime_provider_custom._resolve_llamacpp_runtime``. With no server
  5. running the answer is "unavailable", never the generic custom/API-key discovery: that handed the
  6. local model slug to whatever cloud provider held a key (#119227) or to the primary's own endpoint.
  7. """
  8. from __future__ import annotations
  9. from typing import Any, Optional, Tuple
  10. from hermes_cli.local_runtime.endpoint import LLAMACPP_ALIASES
  11. def bare_llamacpp_endpoint(provider: Optional[str], base_url: Optional[str],
  12. api_key: Any) -> Optional[tuple[str, Any]]:
  13. """``(base_url, api_key)`` of the profile's local llama.cpp server for a bare alias.
  14. ``base_url`` is ``""`` when nothing is serving. ``None`` when the request is not a bare alias:
  15. an explicit base_url or a configured provider entry under the alias name resolves as before.
  16. Read on every call so a restarted server's new port/key is picked up.
  17. """
  18. alias = (provider or "").strip().lower()
  19. if alias not in LLAMACPP_ALIASES or base_url:
  20. return None
  21. from hermes_cli.config import load_config
  22. from hermes_cli.local_runtime.endpoint import resolve_llamacpp_endpoint
  23. from hermes_cli.runtime_provider import _get_named_custom_provider
  24. if _get_named_custom_provider(alias):
  25. return None
  26. endpoint = resolve_llamacpp_endpoint(config=load_config()) or {}
  27. return (str(endpoint.get("base_url") or "").strip(),
  28. api_key or endpoint.get("api_key") or "no-key-required")