Files
hermes-agent/plugins/model-providers/fireworks/__init__.py
Teknium d509ab10d7 fix(providers): lazy provider headers stay a real dict for plugin overrides
Review finding (P2, #144640): LazyHeaders was a read-only Mapping, so a
user provider override doing get_provider_profile('gmi').default_headers.copy()
(or |, update, json.dumps, ==) raised AttributeError and the provider
disappeared, in-process and under plugins.isolation: host.

LazyHeaders is now a dict subclass that stores every key up front and
resolves callable values (the release-carrying User-Agent) on first value
read. Every value-reading/mutating method resolves first; __iter__ is
overridden so dict(x)/{**x}/f(**x) leave CPython's raw-storage fast path;
json.dumps takes items() because the stored keys make it non-empty.
.copy()/|/copy/pickle yield plain resolved dicts. Importing provider plugins
still runs no git. The plugin-host Mapping materialization is gone: encode()
reads a dict subclass through items(), which resolves.
2026-10-25 17:50:59 -07:00

50 lines
2.2 KiB
Python

"""Fireworks AI provider profile. Models are addressed by full catalog ID
(``accounts/fireworks/models/<slug>``), tracking fw-ai/fireconnect ``setup-cli``."""
from typing import Any
from hermes_cli.version_info import hermes_user_agent
from providers import register_provider
from providers.base import LazyHeaders, ProviderProfile
class FireworksProfile(ProviderProfile):
"""Map Hermes reasoning controls onto Fireworks' OpenAI-compatible wire."""
def build_api_kwargs_extras(
self, *, reasoning_config: dict | None = None, **context: Any
) -> tuple[dict[str, Any], dict[str, Any]]:
# Fireworks rejects the nested ``extra_body.reasoning`` fallback some OpenAI-compatible
# gateways accept (#109774); its documented control is top-level ``reasoning_effort``
# (``none`` disables thinking). Overriding here marks the profile reasoning-aware, so the
# transport never sends the generic fallback on this route.
if not isinstance(reasoning_config, dict):
return {}, {}
if reasoning_config.get("enabled") is False:
return {}, {"reasoning_effort": "none"}
effort = reasoning_config.get("effort")
return {}, ({"reasoning_effort": effort} if effort else {})
fireworks = FireworksProfile(
name="fireworks", aliases=("fireworks-ai", "fw"), display_name="Fireworks AI",
description="Fireworks AI — OpenAI-compatible direct model API",
signup_url="https://app.fireworks.ai/settings/users/api-keys", env_vars=("FIREWORKS_API_KEY",),
base_url="https://api.fireworks.ai/inference/v1", auth_type="api_key",
# Attribution headers (canonical Hermes set); via default_headers so they
# survive switch_model and credential rotation.
default_headers=LazyHeaders({
"HTTP-Referer": "https://hermes-agent.nousresearch.com",
"X-Title": "Hermes Agent",
"User-Agent": lambda: hermes_user_agent("HermesAgent"),
}),
default_aux_model="accounts/fireworks/models/glm-5p2",
# Picker safety net when the live catalog fetch fails.
fallback_models=(
"accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/glm-5p2",
"accounts/fireworks/models/kimi-k2p7-code",
),
)
register_provider(fireworks)