bugfix
This commit is contained in:
parent
84f6c27cbb
commit
1eced06197
@ -7,15 +7,14 @@ 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 ahserver.serverenv import ServerEnv
|
||||||
# from pricing.pricing import pricing_program_charging
|
|
||||||
from accounting.consume import consume_accounting
|
from accounting.consume import consume_accounting
|
||||||
from accounting.getaccount import getCustomerBalance
|
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.usages)
|
prices = await env.pbuffered_chargin(ppid, llmusage.usages)
|
||||||
if prices is None:
|
if prices is None:
|
||||||
e = Exception(f'{ppid=}, {llmusage.usage=}{llmusage.id=} env.pricing_program_charging() return None')
|
e = Exception(f'{ppid=}, {llmusage.usage=}{llmusage.id=} env.buffered_charging() return None')
|
||||||
exception(f'{e}')
|
exception(f'{e}')
|
||||||
raise e
|
raise e
|
||||||
return None
|
return None
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from .keling import keling_token
|
|||||||
from .jimeng import jimeng_auth_headers
|
from .jimeng import jimeng_auth_headers
|
||||||
from .utils import (
|
from .utils import (
|
||||||
llm_query_orders,
|
llm_query_orders,
|
||||||
|
llm_query_price,
|
||||||
get_llm_by_model
|
get_llm_by_model
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,7 +16,6 @@ from .llmclient import (
|
|||||||
get_llm,
|
get_llm,
|
||||||
inference_generator,
|
inference_generator,
|
||||||
inference,
|
inference,
|
||||||
llm_query_price,
|
|
||||||
get_llmproviders,
|
get_llmproviders,
|
||||||
get_llms_sort_by_provider,
|
get_llms_sort_by_provider,
|
||||||
get_llmcatelogs,
|
get_llmcatelogs,
|
||||||
|
|||||||
@ -177,19 +177,3 @@ async def inference(request, *args, params_kw=None, **kw):
|
|||||||
f = partial(inference_generator, request, *args, params_kw=params_kw, **kw)
|
f = partial(inference_generator, request, *args, params_kw=params_kw, **kw)
|
||||||
return await env.stream_response(request, f)
|
return await env.stream_response(request, f)
|
||||||
|
|
||||||
async def llm_query_price(llmid, config_data):
|
|
||||||
env = ServerEnv()
|
|
||||||
async with get_sor_context(env, 'llmage') as sor:
|
|
||||||
llms = await sor.R('llm', {'id': llmid})
|
|
||||||
if not llms:
|
|
||||||
e = Exception(f'id={llmid} llm not founnd')
|
|
||||||
exception(f'{e}')
|
|
||||||
raise e
|
|
||||||
llm = llms[0]
|
|
||||||
if llm.ppid is None:
|
|
||||||
e = Exception(f'{llm=} ppid is None')
|
|
||||||
exception(f'{e}')
|
|
||||||
raise e
|
|
||||||
prices = await env.pricing_program_charging(sor, llm.ppid, config_data)
|
|
||||||
return prices
|
|
||||||
|
|
||||||
|
|||||||
@ -160,19 +160,25 @@ where a.llmcatelogid = b.id
|
|||||||
return d
|
return d
|
||||||
return []
|
return []
|
||||||
|
|
||||||
async def get_llm(llmid):
|
class BufferedLLMs:
|
||||||
db = DBPools()
|
lls = {}
|
||||||
dbname = get_serverenv('get_module_dbname')('llmage')
|
async def get_llm(self, llmid):
|
||||||
async with db.sqlorContext(dbname) as sor:
|
|
||||||
today = curDateString()
|
today = curDateString()
|
||||||
|
k = f'{llmid}.{today}'
|
||||||
|
d = BufferedLLMs.llms.get(k)
|
||||||
|
if d:
|
||||||
|
return d
|
||||||
|
env = ServerEnv()
|
||||||
|
async with get_sor_context(env, 'llmage') as sor:
|
||||||
sql = """select x.*,
|
sql = """select x.*,
|
||||||
z.input_fields
|
z.input_fields
|
||||||
from (
|
from (
|
||||||
select a.*, e.ioid, e.callbackurl, e.stream
|
select a.*, e.ioid, e.callbackurl, e.stream, f.input_fields as inputfields
|
||||||
from llm a, upapp c, uapiset d, uapi e
|
from llm a, upapp c, uapiset d, uapi e, uapiio f
|
||||||
where a.upappid = c.id
|
where a.upappid = c.id
|
||||||
and c.apisetid = d.id
|
and c.apisetid = d.id
|
||||||
and e.apisetid = d.id
|
and e.apisetid = d.id
|
||||||
|
and e.ioid = f.id
|
||||||
and a.apiname = e.name
|
and a.apiname = e.name
|
||||||
and a.expired_date > ${today}$
|
and a.expired_date > ${today}$
|
||||||
and a.enabled_date <= ${today}$
|
and a.enabled_date <= ${today}$
|
||||||
@ -183,19 +189,27 @@ where x.id = ${llmid}$
|
|||||||
recs = await sor.sqlExe(sql, ns.copy())
|
recs = await sor.sqlExe(sql, ns.copy())
|
||||||
if len(recs) > 0:
|
if len(recs) > 0:
|
||||||
r = recs[0]
|
r = recs[0]
|
||||||
api = await sor_get_uapi(sor, r.upappid, r.apiname)
|
dates = BufferedLLMs.llms.get(llmid, [])
|
||||||
if api is None:
|
dates.append(today)
|
||||||
e = Exception(f'{r.upappid=},{r.apiname=} uapi not found')
|
cnt = len(dates)
|
||||||
exception(f'{e=}\n{format_exc()}')
|
if cnt > 2:
|
||||||
raise e
|
for i in range(0, cnt -2)
|
||||||
r.inputfields = api.input_fields
|
dat = dates[i]
|
||||||
return recs[0]
|
del BufferedLLMs.llms[f'{llmid}.{dat}']
|
||||||
|
dates = dates[-2:]
|
||||||
|
BufferedLLMs.llms[llmid] = dates
|
||||||
|
BufferedLLMs.llms[k] = r
|
||||||
|
return r
|
||||||
else:
|
else:
|
||||||
debug(f'{llmid=} not found, {ns=}, {sql=}')
|
debug(f'{llmid=} not found, {ns=}, {sql=}')
|
||||||
return None
|
return None
|
||||||
exception(f'{db.e_except}\n{format_exc()}')
|
exception(f'Error: format_exc()}')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
async def get_llm(llmid):
|
||||||
|
bllms = BufferedLLMs()
|
||||||
|
return await bllms.get_llm(llmid)
|
||||||
|
|
||||||
async def get_owner_userid(sor, llm):
|
async def get_owner_userid(sor, llm):
|
||||||
sql = '''select a.ownerid as userid from upappkey a, upapp b
|
sql = '''select a.ownerid as userid from upappkey a, upapp b
|
||||||
where a.upappid=b.id
|
where a.upappid=b.id
|
||||||
@ -210,3 +224,13 @@ async def write_llmusage(llmusage):
|
|||||||
async with get_sor_context(env, 'llmage') as sor:
|
async with get_sor_context(env, 'llmage') as sor:
|
||||||
await sor.C('llmusage', llmusage)
|
await sor.C('llmusage', llmusage)
|
||||||
|
|
||||||
|
async def llm_query_price(llmid, config_data):
|
||||||
|
env = ServerEnv()
|
||||||
|
llm = await get_llm(llmid)
|
||||||
|
if llm.ppid is None:
|
||||||
|
e = Exception(f'{llm=} ppid is None')
|
||||||
|
exception(f'{e}')
|
||||||
|
raise e
|
||||||
|
prices = await env.buffered_charging(llm.ppid, config_data)
|
||||||
|
return prices
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user