llmage/wwwroot/api/llm_catalog_rel_create.dspy
yumoqing 6cc3986a2d feat: support multi-catalog for LLMs
- Create llm_catalog_rel model for one-to-many relationship
- Remove llmcatelogid from llm model
- Update SQL queries in utils.py and dspy files to use join
- Add maintenance UI (llm_catalog_rel_manage.ui) and API endpoints
- Filter options by user's orgid
2026-05-16 21:31:19 +08:00

33 lines
1.3 KiB
Python

#!/usr/bin/env python3
import json
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
dbname = get_module_dbname('llmage')
llmid = params_kw.get('llmid', '')
catelogid = params_kw.get('llmcatelogid', '')
if not llmid or not catelogid:
result['options'] = {'title': 'Error', 'message': '请选择模型和目录', 'type': 'error'}
else:
from appPublic.uniqueID import getID
new_id = getID()
async with DBPools().sqlorContext(dbname) as sor:
# 检查是否已存在
check_sql = "select id from llm_catalog_rel where llmid = ${llmid}$ and llmcatelogid = ${catelogid}$"
exists = await sor.sqlExe(check_sql, {'llmid': llmid, 'catelogid': catelogid})
if exists:
result['options'] = {'title': '提示', 'message': '该关联已存在', 'type': 'warning'}
else:
data = {'id': new_id, 'llmid': llmid, 'llmcatelogid': catelogid}
await sor.C('llm_catalog_rel', data)
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)