This commit is contained in:
yumoqing 2026-03-30 12:17:35 +08:00
parent e6129764f5
commit 3c3b4eec93
2 changed files with 12 additions and 7 deletions

View File

@ -123,4 +123,6 @@ async def llm_accounting(request, llmusage):
} }
ais.append(ai1) ais.append(ai1)
await consume_accounting(sor, orderid, ais) await consume_accounting(sor, orderid, ais)
llmusage.accounting_status = 'accounted'
await sor.U('llmusage', llmusage)

View File

@ -117,20 +117,22 @@ async def async_uapi_request(request, llm, sor,
yield f'{s}\n' yield f'{s}\n'
return return
async def add_new_llmusage_output(luid, rzt): async def add_new_llmusage_output(luid, newd):
env = ServerEnv() env = ServerEnv()
newd = newd.copy()
async with get_sor_context(env, 'llmage') as sor: async with get_sor_context(env, 'llmage') as sor:
recs = await sor.R('llmusage', {'id': luid}) recs = await sor.R('llmusage', {'id': luid})
if recs: if recs:
r = recs[0] r = recs[0]
io = json.loads(r.ioinfo) io = json.loads(r.ioinfo)
out = io.get('output', []) out = io.get('output', [])
out.append(rzt) rzt = newd.get('output')
if rzt:
out.append(rzt)
newd = {k:v for k,v in newd.items() if k != 'output'}
io['output'] = out io['output'] = out
r.ioinfo = json.dumps({ r.ioinfo = json.dumps(io)
'input': io.get('input',{}), r.update(newd)
'output': out
})
await sor.U('llmusage', r) await sor.U('llmusage', r)
return return
@ -183,7 +185,8 @@ async def query_task_status(request, upappid, apiname, luid, userid, taskid):
else: else:
changed.amount = 0 changed.amount = 0
changed.cost = 0 changed.cost = 0
await add_new_llmusage_output(luid, changed) await add_new_llmusage_output(luid, changed)
if llmusage.accounting_status != 'accounted':
await llm_accounting(request, llmusage) await llm_accounting(request, llmusage)
status = rzt.status status = rzt.status
if rzt.status == 'FAILED': if rzt.status == 'FAILED':