- 删除 llm_catalog_rel 表定义(models/json/xlsx)、CRUD文件、管理页面、迁移脚本 - utils.py: get_llms_by_catelog/get_llms_by_catelog_to_customer 的SQL从 llm_catalog_rel 改为 llm_api_map (加distinct去重) - init.py: 缓存清除事件从 llm_catalog_rel 改为 llm_api_map - menu.ui/index.ui: 移除类型关联菜单项 - dspy文件: v1/chat/completions, t2t, get_type_llms, list_catelog_models, list_paging_catelog_llms, llmcatelog_delete 全部改为 join llm_api_map - 迁移脚本: 添加try/except兼容旧表不存在的情况
34 lines
1.5 KiB
Python
34 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
|
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
|
|
|
try:
|
|
dbname = get_module_dbname('llmage')
|
|
id = params_kw.get('id', '').strip()
|
|
|
|
if not id:
|
|
result['options'] = {'title': '错误', 'message': '记录ID不能为空', 'type': 'error'}
|
|
else:
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
# 检查是否有模型关联此类型
|
|
check_sql = "select count(*) as cnt from llm_api_map where llmcatelogid=${id}$"
|
|
rel_count = await sor.sqlExe(check_sql, {'id': id})
|
|
cnt = rel_count[0]['cnt'] if rel_count else 0
|
|
if cnt > 0:
|
|
result['options'] = {'title': '提示', 'message': f'该类型下还有 {cnt} 个模型关联,无法删除', 'type': 'warning'}
|
|
else:
|
|
# 获取类型名用于提示
|
|
name_sql = "select name from llmcatelog where id=${id}$"
|
|
name_rows = await sor.sqlExe(name_sql, {'id': id})
|
|
type_name = name_rows[0]['name'] if name_rows else id
|
|
|
|
delete_sql = "delete from llmcatelog where id=${id}$"
|
|
await sor.sqlExe(delete_sql, {'id': id})
|
|
result = {'widgettype': 'Message', 'options': {'title': '成功', 'message': f'类型「{type_name}」已删除', 'type': 'info'}}
|
|
|
|
except Exception as e:
|
|
result['options'] = {'title': '错误', 'message': str(e), 'type': 'error'}
|
|
|
|
return json.dumps(result, ensure_ascii=False)
|