feat(settings): rename custom gateway models
This commit is contained in:
@@ -1003,6 +1003,25 @@ def update_ai_model(model_name, path=AI_MODELS_PATH, **fields) -> None:
|
||||
save_ai_models_config(config, path=path)
|
||||
|
||||
|
||||
def rename_ai_model(model_name, new_name, path=AI_MODELS_PATH) -> dict:
|
||||
"""Rename one AI model while preserving every other stored field."""
|
||||
|
||||
config = load_ai_models_config(path)
|
||||
index = _model_index(config["models"], model_name)
|
||||
renamed = copy.deepcopy(config["models"][index])
|
||||
renamed["name"] = str(new_name or "").strip()
|
||||
if not renamed["name"]:
|
||||
raise ConfigError("AI 模型名称不能为空")
|
||||
if renamed["name"] != model_name and any(
|
||||
model["name"] == renamed["name"] for model in config["models"]
|
||||
):
|
||||
raise ConfigError(f"AI 模型名称已存在:{renamed['name']}")
|
||||
normalized = _normalize_ai_model(renamed)
|
||||
config["models"][index] = normalized
|
||||
save_ai_models_config(config, path=path)
|
||||
return copy.deepcopy(normalized)
|
||||
|
||||
|
||||
def delete_ai_model(name, path=AI_MODELS_PATH) -> None:
|
||||
config = load_ai_models_config(path)
|
||||
index = _model_index(config["models"], name)
|
||||
|
||||
Reference in New Issue
Block a user