mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-08 03:01:47 +00:00
Every provider profile is now a self-contained plugin under plugins/model-providers/<name>/, mirroring the plugins/platforms/ pattern established for IRC and Teams. The ProviderProfile ABC stays in providers/; the per-provider profile data moves out. - plugins/model-providers/<name>/__init__.py calls register_provider() - plugins/model-providers/<name>/plugin.yaml declares kind: model-provider - providers/__init__.py._discover_providers() lazily scans bundled plugins then $HERMES_HOME/plugins/model-providers/<name>/ (user override path) - User plugins with the same name override bundled ones (last-writer-wins in register_provider) - Legacy providers/<name>.py layout still supported for back-compat with out-of-tree editable installs - Hermes PluginManager: new kind=model-provider; skipped like memory plugins (providers/ discovery owns them); standalone plugins with register_provider+ProviderProfile in their __init__.py auto-coerce to this kind (same heuristic as memory providers) - skip_names extended to include 'model-providers' so the general PluginManager doesn't double-scan the category - 4 new tests in tests/providers/test_plugin_discovery.py covering bundled discovery, user override, and general-loader isolation - Docs updated: website/docs/developer-guide/adding-providers.md, provider-runtime.md, providers/README.md, plugins/model-providers/README.md No API break: auth.py / config.py / doctor.py / models.py / runtime_provider.py / model_metadata.py / auxiliary_client.py / chat_completions.py / run_agent.py all still consume providers via get_provider_profile() / list_providers() — they just now see plugin-discovered entries instead of pkgutil-iterated ones. Third parties can now drop a single directory into ~/.hermes/plugins/model-providers/<name>/ to add or override an inference provider without touching the repo.
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""Native Anthropic provider profile."""
|
|
|
|
import json
|
|
import logging
|
|
import urllib.request
|
|
|
|
from providers import register_provider
|
|
from providers.base import ProviderProfile
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class AnthropicProfile(ProviderProfile):
|
|
"""Native Anthropic — uses x-api-key header, not Bearer."""
|
|
|
|
def fetch_models(
|
|
self,
|
|
*,
|
|
api_key: str | None = None,
|
|
timeout: float = 8.0,
|
|
) -> list[str] | None:
|
|
"""Anthropic uses x-api-key header and anthropic-version."""
|
|
if not api_key:
|
|
return None
|
|
try:
|
|
req = urllib.request.Request("https://api.anthropic.com/v1/models")
|
|
req.add_header("x-api-key", api_key)
|
|
req.add_header("anthropic-version", "2023-06-01")
|
|
req.add_header("Accept", "application/json")
|
|
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
data = json.loads(resp.read().decode())
|
|
return [
|
|
m["id"]
|
|
for m in data.get("data", [])
|
|
if isinstance(m, dict) and "id" in m
|
|
]
|
|
except Exception as exc:
|
|
logger.debug("fetch_models(anthropic): %s", exc)
|
|
return None
|
|
|
|
|
|
anthropic = AnthropicProfile(
|
|
name="anthropic",
|
|
aliases=("claude", "claude-oauth", "claude-code"),
|
|
api_mode="anthropic_messages",
|
|
env_vars=("ANTHROPIC_API_KEY", "ANTHROPIC_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN"),
|
|
base_url="https://api.anthropic.com",
|
|
auth_type="api_key",
|
|
default_aux_model="claude-haiku-4-5-20251001",
|
|
)
|
|
|
|
register_provider(anthropic)
|