mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-31 06:51:29 +00:00
91 lines
3 KiB
Python
91 lines
3 KiB
Python
"""OpenCode provider profiles (Zen + Go).
|
|
|
|
Both use per-model api_mode routing:
|
|
- OpenCode Zen: Claude → anthropic_messages, GPT-5/Codex → codex_responses,
|
|
everything else → chat_completions (this profile)
|
|
- OpenCode Go: MiniMax → anthropic_messages, GLM/Kimi → chat_completions
|
|
(this profile)
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from providers import register_provider
|
|
from providers.base import ProviderProfile
|
|
|
|
|
|
def _flat_model_name(model: str | None) -> str:
|
|
"""Return the bare OpenCode model ID, tolerating aggregator prefixes."""
|
|
return (model or "").strip().rsplit("/", 1)[-1].lower()
|
|
|
|
|
|
def _is_kimi_k2_model(model: str | None) -> bool:
|
|
return _flat_model_name(model).startswith("kimi-k2")
|
|
|
|
|
|
def _is_deepseek_thinking_model(model: str | None) -> bool:
|
|
m = _flat_model_name(model)
|
|
if m.startswith("deepseek-v") and not m.startswith("deepseek-v3"):
|
|
return True
|
|
return m == "deepseek-reasoner"
|
|
|
|
|
|
class OpenCodeGoProfile(ProviderProfile):
|
|
"""OpenCode Go - model-specific reasoning controls."""
|
|
|
|
def build_api_kwargs_extras(
|
|
self, *, reasoning_config: dict | None = None, model: str | None = None, **context
|
|
) -> tuple[dict[str, Any], dict[str, Any]]:
|
|
extra_body: dict[str, Any] = {}
|
|
top_level: dict[str, Any] = {}
|
|
|
|
if _is_kimi_k2_model(model):
|
|
# Kimi K2 uses Moonshot's native binary thinking switch here, not
|
|
# OpenRouter's normalized extra_body.reasoning object.
|
|
if isinstance(reasoning_config, dict):
|
|
enabled = reasoning_config.get("enabled") is not False
|
|
extra_body["thinking"] = {
|
|
"type": "enabled" if enabled else "disabled"
|
|
}
|
|
return extra_body, top_level
|
|
|
|
if not _is_deepseek_thinking_model(model):
|
|
return extra_body, top_level
|
|
|
|
enabled = True
|
|
if isinstance(reasoning_config, dict) and reasoning_config.get("enabled") is False:
|
|
enabled = False
|
|
extra_body["thinking"] = {"type": "enabled" if enabled else "disabled"}
|
|
|
|
if not enabled:
|
|
return extra_body, top_level
|
|
|
|
if isinstance(reasoning_config, dict):
|
|
effort = (reasoning_config.get("effort") or "").strip().lower()
|
|
if effort in {"xhigh", "max"}:
|
|
top_level["reasoning_effort"] = "max"
|
|
elif effort in {"low", "medium", "high"}:
|
|
top_level["reasoning_effort"] = effort
|
|
|
|
return extra_body, top_level
|
|
|
|
|
|
opencode_zen = ProviderProfile(
|
|
name="opencode-zen",
|
|
aliases=("opencode", "opencode_zen", "zen"),
|
|
env_vars=("OPENCODE_ZEN_API_KEY",),
|
|
base_url="https://opencode.ai/zen/v1",
|
|
default_aux_model="gemini-3-flash",
|
|
)
|
|
|
|
opencode_go = OpenCodeGoProfile(
|
|
name="opencode-go",
|
|
aliases=("opencode_go", "go", "opencode-go-sub"),
|
|
env_vars=("OPENCODE_GO_API_KEY",),
|
|
base_url="https://opencode.ai/zen/go/v1",
|
|
default_aux_model="glm-5",
|
|
)
|
|
|
|
register_provider(opencode_zen)
|
|
register_provider(opencode_go)
|