feat(webui): show resolved Auto API in preset selector
This commit is contained in:
1 parent
994ce51502
commit
73a27e0726
28 files changed
+464
-259
No files matched your search
@@ -330,6 +330,14 @@ def update_provider_settings(
|
||||
)
|
||||
|
||||
|
||||
def model_api_resolution_payload(
|
||||
query: QueryParams,
|
||||
*,
|
||||
config_path: Path | None = None,
|
||||
) -> dict[str, Any]:
|
||||
return models.model_api_resolution_payload(_load_settings_config(config_path), query)
|
||||
|
||||
|
||||
def provider_models_payload(
|
||||
query: QueryParams,
|
||||
*,
|
||||
|
||||
@@ -32,6 +32,7 @@ from nanobot.config.schema import (
|
||||
ModelPresetConfig,
|
||||
ProviderConfig,
|
||||
)
|
||||
from nanobot.providers.factory import resolve_automatic_model_api
|
||||
from nanobot.providers.image_generation import get_image_gen_provider
|
||||
from nanobot.providers.oauth_guidance import OAUTH_CLI_KIT_MISSING_MESSAGE
|
||||
from nanobot.providers.oauth_model_catalog import (
|
||||
@@ -73,6 +74,7 @@ class ModelSettingsOperations:
|
||||
update_provider: SettingsOperation
|
||||
create_provider: SettingsOperation
|
||||
provider_models: SettingsOperation
|
||||
model_api: SettingsOperation
|
||||
oauth_login: SettingsOperation
|
||||
oauth_complete: SettingsOperation
|
||||
oauth_logout: SettingsOperation
|
||||
@@ -88,6 +90,7 @@ class ModelSettingsPayload(TypedDict):
|
||||
model_call_order: list[str]
|
||||
model_call_order_editable: bool
|
||||
model_configuration_migratable: bool
|
||||
model_api_resolution_supported: bool
|
||||
providers: list[dict[str, Any]]
|
||||
|
||||
|
||||
@@ -1013,6 +1016,25 @@ def reasoning_effort_values_for(provider_name: str, model: str) -> list[str]:
|
||||
return list(_DEFAULT_REASONING_EFFORT_VALUES)
|
||||
|
||||
|
||||
def model_api_resolution_payload(config: Config, query: QueryParams) -> dict[str, Any]:
|
||||
"""Resolve a draft's automatic API using provider-owned routing rules."""
|
||||
model = (query_first(query, "model") or "").strip()
|
||||
if not model:
|
||||
raise WebUISettingsError("model is required")
|
||||
preset = ModelPresetConfig(
|
||||
model=model,
|
||||
provider=(query_first(query, "provider") or "auto").strip(),
|
||||
reasoning_effort=(query_first(query, "reasoning_effort") or "").strip() or None,
|
||||
)
|
||||
try:
|
||||
provider, api = resolve_automatic_model_api(
|
||||
resolve_config_env_vars(config.model_copy(deep=True)), preset=preset,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise WebUISettingsError(str(exc)) from exc
|
||||
return {"provider": provider, "api": api}
|
||||
|
||||
|
||||
def model_settings_payload(
|
||||
config: Config,
|
||||
*,
|
||||
@@ -1102,6 +1124,7 @@ def model_settings_payload(
|
||||
|
||||
model_call_order, model_call_order_editable = _model_call_order_state(config)
|
||||
return {
|
||||
"model_api_resolution_supported": True,
|
||||
"agent": {
|
||||
"model": effective_preset.model,
|
||||
"provider": selected_provider,
|
||||
@@ -1886,6 +1909,12 @@ class ModelSettingsHandler:
|
||||
),
|
||||
)
|
||||
|
||||
if action == "model-api":
|
||||
payload = await asyncio.to_thread(
|
||||
self.settings.read, operations.model_api, request.query,
|
||||
)
|
||||
return SettingsRouteResult.success(payload)
|
||||
|
||||
if action == "provider-models":
|
||||
try:
|
||||
payload = await asyncio.to_thread(
|
||||
|
||||
@@ -44,6 +44,7 @@ from nanobot.webui.settings_api import (
|
||||
login_oauth_provider,
|
||||
logout_oauth_provider,
|
||||
migrate_model_configurations,
|
||||
model_api_resolution_payload,
|
||||
provider_models_payload,
|
||||
settings_payload,
|
||||
settings_usage_payload,
|
||||
@@ -112,6 +113,7 @@ _MODEL_ROUTES = {
|
||||
"/api/settings/provider/update": "provider-update",
|
||||
"/api/settings/provider/create": "provider-create",
|
||||
"/api/settings/provider-models": "provider-models",
|
||||
"/api/settings/model-api": "model-api",
|
||||
"/api/settings/provider/oauth-login": "oauth-login",
|
||||
"/api/settings/provider/oauth-login/complete": "oauth-complete",
|
||||
"/api/settings/provider/oauth-logout": "oauth-logout",
|
||||
@@ -484,6 +486,7 @@ class WebUISettingsRouter:
|
||||
update_provider=update_provider_settings,
|
||||
create_provider=create_provider_settings,
|
||||
provider_models=provider_models_payload,
|
||||
model_api=model_api_resolution_payload,
|
||||
oauth_login=login_oauth_provider,
|
||||
oauth_complete=complete_oauth_provider,
|
||||
oauth_logout=logout_oauth_provider,
|
||||
|
||||
Reference in new issue
Block a user