删除已在 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 全局调用。
38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
result = {'success': False, 'data': {'llms': [], 'catelogs': [], 'apis': [], 'ppids': []}}
|
|
|
|
try:
|
|
dbname = get_module_dbname('llmage')
|
|
user_orgid = await get_userorgid()
|
|
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
# Active LLMs for 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 [])]
|
|
|
|
# All catalogs
|
|
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 [])]
|
|
|
|
# uapi list (for apiname selection)
|
|
apis = await sor.sqlExe("select name, path from uapi order by name", {})
|
|
result['data']['apis'] = [{'id': r['name'], 'text': f"{r['name']} ({r['path']})"} for r in (apis or [])]
|
|
|
|
# Pricing programs
|
|
ppids = await sor.sqlExe("select id, name from pricing_program order by name", {})
|
|
result['data']['ppids'] = [{'id': r['id'], 'text': r['name']} for r in (ppids or [])]
|
|
|
|
result['success'] = True
|
|
|
|
except Exception as e:
|
|
result['error'] = str(e)
|
|
|
|
return json.dumps(result, ensure_ascii=False, default=str)
|