feat(models): declare request APIs per preset

Bind API support and preference to the preset's provider and model. Carry the
API declaration through factory selection, fallback chains, hot reload and
WebUI persistence. Use Copilot endpoint metadata for automatic routing and
keep reasoning replay and compaction defaults in provider capability profiles.

Consolidate Responses follow-ups from #5906, #5935, #6020, #6051 and #5834;
acknowledge equivalent contributions in #6105 and #5863.

Co-authored-by: Parman Mohammadalizadeh <prmma23@gmail.com>
Co-authored-by: Lanre Shittu <136805224+Shizoqua@users.noreply.github.com>
Co-authored-by: kkkhoo <128304090+kkkhoo@users.noreply.github.com>
Co-authored-by: pei711 <199601925+pei711@users.noreply.github.com>
Co-authored-by: Steven Huang <134844631+remote-controlled-man@users.noreply.github.com>
Co-authored-by: Louis Yue <179701714+selfucker@users.noreply.github.com>
Co-authored-by: iuiuiu <92971770+iuiu-py@users.noreply.github.com>
This commit is contained in:
authored and chengyongru committed 2026-10-10 01:33:02 +08:00
1 parent 3c866d63ac
commit b5808e47de
23 files changed
+738 -63

No files matched your search

+10 -1
View File
@@ -97,6 +97,8 @@ def _resolve_provider_setup(
if spec and spec.is_transcription_only:
raise ValueError(f"Provider '{provider_name}' only supports transcription.")
backend = spec.backend if spec else "openai_compat"
if preset.api is not None and backend not in {"openai_compat", "github_copilot"}:
raise ValueError("preset.api is supported for OpenAI-compatible and GitHub Copilot providers")
if p and p.proxy and backend not in {"openai_compat", "openai_codex", "xai_grok"}:
raise ValueError(
f"providers.{provider_name}.proxy is only supported for "
@@ -197,7 +199,10 @@ def _make_provider_core(
elif backend == "github_copilot":
from nanobot.providers.github_copilot_provider import GitHubCopilotProvider
provider = GitHubCopilotProvider(default_model=model, provider_name=provider_name)
provider = GitHubCopilotProvider(
default_model=model, provider_name=provider_name,
model_api=preset.api.to_capabilities() if preset.api is not None else None,
)
elif backend == "anthropic":
from nanobot.providers.anthropic_provider import AnthropicProvider
@@ -231,6 +236,7 @@ def _make_provider_core(
spec=spec,
extra_body=p.extra_body if p else None,
api_type=p.api_type if p else "auto",
model_api=preset.api.to_capabilities() if preset.api is not None else None,
extra_query=p.extra_query if p else None,
proxy=p.proxy if p else None,
provider_name=provider_name,
@@ -257,6 +263,7 @@ def _inline_fallback_preset(
fallback.temperature if fallback.temperature is not None else primary.temperature
),
reasoning_effort=fallback.reasoning_effort,
api=fallback.api,
)
@@ -347,6 +354,7 @@ def provider_signature(
fallback.temperature,
fallback.reasoning_effort,
fallback.context_window_tokens,
fallback.api.model_dump_json() if fallback.api is not None else None,
getattr(fp, "proxy", None) if fp else None,
fp.thinking_style if fp else None,
)
@@ -368,6 +376,7 @@ def provider_signature(
resolved.temperature,
resolved.reasoning_effort,
resolved.context_window_tokens,
resolved.api.model_dump_json() if resolved.api is not None else None,
getattr(p, "proxy", None) if p else None,
p.thinking_style if p else None,
tuple(