- 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
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
|
|
result = {'success': False, 'data': {'llms': [], 'catelogs': []}}
|
|
|
|
try:
|
|
dbname = get_module_dbname('llmage')
|
|
user_orgid = await get_userorgid()
|
|
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
# Get all active LLMs belonging to the user's organization
|
|
today = await get_business_date(sor)
|
|
llms_sql = """select id, name from llm
|
|
where enabled_date <= ${today}$
|
|
and expired_date > ${today}$
|
|
and ownerid = ${ownerid}$
|
|
order by name"""
|
|
llms = await sor.sqlExe(llms_sql, {'today': today, 'ownerid': user_orgid})
|
|
result['data']['llms'] = [{'id': r['id'], 'text': r['name']} for r in (llms or [])]
|
|
|
|
# Get all catalogs (assuming catalogs are global or filtered similarly if needed)
|
|
catelogs = await sor.sqlExe("select id, name from llmcatelog order by name", {})
|
|
result['data']['catelogs'] = [{'id': r['id'], 'text': r['name']} for r in (catelogs or [])]
|
|
|
|
result['success'] = True
|
|
|
|
except Exception as e:
|
|
result['error'] = str(e)
|
|
|
|
return json.dumps(result, ensure_ascii=False, default=str)
|