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:
1 parent
3c866d63ac
commit
b5808e47de
23 files changed
+738
-63
No files matched your search
@@ -10,6 +10,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from nanobot.config.timezone import detect_system_timezone
|
||||
from nanobot.config_base import Base
|
||||
from nanobot.cron.types import CronSchedule
|
||||
from nanobot.providers.registry import ModelAPICapabilities, RequestAPI
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nanobot.agent.tools.cli_apps import CliAppsToolConfig
|
||||
@@ -81,6 +82,25 @@ class DreamConfig(Base):
|
||||
return f"every {hours}h"
|
||||
|
||||
|
||||
class ModelAPIConfig(Base):
|
||||
"""API support and preference scoped to a model preset's endpoint."""
|
||||
|
||||
supported_apis: tuple[RequestAPI, ...] = Field(min_length=1)
|
||||
preferred_api: RequestAPI | None = None
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _validate_preference(self) -> "ModelAPIConfig":
|
||||
if self.preferred_api is not None and self.preferred_api not in self.supported_apis:
|
||||
raise ValueError("preferred_api must be one of supported_apis")
|
||||
return self
|
||||
|
||||
def to_capabilities(self) -> ModelAPICapabilities:
|
||||
return ModelAPICapabilities(
|
||||
supported_apis=self.supported_apis,
|
||||
preferred_api=self.preferred_api or self.supported_apis[0],
|
||||
)
|
||||
|
||||
|
||||
class InlineFallbackConfig(Base):
|
||||
"""One inline fallback model configuration."""
|
||||
|
||||
@@ -90,6 +110,7 @@ class InlineFallbackConfig(Base):
|
||||
context_window_tokens: int | None = None
|
||||
temperature: float | None = None
|
||||
reasoning_effort: str | None = None
|
||||
api: ModelAPIConfig | None = None
|
||||
|
||||
|
||||
FallbackCandidate = str | InlineFallbackConfig
|
||||
@@ -104,6 +125,7 @@ class ModelPresetConfig(Base):
|
||||
context_window_tokens: int = 200_000
|
||||
temperature: float = 0.1
|
||||
reasoning_effort: str | None = None
|
||||
api: ModelAPIConfig | None = None
|
||||
|
||||
def to_generation_settings(self) -> Any:
|
||||
from nanobot.providers.base import GenerationSettings
|
||||
@@ -139,6 +161,7 @@ class AgentDefaults(Base):
|
||||
serialization_alias="toolHintMaxLength",
|
||||
) # Max characters for tool hint display (e.g. "$ cd …/project && npm test")
|
||||
reasoning_effort: str | None = None # low / medium / high / xhigh / max / adaptive / none — LLM thinking effort; None preserves the provider default
|
||||
api: ModelAPIConfig | None = None
|
||||
timezone: str = "UTC" # Effective IANA timezone, e.g. "Asia/Shanghai"
|
||||
timezone_mode: Literal["auto", "manual"] = "auto"
|
||||
bot_name: str = "nanobot" # Display name shown in CLI prompts (e.g. "{name} is thinking...")
|
||||
@@ -476,7 +499,7 @@ class Config(BaseSettings):
|
||||
return ModelPresetConfig(
|
||||
model=d.model, provider=d.provider, max_tokens=d.max_tokens,
|
||||
context_window_tokens=d.context_window_tokens,
|
||||
temperature=d.temperature, reasoning_effort=d.reasoning_effort,
|
||||
temperature=d.temperature, reasoning_effort=d.reasoning_effort, api=d.api,
|
||||
)
|
||||
|
||||
def resolve_preset(self, name: str | None = None) -> ModelPresetConfig:
|
||||
|
||||
Reference in new issue
Block a user