refactor(config)!: retire the old OpenAI API selector (#6615)
Co-authored-by: chengyongru <chengyongru.ai@gmail.com>
This commit is contained in:
1 parent
e3a1af2ed3
commit
5c1083df7f
14 files changed
+112
-141
No files matched your search
@@ -26,7 +26,6 @@ from typing import TYPE_CHECKING, Any, Awaitable, Callable, NotRequired, TypedDi
|
||||
import httpx
|
||||
|
||||
from nanobot.config.loader import resolve_config_env_vars
|
||||
from nanobot.config.provider_api_migration import migrate_legacy_provider_api
|
||||
from nanobot.config.schema import (
|
||||
Config,
|
||||
FallbackCandidate,
|
||||
@@ -131,7 +130,14 @@ _ENV_REF_RE = re.compile(r"\$\{([A-Za-z_][A-Za-z0-9_]*)\}")
|
||||
_PROVIDER_STRUCTURED_FIELDS = ("extra_headers", "extra_body", "extra_query")
|
||||
|
||||
|
||||
def _provider_config_updates(query: QueryParams) -> dict[str, Any]:
|
||||
def _provider_config_updates(
|
||||
query: QueryParams, *, ignore_retired_api_type: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
if not ignore_retired_api_type and query_has_alias(query, "api_type", "apiType"):
|
||||
raise WebUISettingsError(
|
||||
"This client sent the retired apiType setting. Update the client or use the WebUI "
|
||||
"served by the gateway to save the provider settings."
|
||||
)
|
||||
updates: dict[str, Any] = {}
|
||||
string_fields = (
|
||||
("api_key", "apiKey"),
|
||||
@@ -161,9 +167,6 @@ def _provider_config_updates(query: QueryParams) -> dict[str, Any]:
|
||||
updates["api"] = json.loads(query_first(query, "api") or "null")
|
||||
except ValueError as exc:
|
||||
raise WebUISettingsError("api must declare supportedApis and a preferredApi from that list") from exc
|
||||
# Temporary input compatibility for older clients during the two-release window.
|
||||
if query_has_alias(query, "api_type", "apiType"):
|
||||
updates["api_type"] = query_first_alias(query, "api_type", "apiType") or "auto"
|
||||
return updates
|
||||
|
||||
|
||||
@@ -1639,18 +1642,16 @@ def update_provider_settings(
|
||||
if resolved_provider is None:
|
||||
raise WebUISettingsError("unknown provider")
|
||||
spec, provider_key, provider_config = resolved_provider
|
||||
updates = _provider_config_updates(query)
|
||||
# Keep the current declaration authoritative and preserve saves from old
|
||||
# clients that also sent this irrelevant field for other providers.
|
||||
updates = _provider_config_updates(
|
||||
query, ignore_retired_api_type="api" in query or (not spec.is_oauth and spec.name != "openai"),
|
||||
)
|
||||
if updates.get("use_proxy"):
|
||||
try:
|
||||
config.network.resolve_proxy(True)
|
||||
except ValueError as exc:
|
||||
raise WebUISettingsError(str(exc)) from None
|
||||
if not spec.is_oauth and spec.name != "openai":
|
||||
updates.pop("api_type", None)
|
||||
try:
|
||||
updates = migrate_legacy_provider_api(updates, provider_name=provider_key)
|
||||
except ValueError as exc:
|
||||
raise WebUISettingsError(str(exc)) from None
|
||||
if spec.is_oauth:
|
||||
if spec.name not in _OAUTH_PROXY_PROVIDERS:
|
||||
raise WebUISettingsError("unknown provider")
|
||||
|
||||
Reference in new issue
Block a user