bugfix
This commit is contained in:
parent
444efd7a52
commit
9697b9c16c
@ -8,6 +8,7 @@ from llmage.llmclient import (
|
||||
get_llm,
|
||||
inference_generator,
|
||||
inference,
|
||||
llm_query_price,
|
||||
get_llmproviders,
|
||||
get_llms_sort_by_provider,
|
||||
get_llmcatelogs,
|
||||
@ -29,6 +30,6 @@ def load_llmage():
|
||||
env.get_llmproviders = get_llmproviders
|
||||
env.get_llms_sort_by_provider = get_llms_sort_by_provider
|
||||
env.keling_token = keling_token
|
||||
|
||||
env.llm_query_price = llm_query_price
|
||||
rf = RegisterFunction()
|
||||
rf.register('jimeng_auth_headers', jimeng_auth_headers)
|
||||
|
||||
@ -425,3 +425,18 @@ async def inference(request, *args, params_kw=None, **kw):
|
||||
f = partial(inference_generator, request, *args, params_kw=params_kw, **kw)
|
||||
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 = env.pricing_program_charging(sor, llm.ppid, config_data)
|
||||
return prices
|
||||
|
||||
@ -3,5 +3,40 @@ product_id:
|
||||
product_type: llm
|
||||
config_data:
|
||||
"""
|
||||
|
||||
product_id = params_kw.product_id
|
||||
if product_id is None:
|
||||
return {
|
||||
"status": "error",
|
||||
"data": {
|
||||
"message": "need a llmid"
|
||||
}
|
||||
}
|
||||
config_data = params_kw.config_data
|
||||
if config_data is None:
|
||||
return {
|
||||
"status": "error",
|
||||
"data": {
|
||||
"message": "need a config_data"
|
||||
}
|
||||
}
|
||||
try:
|
||||
prices = llm_query_price(product_id, config_data)
|
||||
amount = 0
|
||||
for p in prices:
|
||||
amount += p.amount
|
||||
return {
|
||||
"status": "ok",
|
||||
"data": {
|
||||
"price": amount
|
||||
}
|
||||
}
|
||||
except Exception as e:
|
||||
msg = f'{product_id=}, {config_data=}, {e=}'
|
||||
exception(msg)
|
||||
return {
|
||||
"status": "error",
|
||||
"data": {
|
||||
"message": msg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user