Files
hermes-agent/plugins/model-providers/actual/__init__.py
T
teknium1 f678ed8299 refactor(model-providers): thinking-toggle XOR effort translation lives in agent.reasoning_effort; opencode-free imports it instead of borrowing via sys.modules
Four chat_completions profiles (kimi-coding, deepseek, opencode-go's Kimi K2 and DeepSeek branches, actual) each hand-rolled the same extra_body.thinking / top-level reasoning_effort translation, and the copies had already drifted in small ways (kimi's `.get("enabled", True)`, deepseek's separate effort parsing). agent.reasoning_effort.thinking_toggle_extras is now the single implementation: the Moonshot default emits effort XOR toggle (both is an HTTP 400), and always_emit_toggle=True covers DeepSeek's contract where the toggle must ride on every request to dodge the reasoning_content echo trap. actual keeps its two contract-specific lines (reasoning_config None -> nothing; effort "none" -> disabled toggle plus reasoning_effort="none", which the relay accepts as a real level) and delegates the rest. ox_alpha_reasoning_extras moves alongside so opencode-free imports it like any other helper instead of reaching into the zen plugin's module through sys.modules and swallowing every exception into ({}, {}) - a failure there previously silently dropped the user's effort setting. No wire behavior changes; tests/plugins/model_providers/test_thinking_toggle_parity.py pins the XOR invariant across the matrix and zen/free parity.
2026-09-13 05:19:48 -07:00

93 lines
3.3 KiB
Python

"""Actual Computer provider profile."""
import os
import sys
from typing import Any
from urllib.parse import urlparse
from providers import register_provider
from providers.base import ProviderProfile
DEFAULT_ACTUAL_BASE_URL = "https://api.actual.inc/v1"
class ActualProfile(ProviderProfile):
"""Actual Computer: hosted at api.actual.inc; local (offline-mode client)
inference opted into via model.base_url in config.yaml."""
def build_client_kwargs_extras(self, **context: Any) -> dict[str, Any]:
base_url = str(context.get("base_url") or self.base_url or "")
try:
hostname = (urlparse(base_url).hostname or "").lower().rstrip(".")
except ValueError:
return {}
if sys.platform != "darwin" or hostname != "api.actual.inc":
return {}
if any(
os.getenv(key)
for key in (
"HERMES_CA_BUNDLE",
"SSL_CERT_FILE",
"REQUESTS_CA_BUNDLE",
"CURL_CA_BUNDLE",
)
):
return {}
import certifi
return {"ssl_ca_cert": certifi.where()}
def supported_reasoning_efforts(self, model: str | None) -> tuple[str, ...] | None:
from agent.reasoning_effort import ACTUAL_RELAY_EFFORTS
return ACTUAL_RELAY_EFFORTS
def build_api_kwargs_extras(
self, *, reasoning_config: dict | None = None, **context: Any
) -> tuple[dict[str, Any], dict[str, Any]]:
if not isinstance(reasoning_config, dict):
return {}, {}
from agent.reasoning_effort import thinking_toggle_extras
# The relay accepts ``none`` as a real effort level: it switches thinking off AND
# is echoed as reasoning_effort, unlike the Moonshot/DeepSeek wires.
effort_none = str(reasoning_config.get("effort") or "").strip().lower() == "none"
if reasoning_config.get("enabled") is not False and effort_none:
return {"thinking": {"type": "disabled"}}, {"reasoning_effort": "none"}
supported = self.supported_reasoning_efforts(context.get("model")) or ()
return thinking_toggle_extras(reasoning_config, supported, always_emit_toggle=True)
def fetch_models(
self,
*,
api_key: str | None = None,
base_url: str | None = None,
timeout: float = 8.0,
) -> list[str] | None:
"""Use the selected route, then config.yaml, then the legacy environment override."""
from hermes_cli.auth import (
normalize_actual_base_url,
resolve_api_key_provider_credentials,
)
base_url = normalize_actual_base_url(
base_url or resolve_api_key_provider_credentials("actual")["base_url"]
)
return super().fetch_models(api_key=api_key, base_url=base_url, timeout=timeout)
actual = ActualProfile(
name="actual",
aliases=("actual-computer", "actualcomputer", "aci"),
display_name="Actual Computer",
description="Actual Computer - hosted inference via api.actual.inc, or local "
"offline inference via model.base_url in config.yaml",
signup_url="https://actual.inc",
env_vars=("ACTUAL_API_KEY",),
base_url=DEFAULT_ACTUAL_BASE_URL,
auth_type="api_key",
api_mode="chat_completions",
)
register_provider(actual)