llmage/wwwroot/api/llm_api_map_delete.dspy
yumoqing 6890af7638 fix: 清理所有 dspy 文件的 import 语句
删除已在 ahserver/ServerEnv 预加载的模块:
  json, datetime, getID, debug, curDateString, timestampstr,
  get_sor_context, time, DictObject, partial, FileStorage, os

删除模块内部 import:
  from llmage.utils import get_llmusage_by_id, read_ioinfo_content

同步将 get_llmusage_by_id, read_ioinfo_content 加入 load_llmage() 导出,
dspy 中通过 ServerEnv 全局调用。
2026-06-30 17:38:37 +08:00

31 lines
1.3 KiB
Python

#!/usr/bin/env python3
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
dbname = get_module_dbname('llmage')
map_id = params_kw.get('id', '')
if not map_id:
result['options'] = {'title': 'Error', 'message': '缺少ID参数', 'type': 'error'}
else:
user_orgid = await get_userorgid()
async with DBPools().sqlorContext(dbname) as sor:
# 验证映射记录对应的模型属于当前用户的机构
check = await sor.sqlExe(
"""select m.id from llm_api_map m
join llm l on m.llmid = l.id
where m.id = ${id}$ and l.ownerid = ${ownerid}$""",
{'id': map_id, 'ownerid': user_orgid}
)
if not check:
result['options'] = {'title': 'Error', 'message': '无权删除该映射', 'type': 'error'}
else:
await sor.sqlExe("delete from llm_api_map where id = ${id}$", {'id': map_id})
result['options'] = {'title': 'Success', 'message': '删除成功', 'type': 'success'}
except Exception as e:
result['options'] = {'title': 'Error', 'message': f'删除失败: {str(e)}', 'type': 'error'}
return json.dumps(result, ensure_ascii=False)