Merge branch 'main' of git.opencomputing.cn:yumoqing/kboss

This commit is contained in:
hrx 2026-05-28 17:40:56 +08:00
commit 35d635f0ab
4 changed files with 2907 additions and 3 deletions

2828
b/all_table.sql Normal file

File diff suppressed because it is too large Load Diff

View File

@ -376,7 +376,6 @@ async def model_usage_user_report(ns={}):
except Exception as e: except Exception as e:
return {'status': False, 'msg': '查询失败, %s' % str(e)} return {'status': False, 'msg': '查询失败, %s' % str(e)}
async def model_usage_admin_report(ns={}): async def model_usage_admin_report(ns={}):
""" """
管理员查看当前机构下所有客户的模型使用汇总。 管理员查看当前机构下所有客户的模型使用汇总。

View File

@ -316,8 +316,8 @@ async def model_usage_user_report(ns={}):
if group_by and group_by not in ('hour', 'day', 'week'): if group_by and group_by not in ('hour', 'day', 'week'):
return {'status': False, 'msg': 'group_by 仅支持 hour / day / week'} return {'status': False, 'msg': 'group_by 仅支持 hour / day / week'}
page_size = int(ns.get('page_size', 20)) page_size = int(ns.get('page_size')) if ns.get('page_size') else 20
current_page = int(ns.get('current_page', 1)) current_page = int(ns.get('current_page')) if ns.get('current_page') else 1
offset = (current_page - 1) * page_size offset = (current_page - 1) * page_size
db = DBPools() db = DBPools()

View File

@ -0,0 +1,77 @@
async def sync_model_to_llm(ns={}):
import aiohttp
# 从数据库读取domain和Bearer token
db = DBPools()
async with db.sqlorContext('kboss') as sor:
domain_li = await sor.R('params', {'pname': 'cntoai_domain'})
user_key = await sor.R('params', {'pname': 'cntoai_already_sync_user_key'})
if not domain_li or not user_key:
return {
'status': False,
'msg': '未找到params domain或Bearer token'
}
domain = domain_li[0]['pvalue']
bearer_token = user_key[0]['pvalue']
url = f"{domain}/llmage/list_llms"
header = {
'Authorization': f'Bearer {bearer_token}',
'Content-Type': 'application/json',
}
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=header) as response:
result = await response.json()
if not result:
return {
'status': False,
'msg': '没有找到模型列表'
}
# 插入数据库
db = DBPools()
async with db.sqlorContext('kboss') as sor:
new_llms_count = 0
new_llms_list = []
for category_list in result:
for item in category_list.get('llms', []):
# 查找数据库中是否已经存在,不存在就插入
exist_llm = await sor.R('llm', {'model': item.get('model')})
if exist_llm:
continue
new_llms = {
'id': item.get('id'),
'name': item.get('name'),
'model': item.get('model'),
'description': item.get('description'),
'llmcatelogid': item.get('catelog_id') or item.get('catelogid'),
'iconid': item.get('iconid'),
'upappid': item.get('upappid'),
'apiname': item.get('apiname'),
'providerid': item.get('providerid'),
'ownerid': item.get('ownerid') or '0',
'enabled_date': item.get('enabled_date'),
'expired_date': item.get('expired_date'),
'query_apiname': item.get('query_apiname') or '',
'query_period': item.get('query_period'),
'ppid': item.get('ppid'),
}
new_llms_count += 1
new_llms_list.append(new_llms.get('model'))
await sor.C('llm', new_llms)
return {
'status': True,
'msg': f"sync_llm_list同步模型成功共插入{new_llms_count}个模型,模型列表: {new_llms_list}"
}
except Exception as e:
return {
'status': False,
'msg': f"sync_llm_list同步模型失败, {domain}, {bearer_token}: {e}"
}
ret = await sync_model_to_llm(params_kw)
return ret