mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-08 13:12:08 +00:00
fix(providers): pass extra headers to model discovery
This commit is contained in:
parent
80a774f972
commit
ab40e952f3
5 changed files with 211 additions and 18 deletions
|
|
@ -23,7 +23,7 @@ from __future__ import annotations
|
|||
import logging
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from typing import List, NamedTuple, Optional
|
||||
from typing import Any, List, NamedTuple, Optional
|
||||
|
||||
from hermes_cli.providers import (
|
||||
ProviderDef,
|
||||
|
|
@ -1362,6 +1362,19 @@ import threading as _threading # noqa: E402
|
|||
_picker_prewarm_done = _threading.Event()
|
||||
|
||||
|
||||
def _extra_headers_from_config(entry: Any) -> dict[str, str]:
|
||||
if not isinstance(entry, dict):
|
||||
return {}
|
||||
headers = entry.get("extra_headers")
|
||||
if not isinstance(headers, dict) or not headers:
|
||||
return {}
|
||||
return {
|
||||
str(key): str(value)
|
||||
for key, value in headers.items()
|
||||
if value is not None
|
||||
}
|
||||
|
||||
|
||||
def prewarm_picker_cache_async() -> Optional["_threading.Thread"]:
|
||||
"""Warm the provider-models disk cache in a background daemon thread.
|
||||
|
||||
|
|
@ -1993,7 +2006,11 @@ def list_authenticated_providers(
|
|||
if should_probe:
|
||||
try:
|
||||
from hermes_cli.models import fetch_api_models
|
||||
live_models = fetch_api_models(api_key, api_url)
|
||||
live_models = fetch_api_models(
|
||||
api_key,
|
||||
api_url,
|
||||
headers=_extra_headers_from_config(ep_cfg) or None,
|
||||
)
|
||||
if live_models:
|
||||
models_list = live_models
|
||||
except Exception:
|
||||
|
|
@ -2130,10 +2147,13 @@ def list_authenticated_providers(
|
|||
"api_key": api_key,
|
||||
"models": [],
|
||||
"discover_models": discover,
|
||||
"extra_headers": _extra_headers_from_config(entry),
|
||||
}
|
||||
else:
|
||||
if api_key and not groups[group_key].get("api_key"):
|
||||
groups[group_key]["api_key"] = api_key
|
||||
if not groups[group_key].get("extra_headers"):
|
||||
groups[group_key]["extra_headers"] = _extra_headers_from_config(entry)
|
||||
# If any entry in this group opts out of discovery,
|
||||
# honour that for the whole grouped row.
|
||||
if not discover:
|
||||
|
|
@ -2240,7 +2260,11 @@ def list_authenticated_providers(
|
|||
try:
|
||||
from hermes_cli.models import fetch_api_models
|
||||
|
||||
live_models = fetch_api_models(api_key, api_url)
|
||||
live_models = fetch_api_models(
|
||||
api_key,
|
||||
api_url,
|
||||
headers=grp.get("extra_headers") or None,
|
||||
)
|
||||
if live_models:
|
||||
grp["models"] = live_models
|
||||
grp["total_models"] = len(live_models)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue