perf(webui): streamline model preset saves (#6631)
* perf(webui): streamline model preset saves * fix(webui): type optional settings usage payload
This commit is contained in:
1 parent
3c61bcfdf0
commit
28d73b6942
10 files changed
+174
-59
No files matched your search
@@ -29,6 +29,7 @@ UPDATE_CHANNEL_CAPABILITY = "webui.update-channels.v1"
|
||||
CONTEXT_GRAPH_REFERENCES_CAPABILITY = "webui.context-graph.references.v1"
|
||||
PROMPT_NAVIGATION_CAPABILITY = "webui.prompt-navigation.v1"
|
||||
SANDBOX_SETTINGS_CAPABILITY = "webui.sandbox-settings.v1"
|
||||
MODEL_PRESET_SAVE_CAPABILITY = "webui.model-preset-save.v1"
|
||||
|
||||
|
||||
class Compatibility(TypedDict):
|
||||
@@ -49,7 +50,7 @@ def webui_contract() -> dict[str, object]:
|
||||
UPDATE_JOB_CAPABILITY, UPDATE_PREPARATION_CAPABILITY, UPDATE_EXECUTION_CAPABILITY,
|
||||
UPDATE_RETRY_CAPABILITY, UPDATE_SETTLE_HANDOFF_CAPABILITY, UPDATE_FLOW_CAPABILITY, UPDATE_CHANNEL_CAPABILITY,
|
||||
PROMPT_NAVIGATION_CAPABILITY, CONTEXT_GRAPH_REFERENCES_CAPABILITY,
|
||||
SANDBOX_SETTINGS_CAPABILITY,
|
||||
SANDBOX_SETTINGS_CAPABILITY, MODEL_PRESET_SAVE_CAPABILITY,
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@@ -161,6 +161,7 @@ def settings_payload(
|
||||
restart_required_sections: list[str] | None = None,
|
||||
apply_state: dict[str, Any] | None = None,
|
||||
config_path: Path | None = None,
|
||||
include_usage: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
config = _load_settings_config(config_path)
|
||||
payload: dict[str, Any] = {
|
||||
@@ -176,6 +177,7 @@ def settings_payload(
|
||||
config,
|
||||
config_path=_settings_config_path(config_path),
|
||||
version=__version__,
|
||||
include_usage=include_usage,
|
||||
),
|
||||
"requires_restart": requires_restart,
|
||||
}
|
||||
@@ -223,8 +225,12 @@ def create_model_configuration(
|
||||
query,
|
||||
oauth_status=_oauth_provider_status,
|
||||
)
|
||||
if _query_first(query, "append_to_order") == "true":
|
||||
models.append_model_call_order(config, name, oauth_status=_oauth_provider_status)
|
||||
_save_settings_config(config, config_path)
|
||||
payload = settings_payload(config_path=config_path)
|
||||
payload = settings_payload(
|
||||
config_path=config_path, include_usage=_query_first(query, "include_usage") != "false",
|
||||
)
|
||||
payload["created_model_preset"] = name
|
||||
return payload
|
||||
|
||||
@@ -259,7 +265,9 @@ def update_model_configuration(
|
||||
raise
|
||||
else:
|
||||
_save_settings_config(config, config_path)
|
||||
return settings_payload(config_path=config_path)
|
||||
return settings_payload(
|
||||
config_path=config_path, include_usage=_query_first(query, "include_usage") != "false",
|
||||
)
|
||||
|
||||
|
||||
def update_model_call_order(
|
||||
|
||||
@@ -1483,6 +1483,19 @@ def update_model_call_order(
|
||||
raise WebUISettingsError("model call order must contain at least one preset")
|
||||
|
||||
normalized_order = [cast(str, name).strip() for name in cast(list[object], order)]
|
||||
return _set_model_call_order(config, normalized_order, oauth_status=oauth_status)
|
||||
|
||||
|
||||
def append_model_call_order(config: Config, name: str, *, oauth_status: OAuthStatusReader) -> None:
|
||||
order, _ = _model_call_order_state(config)
|
||||
if name not in order:
|
||||
order.append(name)
|
||||
_set_model_call_order(config, order, oauth_status=oauth_status)
|
||||
|
||||
|
||||
def _set_model_call_order(
|
||||
config: Config, normalized_order: list[str], *, oauth_status: OAuthStatusReader,
|
||||
) -> bool:
|
||||
unknown = [name for name in normalized_order if name not in config.model_presets]
|
||||
if unknown:
|
||||
raise WebUISettingsError(f"unknown model preset: {unknown[0]}")
|
||||
|
||||
@@ -10,7 +10,7 @@ import time
|
||||
from collections.abc import Awaitable, Callable, Iterable, Mapping
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, TypedDict, cast
|
||||
from typing import TYPE_CHECKING, Any, NotRequired, TypedDict, cast
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import httpx
|
||||
@@ -100,7 +100,7 @@ class GatewayEnvironmentPayload(TypedDict):
|
||||
class SystemSettingsPayload(TypedDict):
|
||||
runtime_config: dict[str, Any]
|
||||
runtime: dict[str, Any]
|
||||
usage: dict[str, Any]
|
||||
usage: NotRequired[dict[str, Any]]
|
||||
advanced: dict[str, Any]
|
||||
version: dict[str, Any]
|
||||
environment: GatewayEnvironmentPayload
|
||||
@@ -136,6 +136,7 @@ def system_settings_payload(
|
||||
*,
|
||||
config_path: Path,
|
||||
version: str,
|
||||
include_usage: bool = True,
|
||||
) -> SystemSettingsPayload:
|
||||
defaults = config.agents.defaults
|
||||
exec_config = config.tools.exec
|
||||
@@ -143,7 +144,7 @@ def system_settings_payload(
|
||||
restrict_to_workspace=config.tools.restrict_to_workspace,
|
||||
workspace=config.workspace_path,
|
||||
)
|
||||
return {
|
||||
payload: SystemSettingsPayload = {
|
||||
"runtime_config": runtime_config_payload(config),
|
||||
"runtime": {
|
||||
"config_path": str(config_path.expanduser()),
|
||||
@@ -159,7 +160,6 @@ def system_settings_payload(
|
||||
},
|
||||
"unified_session": defaults.unified_session,
|
||||
},
|
||||
"usage": llm_usage_payload(timezone_name=defaults.timezone),
|
||||
"advanced": {
|
||||
"restrict_to_workspace": config.tools.restrict_to_workspace,
|
||||
"workspace_sandbox": sandbox_status.as_dict(),
|
||||
@@ -181,6 +181,9 @@ def system_settings_payload(
|
||||
},
|
||||
"docs": docs_payload(version),
|
||||
}
|
||||
if include_usage:
|
||||
payload["usage"] = llm_usage_payload(timezone_name=defaults.timezone)
|
||||
return payload
|
||||
|
||||
|
||||
def settings_usage_payload(config: Config) -> dict[str, Any]:
|
||||
|
||||
Reference in new issue
Block a user