mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
Cycle 2 PR 1 (#14418). Introduces providers/ package with ProviderProfile ABC and auto-discovery registry, then wires ChatCompletionsTransport to delegate to profiles via a clean single-path method. Provider profiles (8 providers): - nvidia: default_max_tokens=16384 - kimi + kimi-cn: OMIT_TEMPERATURE, thinking + top-level reasoning_effort - openrouter: provider_preferences, full reasoning_config passthrough - nous: product tags, reasoning with Nous-specific disabled omission - deepseek: base_url + env_vars - qwen-oauth: vl_high_resolution extra_body, metadata top-level api_kwargs Transport integration: - _build_kwargs_from_profile() replaces the entire legacy flag-based assembly when provider_profile param is passed - Single path: no dual-execution, no overwrites, no legacy fallthrough - build_api_kwargs_extras() returns (extra_body, top_level) tuple to handle Kimi's top-level reasoning_effort vs OpenRouter's extra_body Auth types: api_key | oauth_device_code | oauth_external | copilot | aws (expanded from the lossy 'oauth' to match real Hermes auth modes). 64 new tests: - 30 profile unit tests (registry, all 8 profiles, auth types) - 19 transport parity tests (pin legacy flag-based behavior) - 15 profile wiring tests (verify profile path = legacy path)
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""Provider module registry.
|
|
|
|
Auto-discovers ProviderProfile instances from providers/*.py modules.
|
|
Each module should define a module-level PROVIDER or PROVIDERS list.
|
|
|
|
Usage:
|
|
from providers import get_provider_profile
|
|
profile = get_provider_profile("nvidia") # returns ProviderProfile or None
|
|
profile = get_provider_profile("kimi") # checks name + aliases
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Dict, Optional
|
|
|
|
from providers.base import ProviderProfile, OMIT_TEMPERATURE # noqa: F401
|
|
|
|
_REGISTRY: Dict[str, ProviderProfile] = {}
|
|
_ALIASES: Dict[str, str] = {}
|
|
_discovered = False
|
|
|
|
|
|
def register_provider(profile: ProviderProfile) -> None:
|
|
"""Register a provider profile by name and aliases."""
|
|
_REGISTRY[profile.name] = profile
|
|
for alias in profile.aliases:
|
|
_ALIASES[alias] = profile.name
|
|
|
|
|
|
def get_provider_profile(name: str) -> Optional[ProviderProfile]:
|
|
"""Look up a provider profile by name or alias.
|
|
|
|
Returns None if the provider has no profile (falls back to generic).
|
|
"""
|
|
if not _discovered:
|
|
_discover_providers()
|
|
canonical = _ALIASES.get(name, name)
|
|
return _REGISTRY.get(canonical)
|
|
|
|
|
|
def _discover_providers() -> None:
|
|
"""Import all provider modules to trigger registration."""
|
|
global _discovered
|
|
if _discovered:
|
|
return
|
|
_discovered = True
|
|
|
|
import importlib
|
|
import pkgutil
|
|
import providers as _pkg
|
|
|
|
for _importer, modname, _ispkg in pkgutil.iter_modules(_pkg.__path__):
|
|
if modname.startswith("_") or modname == "base":
|
|
continue
|
|
try:
|
|
importlib.import_module(f"providers.{modname}")
|
|
except ImportError as e:
|
|
import logging
|
|
logging.getLogger(__name__).warning(
|
|
"Failed to import provider module %s: %s", modname, e
|
|
)
|