This commit is contained in:
yumoqing 2026-01-06 11:00:38 +08:00
parent 9e87a9f902
commit d32e25feb1
5 changed files with 27 additions and 1 deletions

View File

@ -2,8 +2,24 @@ from appPublic.log import exception, debug
from appPublic.uniqueID import getID from appPublic.uniqueID import getID
from appPublic.dictObject import DictObject from appPublic.dictObject import DictObject
from sqlor.dbpools import get_sor_context from sqlor.dbpools import get_sor_context
from ahserver.serverenv import ServerEnv
from pricing.pricing import pricing_program_charging from pricing.pricing import pricing_program_charging
from accounting.consume import consume_accounting 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, async def llm_accounting(request, llmid,
usage, customerid, userid, orderid=None): usage, customerid, userid, orderid=None):

View File

@ -10,6 +10,7 @@ from llmage.llmclient import (
get_llmcatelogs, get_llmcatelogs,
get_llms_by_catelog get_llms_by_catelog
) )
from llmage.accounting import checkCustomerBalance
from llmage.messages import ( from llmage.messages import (
BaseMessages, BaseMessages,
SessionMessages, SessionMessages,
@ -33,6 +34,7 @@ def load_llmage():
env.SessageMessages = SessionMessages env.SessageMessages = SessionMessages
env.BaseMessages = BaseMessages env.BaseMessages = BaseMessages
env.keling_token = keling_token env.keling_token = keling_token
env.checkCustomerBalance = checkCustomerBalance
rf = RegisterFunction() rf = RegisterFunction()
rf.register('jimeng_auth_headers', jimeng_auth_headers) rf.register('jimeng_auth_headers', jimeng_auth_headers)

View File

@ -177,6 +177,7 @@ async def uapi_request(request, llm, sor, params_kw=None):
usage['prompt_tokens'] = cnt usage['prompt_tokens'] = cnt
u = await write_llmusage(luid, llm, callerid, usage, params_kw, outlines, sor) u = await write_llmusage(luid, llm, callerid, usage, params_kw, outlines, sor)
if llm.ppid and callerorgid != llm.ownerid: if llm.ppid and callerorgid != llm.ownerid:
debug(f'{usage=},{llm.ownerid=},{callerorgid=}')
await llm_accounting(request, llm.id, usage, callerorgid, callerid) await llm_accounting(request, llm.id, usage, callerorgid, callerid)
except Exception as e: except Exception as e:
exception(f'{e=},{format_exc()}') exception(f'{e=},{format_exc()}')
@ -228,6 +229,7 @@ async def sync_uapi_request(request, llm, sor, params_kw=None):
yield b yield b
await write_llmusage(luid, llm, callerid, usage, params_kw, outlines, sor) await write_llmusage(luid, llm, callerid, usage, params_kw, outlines, sor)
if llm.ppid and callerorgid != llm.ownerid: if llm.ppid and callerorgid != llm.ownerid:
debug(f'{usage=},{llm.ownerid=},{callerorgid=}')
await llm_accounting(request, llm.id, usage, callerorgid, callerid) await llm_accounting(request, llm.id, usage, callerorgid, callerid)
async def async_uapi_request(request, llm, sor, params_kw=None): 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 usage['finish_time'] = t3 -t1
await write_llmusage(luid, llm, callerid, usage, params_kw, outlines, sor) await write_llmusage(luid, llm, callerid, usage, params_kw, outlines, sor)
if llm.ppid and callerorgid != llm.ownerid: if llm.ppid and callerorgid != llm.ownerid:
debug(f'{usage=},{llm.ownerid=},{callerorgid=}')
await llm_accounting(request, llm.id, usage, callerorgid, callerid) await llm_accounting(request, llm.id, usage, callerorgid, callerid)
d = rzt d = rzt

Binary file not shown.

View File

@ -1,3 +1,4 @@
{% set userorgid = get_userorgid %}
{ {
"widgettype":"VScrollPanel", "widgettype":"VScrollPanel",
"options":{ "options":{
@ -28,10 +29,14 @@
}, },
"subwidgets":[ "subwidgets":[
{% for llm in get_llms_by_catelog(cate.id) %} {% for llm in get_llms_by_catelog(cate.id) %}
{% set can_use = checkCustomerBalance(llm.id, userorgid) %}
{ {
"widgettype":"VScrollPanel", "widgettype":"VScrollPanel",
"options":{ "options":{
"css":"card", "css":"card",
{% if not can_use %}
"disabled":true,
{% endif %}
"bgcolor": "#def0f0", "bgcolor": "#def0f0",
"cwidth":20, "cwidth":20,
"cheight":12 "cheight":12