llmage/wwwroot/llmaccounting.dspy
2026-03-30 16:07:52 +08:00

22 lines
621 B
Plaintext

env = request._run_ns
async with get_sor_context(env, 'llmage') as sor:
sql = "select * from llmusage where status='SUCCEEDED' and accounting_status != 'accounted'"
recs = await sor.sqlExe(sql, {})
for r in recs:
try:
llms = await sor.R('llm', {'id': r.llmid})
if len(llms) == 0:
e = Exception(f'{r.llmid=} not found in llm')
exception(f'{e}')
raise e
try:
prices = await llm_charging(sor, llms[0].ppid, r)
except:
continue
r.amount = prices.amount
r.cost = prices.cost
x = await llm_accounting(request, r)
except Exception as e:
exception(f'{r.id=} accounting error')