llmage/wwwroot/api/llmcatelog_list.dspy
yumoqing 1b74b5bf10 feat: add llm catalog (type) management module
- Add CRUD API for llmcatelog (list/create/update/delete)
- Add llmcatelog.ui as main entry for catalog management
- Add llmcatelog_list.ui as DataViewer interface
- Add index.ui as module navigation page
- Update json/llmcatelog.json with editable section
2026-05-17 00:46:31 +08:00

29 lines
982 B
Python

#!/usr/bin/env python3
import json
result = {'success': False, 'rows': [], 'total': 0}
try:
dbname = get_module_dbname('llmage')
page = int(params_kw.get('page', 1))
rows_per_page = int(params_kw.get('rows', 20))
offset = (page - 1) * rows_per_page
async with DBPools().sqlorContext(dbname) as sor:
# 获取总数
count_sql = "select count(*) as cnt from llmcatelog"
count_rows = await sor.sqlExe(count_sql, {})
total = count_rows[0]['cnt'] if count_rows else 0
# 获取分页数据
data_sql = "select id, name, description from llmcatelog order by name limit ${limit}$ offset ${offset}$"
rows = await sor.sqlExe(data_sql, {'limit': rows_per_page, 'offset': offset})
result['rows'] = [dict(r) for r in (rows or [])]
result['total'] = total
result['success'] = True
except Exception as e:
result['error'] = str(e)
return json.dumps(result, ensure_ascii=False, default=str)