buggix
This commit is contained in:
parent
7523e67214
commit
90a036e6a9
@ -36,35 +36,28 @@ async def llm_charging(ppid, llmusage):
|
|||||||
'cost': cost
|
'cost': cost
|
||||||
})
|
})
|
||||||
|
|
||||||
async def checkCustomerBalance(llmid, userid, userorgid):
|
async def checkCustomerBalance(llmid, userid, userorgid, catelogid=None):
|
||||||
if llmid is None:
|
if llmid is None:
|
||||||
debug(f'checkCustomerBalance(): llmid is None')
|
debug(f'checkCustomerBalance(): llmid is None')
|
||||||
return False
|
return False
|
||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
async with get_sor_context(env, 'llmage') as sor:
|
llm = await get_llm(llm)
|
||||||
llms = await sor.R('llm', { 'id': llmid})
|
if llm.ownerid == userorgid:
|
||||||
if len(llms) < 1:
|
debug(f'self orgid user')
|
||||||
e = Exception(f'llm({llmid}) not exists')
|
return True
|
||||||
exception(f'{e}')
|
balance = 0.00
|
||||||
raise e
|
apikey = await get_user_tpac_apikey(userid)
|
||||||
llm = llms[0].copy()
|
if apikey:
|
||||||
if llm.ownerid == userorgid:
|
balance = await get_tpac_balance(apikey, userid)
|
||||||
debug(f'self orgid user')
|
else:
|
||||||
return True
|
async with get_sor_context(env, 'accounting') as sor:
|
||||||
apikey = await get_user_tpac_apikey(userid)
|
balance = await getCustomerBalance(userorgid)
|
||||||
balance = 0.00
|
bal = 0 if balance is None else balance
|
||||||
if apikey:
|
if llm.min_balance is None:
|
||||||
balance = await get_tpac_balance(apikey, userid)
|
llm.min_balance = 0.00
|
||||||
else:
|
ret = llm.ppid and llm.min_balance < bal
|
||||||
balance = await getCustomerBalance(sor, userorgid)
|
debug(f'{llm.ppid=}, {llm.min_balance=}, {bal=}')
|
||||||
bal = 0 if balance is None else balance
|
return ret
|
||||||
if llm.min_balance is None:
|
|
||||||
llm.min_balance = 0.00
|
|
||||||
# debug(f'{userorgid=}, {balance=}, {llm.min_balance=}, {llm.ppid=}')
|
|
||||||
ret = llm.ppid and llm.min_balance < bal
|
|
||||||
return ret
|
|
||||||
debug(f'{userorgid=} checkCustomerBalance() failed')
|
|
||||||
return False
|
|
||||||
|
|
||||||
async def llm_accounting(llmusage):
|
async def llm_accounting(llmusage):
|
||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user