dashboard_for_sage/wwwroot/api/get_today_usage.dspy

25 lines
573 B
Plaintext

"""获取当天llmusage笔数和交易金额"""
import json
from datetime import date
ns = params_kw.copy()
sql = """
SELECT
COUNT(*) as cnt,
COALESCE(SUM(amount), 0) as total_amount
FROM llmusage
WHERE use_date = ${today}$
"""
today = date.today().isoformat()
db = DBPools()
async with db.sqlorContext('sage') as sor:
recs = await sor.sqlExe(sql, {'today': today})
if recs:
return {
'cnt': int(recs[0].get('cnt', 0)),
'total_amount': float(recs[0].get('total_amount', 0))
}
return {'cnt': 0, 'total_amount': 0}