model_setup.py 1.2 KB

12345678910111213141516171819202122232425
  1. """Public helpers for a provider plugin's own ``hermes model`` step (``ProviderProfile.model_setup_flow``).
  2. Documented in website/docs/developer-guide/model-provider-plugin.md: these are the contract a plugin
  3. flow calls instead of re-implementing core's config rules.
  4. """
  5. from __future__ import annotations
  6. def persist_model_selection(model: str, provider: str, *, base_url: str | None = None,
  7. api_mode: str | None = None) -> dict:
  8. """Save *model* on *provider* as the default: writes the ``model:`` section (``provider``, then
  9. ``base_url`` and ``api_mode`` when given), scrubs inline endpoint credentials from it, saves
  10. config.yaml and deactivates the previously active OAuth provider. Returns the saved section."""
  11. from hermes_cli.model_setup_flows_common import _persist_model
  12. return _persist_model(model, provider, base_url=base_url, api_mode=api_mode)
  13. def note_setup_failure(failure_class: str) -> None:
  14. """Record why the flow ends without a pick (``"auth"``, ``"no_models"``, ...) for the opt-in
  15. provider-setup metric; a no-op outside a tracked ``hermes model`` / setup flow."""
  16. from hermes_cli.model_setup_flows_common import _note_setup_failure
  17. _note_setup_failure(failure_class)