bugfix
This commit is contained in:
parent
dd304972b5
commit
59587a8c31
@ -5,21 +5,21 @@
|
|||||||
#
|
#
|
||||||
# Example request:
|
# Example request:
|
||||||
# {
|
# {
|
||||||
# "model": "keling-2.1",
|
# "model": "keling-2.1",
|
||||||
# "catelogid": "t2v",
|
# "catelogid": "t2v",
|
||||||
# "prompt": "A beautiful sunset over the ocean",
|
# "prompt": "A beautiful sunset over the ocean",
|
||||||
# "duration": "5s",
|
# "duration": "5s",
|
||||||
# "resolution": "1080p"
|
# "resolution": "1080p"
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# Response (async task):
|
# Response (async task):
|
||||||
# {
|
# {
|
||||||
# "id": "vid_xxx",
|
# "id": "vid_xxx",
|
||||||
# "object": "video.generation",
|
# "object": "video.generation",
|
||||||
# "model": "keling-2.1",
|
# "model": "keling-2.1",
|
||||||
# "status": "submitted",
|
# "status": "submitted",
|
||||||
# "taskid": "task_xxx",
|
# "taskid": "task_xxx",
|
||||||
# "created": 1234567890
|
# "created": 1234567890
|
||||||
# }
|
# }
|
||||||
|
|
||||||
import json
|
import json
|
||||||
@ -36,41 +36,41 @@ debug_params('params_kw', params_kw)
|
|||||||
userid = await get_user()
|
userid = await get_user()
|
||||||
userorgid = await get_userorgid()
|
userorgid = await get_userorgid()
|
||||||
if userid is None:
|
if userid is None:
|
||||||
debug('need login')
|
debug('need login')
|
||||||
return openai_403()
|
return openai_403()
|
||||||
|
|
||||||
# Validate required parameters
|
# Validate required parameters
|
||||||
if not params_kw.model:
|
if not params_kw.model:
|
||||||
d = return_error('Missing required parameter: model')
|
d = return_error('Missing required parameter: model')
|
||||||
return json_response(d, status=400)
|
return json_response(d, status=400)
|
||||||
|
|
||||||
if not params_kw.catelogid:
|
if not params_kw.catelogid:
|
||||||
d = return_error('Missing required parameter: catelogid')
|
d = return_error('Missing required parameter: catelogid')
|
||||||
return json_response(d, status=400)
|
return json_response(d, status=400)
|
||||||
|
|
||||||
if not params_kw.prompt:
|
if not params_kw.prompt:
|
||||||
d = return_error('Missing required parameter: prompt')
|
d = return_error('Missing required parameter: prompt')
|
||||||
return json_response(d, status=400)
|
return json_response(d, status=400)
|
||||||
|
|
||||||
lctype = params_kw.catelogid
|
lctype = params_kw.catelogid
|
||||||
|
|
||||||
env = request._run_ns
|
env = request._run_ns
|
||||||
async with get_sor_context(env, 'llmage') as sor:
|
async with get_sor_context(env, 'llmage') as sor:
|
||||||
# Look up llm by model name and catalog type through llm_api_map
|
# Look up llm by model name and catalog type through llm_api_map
|
||||||
sql = """select distinct a.* from llm a
|
sql = """select distinct a.* from llm a
|
||||||
join llm_api_map m on a.id = m.llmid
|
join llm_api_map m on a.id = m.llmid
|
||||||
join llmcatelog b on m.llmcatelogid = b.id
|
join llmcatelog b on m.llmcatelogid = b.id
|
||||||
where (b.id = ${lctype}$ OR b.name = ${lctype}$)
|
where (b.id = ${lctype}$ OR b.name = ${lctype}$)
|
||||||
and a.model=${model}$
|
and a.model=${model}$
|
||||||
and a.status = 'published'"""
|
and a.status = 'published'"""
|
||||||
recs = await sor.sqlExe(sql, {
|
recs = await sor.sqlExe(sql, {
|
||||||
'lctype': lctype,
|
'lctype': lctype,
|
||||||
'model': params_kw.model
|
'model': params_kw.model
|
||||||
})
|
})
|
||||||
if len(recs) == 0:
|
if len(recs) == 0:
|
||||||
debug(f'{params_kw.model=} not found for catalog {lctype}')
|
debug(f'{params_kw.model=} not found for catalog {lctype}')
|
||||||
return openai_400()
|
return openai_400()
|
||||||
params_kw.llmid = recs[0].id
|
params_kw.llmid = recs[0].id
|
||||||
params_kw.llmcatelogid = lctype
|
params_kw.llmcatelogid = lctype
|
||||||
|
|
||||||
debug(f'{params_kw.llmid=}')
|
debug(f'{params_kw.llmid=}')
|
||||||
@ -78,12 +78,12 @@ debug(f'{params_kw.llmid=}')
|
|||||||
# Check balance
|
# Check balance
|
||||||
f = await checkCustomerBalance(params_kw.llmid, userid, userorgid)
|
f = await checkCustomerBalance(params_kw.llmid, userid, userorgid)
|
||||||
if not f:
|
if not f:
|
||||||
debug(f'{userid=} balance not enough')
|
debug(f'{userid=} balance not enough')
|
||||||
return openai_429()
|
return openai_429()
|
||||||
|
|
||||||
# Generate task ID and attach to params
|
# Generate task ID and attach to params
|
||||||
if not params_kw.transno:
|
if not params_kw.transno:
|
||||||
params_kw.transno = getID()
|
params_kw.transno = getID()
|
||||||
|
|
||||||
# Call inference (video/image generation is typically async via callback)
|
# Call inference (video/image generation is typically async via callback)
|
||||||
return await inference(request, env=env)
|
return await inference(request, env=env)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user