bugfix
This commit is contained in:
parent
9e87a9f902
commit
d32e25feb1
@ -2,8 +2,24 @@ from appPublic.log import exception, debug
|
||||
from appPublic.uniqueID import getID
|
||||
from appPublic.dictObject import DictObject
|
||||
from sqlor.dbpools import get_sor_context
|
||||
from ahserver.serverenv import ServerEnv
|
||||
from pricing.pricing import pricing_program_charging
|
||||
from accounting.consume import consume_accounting
|
||||
from accounting.getaccount import getCustomerBalance
|
||||
|
||||
async def checkCustomerBalance(llmid, userorgid):
|
||||
env = ServerEnv()
|
||||
async with get_sor_context(env, 'llmage') as sor:
|
||||
llms = await sor.R('llm', { 'id': llmid})
|
||||
if len(llms) < 1:
|
||||
e = Exception(f'llm({llmid}) not exists')
|
||||
exception(f'{e}')
|
||||
raise e
|
||||
if llms[0].ownerid == userorgid:
|
||||
return True
|
||||
balance = await getCustomerBalance(sor, userorgid)
|
||||
return llms[0].min_balance < balance
|
||||
return False
|
||||
|
||||
async def llm_accounting(request, llmid,
|
||||
usage, customerid, userid, orderid=None):
|
||||
|
||||
@ -10,6 +10,7 @@ from llmage.llmclient import (
|
||||
get_llmcatelogs,
|
||||
get_llms_by_catelog
|
||||
)
|
||||
from llmage.accounting import checkCustomerBalance
|
||||
from llmage.messages import (
|
||||
BaseMessages,
|
||||
SessionMessages,
|
||||
@ -33,6 +34,7 @@ def load_llmage():
|
||||
env.SessageMessages = SessionMessages
|
||||
env.BaseMessages = BaseMessages
|
||||
env.keling_token = keling_token
|
||||
env.checkCustomerBalance = checkCustomerBalance
|
||||
|
||||
rf = RegisterFunction()
|
||||
rf.register('jimeng_auth_headers', jimeng_auth_headers)
|
||||
|
||||
@ -177,6 +177,7 @@ async def uapi_request(request, llm, sor, params_kw=None):
|
||||
usage['prompt_tokens'] = cnt
|
||||
u = await write_llmusage(luid, llm, callerid, usage, params_kw, outlines, sor)
|
||||
if llm.ppid and callerorgid != llm.ownerid:
|
||||
debug(f'{usage=},{llm.ownerid=},{callerorgid=}')
|
||||
await llm_accounting(request, llm.id, usage, callerorgid, callerid)
|
||||
except Exception as e:
|
||||
exception(f'{e=},{format_exc()}')
|
||||
@ -228,6 +229,7 @@ async def sync_uapi_request(request, llm, sor, params_kw=None):
|
||||
yield b
|
||||
await write_llmusage(luid, llm, callerid, usage, params_kw, outlines, sor)
|
||||
if llm.ppid and callerorgid != llm.ownerid:
|
||||
debug(f'{usage=},{llm.ownerid=},{callerorgid=}')
|
||||
await llm_accounting(request, llm.id, usage, callerorgid, callerid)
|
||||
|
||||
async def async_uapi_request(request, llm, sor, params_kw=None):
|
||||
@ -301,6 +303,7 @@ async def async_uapi_request(request, llm, sor, params_kw=None):
|
||||
usage['finish_time'] = t3 -t1
|
||||
await write_llmusage(luid, llm, callerid, usage, params_kw, outlines, sor)
|
||||
if llm.ppid and callerorgid != llm.ownerid:
|
||||
debug(f'{usage=},{llm.ownerid=},{callerorgid=}')
|
||||
await llm_accounting(request, llm.id, usage, callerorgid, callerid)
|
||||
|
||||
d = rzt
|
||||
|
||||
BIN
models/llm.xlsx
BIN
models/llm.xlsx
Binary file not shown.
@ -1,3 +1,4 @@
|
||||
{% set userorgid = get_userorgid %}
|
||||
{
|
||||
"widgettype":"VScrollPanel",
|
||||
"options":{
|
||||
@ -28,10 +29,14 @@
|
||||
},
|
||||
"subwidgets":[
|
||||
{% for llm in get_llms_by_catelog(cate.id) %}
|
||||
{
|
||||
{% set can_use = checkCustomerBalance(llm.id, userorgid) %}
|
||||
{
|
||||
"widgettype":"VScrollPanel",
|
||||
"options":{
|
||||
"css":"card",
|
||||
{% if not can_use %}
|
||||
"disabled":true,
|
||||
{% endif %}
|
||||
"bgcolor": "#def0f0",
|
||||
"cwidth":20,
|
||||
"cheight":12
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user