feat(models): declare provider APIs and simplify preset configuration

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-10 01:33:02 +08:00
1 parent 592f0559a9
commit 994ce51502
26 files changed
+444 -123

No files matched your search

+13 -2
View File
@@ -7,8 +7,8 @@ import pytest
from openai import AsyncOpenAI
from pydantic import ValidationError
from nanobot.config.schema import Config, InlineFallbackConfig, ModelAPIConfig
from nanobot.providers.factory import make_provider, provider_signature
from nanobot.config.schema import Config, InlineFallbackConfig, ModelAPIConfig, ModelPresetConfig
from nanobot.providers.factory import make_provider, provider_signature, validate_provider_setup
from nanobot.providers.openai_compat_provider import _RESPONSES_FAILURE_THRESHOLD
@@ -171,6 +171,17 @@ def test_preset_api_preference_must_be_supported():
ModelAPIConfig.model_validate({"supportedApis": ["chat_completions"], "preferredApi": "responses"})
def test_fixed_provider_validates_preset_api_before_loading_client():
config = Config()
preset = ModelPresetConfig(
provider="openai_codex", model="gpt-6-astra", api=ModelAPIConfig(supported_apis=("responses",)),
)
validate_provider_setup(config, preset=preset)
preset.api = ModelAPIConfig(supported_apis=("responses", "chat_completions"))
with pytest.raises(ValueError, match="OpenAI Codex.*does not support chat_completions"):
validate_provider_setup(config, preset=preset)
@pytest.mark.parametrize("apis,preferred", [
(("responses",), "responses"),
(("chat_completions",), "chat_completions"),
@@ -28,6 +28,7 @@ async def test_openai_compat_provider_sets_timeout_on_local_http_client() -> Non
name="local",
keywords=(),
env_key="",
request_apis=("chat_completions", "responses"),
is_local=True,
default_api_base="http://127.0.0.1:11434/v1",
)
@@ -64,6 +64,7 @@ def test_responses_behavior_is_declared_by_capabilities(provider):
name="example",
keywords=("example",),
env_key="EXAMPLE_API_KEY",
request_apis=("chat_completions", "responses"),
responses=ResponsesCapabilities(
models=("example-o3",),
reasoning_replay="plaintext",
@@ -239,6 +240,7 @@ def _deepseek_provider(provider):
name="deepseek",
keywords=("deepseek",),
env_key="DEEPSEEK_API_KEY",
request_apis=("chat_completions", "responses"),
responses=ResponsesCapabilities(
models=("deepseek-v4-flash",),
reasoning_replay="plaintext",
@@ -15,6 +15,7 @@ _STEPFUN_SPEC = ProviderSpec(
name="stepfun",
keywords=("stepfun", "step"),
env_key="STEPFUN_API_KEY",
request_apis=("chat_completions", "responses"),
display_name="Step Fun",
backend="openai_compat",
default_api_base="https://api.stepfun.com/v1",