This commit is contained in:
yumoqing 2026-03-30 08:21:48 +08:00
parent 28af0c1e37
commit e2f6e4149c
5 changed files with 64 additions and 20 deletions

View File

@ -10,6 +10,10 @@ from accounting.getaccount import getCustomerBalance
async def llm_charging(sor, ppid, llmusage): async def llm_charging(sor, ppid, llmusage):
env = ServerEnv() env = ServerEnv()
prices = await env.pricing_program_charging(sor, ppid, llmusage.usage) prices = await env.pricing_program_charging(sor, ppid, llmusage.usage)
if not pricing:
d = DictObject()
d.original_amount = d.amount = d.cost = 0.00
return d
amount = 0 amount = 0
cost = 0 cost = 0
for p in prices: for p in prices:

View File

@ -19,7 +19,7 @@ from .utils import *
async def get_today_asynctask_list(userid): async def get_today_asynctask_list(userid):
env = ServerEnv() env = ServerEnv()
async with get_sor_context(env, 'llmage') as sor: async with get_sor_context(env, 'llmage') as sor:
today = getCurrentDate() today = env.get_business_date(sor)
sql = '''select * from llmusage sql = '''select * from llmusage
where userid=${userid}$ where userid=${userid}$
and use_date = ${date}$''' and use_date = ${date}$'''
@ -121,7 +121,7 @@ async def add_new_llmusage_output(luid, rzt):
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(out) out.append(rzt)
io['output'] = out io['output'] = out
r.ioinfo = json.dumps({ r.ioinfo = json.dumps({
'input': io.get('input',{}), 'input': io.get('input',{}),
@ -134,33 +134,51 @@ async def query_task_status(request, upappid, apinames, luid, userid, taskid):
async with get_sor_context(env, 'llmage') as sor: async with get_sor_context(env, 'llmage') as sor:
uapi = UAPI(request, sor) uapi = UAPI(request, sor)
for apiname in apinames: for apiname in apinames:
try: status = 'unknown'
while status != 'SUCCEEDED':
ns = {'taskid': taskid} ns = {'taskid': taskid}
d = None
try:
b = await uapi.call(upappid, apiname, userid, params=ns) b = await uapi.call(upappid, apiname, userid, params=ns)
if isinstance(b, bytes): if isinstance(b, bytes):
b = b.decode('utf-8') b = b.decode('utf-8')
d = json.loads(b) d = json.loads(b)
rzt = DictObject(**d) except Exception as e:
await add_new_llmusage_output(luid, rzt) e = Exception(f'{e}')
if rzt.status == 'FAILED': exception(f'{e}')
changed = {
'status': 'FAILED',
'output': {'status': 'FAILED', 'error': str(e)}
}
await add_new_llmusage_output(luid, changed)
return return
rzt = DictObject(**d)
changed = {
'status': rzt.status,
'output': rzt
}
if rzt.status == 'SUCCEEDED': if rzt.status == 'SUCCEEDED':
if llm.ppid: if llm.ppid:
try: try:
charging = await llm_charging(sor, charging = await llm_charging(sor,
llm.ppid, llmusage) llm.ppid, llmusage)
if charging: if charging:
llmusage.amount = charging.amount changed.amount = charging.amount
llmusage.cost = charging.cost changed.cost = charging.cost
else: else:
llmusage.amount = cost = 0.0 changed.amount = cost = 0.0
except Exception as e: except Exception as e:
e = Exception(f'{llm.pid} charging error{e}') e = Exception(f'{llm.pid} charging error{e}')
exception(f'{e}') exception(f'{e}')
else: else:
llmusage.amount = 0 changed.amount = 0
llmusage.cost = 0 changed.cost = 0
await add_new_llmusage_output(luid, changed)
await llm_accounting(request, llmusage) await llm_accounting(request, llmusage)
status = rzt.status
if rzt.status == 'FAILED':
return
await asyncio.sleep(0.1)
except Exception as e: except Exception as e:
exception(f'{e=},{format_exc()}') exception(f'{e=},{format_exc()}')

View File

@ -1,9 +1,9 @@
from appPublic.base64_to_file import hex2base64 from appPublic.base64_to_file import hex2base64
from appPublic.registerfunction import RegisterFunction from appPublic.registerfunction import RegisterFunction
from llmage.jimeng import jimeng_auth_headers from .jimeng import jimeng_auth_headers
from llmage.keling import keling_token from .keling import keling_token
from llmage.llmclient import ( from .llmclient import (
b64media2url, b64media2url,
get_llm, get_llm,
inference_generator, inference_generator,
@ -14,11 +14,17 @@ from llmage.llmclient import (
get_llmcatelogs, get_llmcatelogs,
get_llms_by_catelog get_llms_by_catelog
) )
from llmage.accounting import checkCustomerBalance from .accounting import checkCustomerBalance
from ahserver.serverenv import ServerEnv from .serverenv import ServerEnv
from asyncinference import (
get_asynctask_status,
get_today_asynctask_list
)
def load_llmage(): def load_llmage():
env = ServerEnv() env = ServerEnv()
env.get_today_asynctask_list = get_today_asynctask_list
env.get_asynctask_status = get_asynctask_status
env.get_llm = get_llm env.get_llm = get_llm
env.b64media2url = b64media2url env.b64media2url = b64media2url
env.hex2base64 = hex2base64 env.hex2base64 = hex2base64

View File

@ -0,0 +1,8 @@
taskid = params_kw.taskid
s = await get_asynctask_status(taskid)
return {
'status': 'ok',
'data': {
'resposne': s
}
}

View File

@ -0,0 +1,8 @@
userid = await get_userid()
tasks = await get_today_asynctask_list(userrid)
return {
'status': 'ok',
'data': {
'tasks': tasks
}
}