feat: add llmcatelogid filter and pagerows param to get_inference_history
- Add llmcatelogid parameter to filter by model catalog (joins llm table) - Change default pagerows from 50 to 10 - Add pagerows parameter for custom page size
This commit is contained in:
parent
eee648038a
commit
6f8c14c329
@ -282,13 +282,15 @@ await query_task_status(request, luid, onetime=False)
|
||||
|
||||
`GET /llmage/api/get_inference_history.dspy`
|
||||
|
||||
跨表(llmusage + llmusage_history)分页查询当前用户的推理历史,按时间倒序返回,每页 50 条。自动通过 FileStorage 读取 ioinfo 文件内容,返回实际输入输出。
|
||||
跨表(llmusage + llmusage_history)分页查询当前用户的推理历史,按时间倒序返回,默认每页 10 条。自动通过 FileStorage 读取 ioinfo 文件内容,返回实际输入输出。
|
||||
|
||||
**请求参数**:
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| page | int | 否 | 页码,默认 1 |
|
||||
| pagerows | int | 否 | 每页条数,默认 10 |
|
||||
| llmcatelogid | str | 否 | 按模型分类 ID 过滤,仅返回该分类下模型的记录 |
|
||||
|
||||
**返回字段**:
|
||||
|
||||
@ -297,7 +299,7 @@ await query_task_status(request, luid, onetime=False)
|
||||
| success | 是否成功 |
|
||||
| total | 两表合计总记录数 |
|
||||
| page | 当前页码 |
|
||||
| page_size | 每页条数(固定 50) |
|
||||
| page_size | 每页条数(默认 10,可通过 pagerows 参数指定) |
|
||||
| rows | 记录列表 |
|
||||
|
||||
**rows 中每条记录**:
|
||||
|
||||
@ -1,25 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
|
||||
result = {'success': False, 'rows': [], 'total': 0, 'page': 1, 'page_size': 50}
|
||||
result = {'success': False, 'rows': [], 'total': 0, 'page': 1, 'page_size': 10}
|
||||
|
||||
try:
|
||||
dbname = get_module_dbname('llmage')
|
||||
userid = await get_user()
|
||||
|
||||
page = int(params_kw.get('page', 1))
|
||||
page_size = 50
|
||||
page_size = int(params_kw.get('pagerows', 10))
|
||||
llmcatelogid = params_kw.get('llmcatelogid')
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
# Build filter conditions
|
||||
conditions = ["userid = ${userid}$"]
|
||||
ns = {'userid': userid}
|
||||
|
||||
if llmcatelogid:
|
||||
conditions.append("llmid in (select id from llm where llmcatelogid = ${llmcatelogid}$)")
|
||||
ns['llmcatelogid'] = llmcatelogid
|
||||
|
||||
where_clause = " and ".join(conditions)
|
||||
|
||||
# Count total from both tables
|
||||
count_sql = """
|
||||
count_sql = f"""
|
||||
select count(*) as cnt from (
|
||||
select id from llmusage where userid = ${userid}$
|
||||
select id from llmusage where {where_clause}
|
||||
union all
|
||||
select id from llmusage_history where userid = ${userid}$
|
||||
select id from llmusage_history where {where_clause}
|
||||
) t
|
||||
"""
|
||||
count_recs = await sor.sqlExe(count_sql, {'userid': userid})
|
||||
count_recs = await sor.sqlExe(count_sql, ns)
|
||||
total = count_recs[0].cnt if count_recs else 0
|
||||
|
||||
# UNION ALL query with pagination, time descending
|
||||
@ -30,16 +41,16 @@ try:
|
||||
from (
|
||||
select id, llmid, use_date, use_time, userid, usages, ioinfo,
|
||||
status, taskid, amount, cost, userorgid, accounting_status
|
||||
from llmusage where userid = ${{userid}}$
|
||||
from llmusage where {where_clause}
|
||||
union all
|
||||
select id, llmid, use_date, use_time, userid, usages, ioinfo,
|
||||
status, taskid, amount, cost, userorgid, accounting_status
|
||||
from llmusage_history where userid = ${{userid}}$
|
||||
from llmusage_history where {where_clause}
|
||||
) t
|
||||
order by use_time desc
|
||||
limit {page_size} offset {offset}
|
||||
"""
|
||||
recs = await sor.sqlExe(query_sql, {'userid': userid})
|
||||
recs = await sor.sqlExe(query_sql, ns)
|
||||
|
||||
rows = []
|
||||
for r in (recs or []):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user