140 lines
6.0 KiB
Plaintext
140 lines
6.0 KiB
Plaintext
"""
|
|
MiniMax-H3 complete setup: uapi + pricing
|
|
POST /uapi/api/minimax_h3_setup.dspy
|
|
Body: {"apikey": "YOUR_MINIMAX_API_KEY"}
|
|
"""
|
|
import json
|
|
|
|
async def main():
|
|
dbname = env.get_module_dbname('uapi')
|
|
pricing_dbname = env.get_module_dbname('pricing')
|
|
db = DBPools()
|
|
results = {}
|
|
|
|
# ============================================================
|
|
# PART 1: UAPI records
|
|
# ============================================================
|
|
async with db.sqlorContext(dbname) as sor:
|
|
uapiio_id = 'm_h3_video_gen_io'
|
|
|
|
# uapiio
|
|
existing = await sor.R('uapiio', {'id': uapiio_id})
|
|
if not existing:
|
|
await sor.C('uapiio', {
|
|
'id': uapiio_id,
|
|
'name': 'MiniMax-H3 视频生成',
|
|
'description': 'MiniMax-H3 视频生成v2接口。支持文生视频、图生视频(首尾帧)、多模态参考生视频。',
|
|
'input_fields': json.dumps({
|
|
"model": {"type": "string", "required": True, "title": "模型名称", "enum": ["MiniMax-H3"]},
|
|
"content": {"type": "array", "required": True, "title": "多模态输入内容"},
|
|
"resolution": {"type": "string", "required": True, "title": "分辨率", "enum": ["768P", "2K"]},
|
|
"duration": {"type": "integer", "required": True, "title": "时长(秒)", "enum": [4,5,6,7,8,9,10,11,12,13,14,15]},
|
|
"ratio": {"type": "string", "title": "宽高比", "enum": ["adaptive","21:9","16:9","4:3","1:1","3:4","9:16"]},
|
|
}, ensure_ascii=False)
|
|
})
|
|
results['uapiio'] = 'created'
|
|
else:
|
|
results['uapiio'] = 'exists'
|
|
|
|
# uapi - create
|
|
cid = 'm_h3_create_task'
|
|
if not await sor.R('uapi', {'id': cid}):
|
|
await sor.C('uapi', {
|
|
'id': cid, 'upappid': 'minimax', 'name': 'video_generation_v2',
|
|
'title': 'MiniMax-H3 创建视频任务', 'description': '创建 MiniMax-H3 视频生成任务',
|
|
'need_auth': '0', 'stream': 'async', 'path': '/v2/video_generation',
|
|
'httpmethod': 'POST', 'chunk_match': 'task_id',
|
|
'headers': '{"Content-Type": "application/json", "Authorization": "Bearer {{apikey}}"}',
|
|
'data': '{{jsondata}}', 'response': '{{response}}', 'ioid': uapiio_id,
|
|
})
|
|
results['uapi_create'] = 'created'
|
|
else:
|
|
results['uapi_create'] = 'exists'
|
|
|
|
# uapi - query
|
|
qid = 'm_h3_query_task'
|
|
if not await sor.R('uapi', {'id': qid}):
|
|
await sor.C('uapi', {
|
|
'id': qid, 'upappid': 'minimax', 'name': 'query_video_generation',
|
|
'title': 'MiniMax-H3 查询视频任务', 'description': '按task_id查询任务状态',
|
|
'need_auth': '0', 'stream': 'sync', 'path': '/v2/query/video_generation/{{task_id}}',
|
|
'httpmethod': 'GET', 'chunk_match': '',
|
|
'headers': '{"Authorization": "Bearer {{apikey}}"}',
|
|
'data': None, 'response': '{{response}}', 'ioid': uapiio_id,
|
|
})
|
|
results['uapi_query'] = 'created'
|
|
else:
|
|
results['uapi_query'] = 'exists'
|
|
|
|
# upapp
|
|
if not await sor.R('upapp', {'id': 'minimax'}):
|
|
await sor.C('upapp', {
|
|
'id': 'minimax', 'name': 'minimax', 'baseurl': 'https://api.minimax.chat',
|
|
'myappid': 'minimax', 'ownerid': 'platform',
|
|
'description': 'MiniMax 视频生成平台。提供 H3 视频生成模型。',
|
|
})
|
|
results['upapp'] = 'created'
|
|
else:
|
|
results['upapp'] = 'exists'
|
|
|
|
# upappkey
|
|
apikey_val = params_kw.get('apikey', '')
|
|
if apikey_val:
|
|
existing = await sor.R('upappkey', {'id': 'mk_minimax_default'})
|
|
if not existing:
|
|
await sor.C('upappkey', {
|
|
'id': 'mk_minimax_default', 'upappid': 'minimax', 'orgid': 'platform',
|
|
'apikey': env.password_encode(apikey_val),
|
|
'enabled_date': '2025-01-01', 'expired_date': '9999-12-31',
|
|
})
|
|
results['upappkey'] = 'created'
|
|
else:
|
|
results['upappkey'] = 'exists'
|
|
else:
|
|
results['upappkey'] = 'skipped (no apikey)'
|
|
|
|
# ============================================================
|
|
# PART 2: Pricing records
|
|
# ============================================================
|
|
async with db.sqlorContext(pricing_dbname) as sor:
|
|
# Inspect table structure
|
|
cols = await sor.I('pricing_program')
|
|
results['pp_cols'] = [c.get('Field') + ' ' + c.get('Type') for c in cols[:15]]
|
|
|
|
# Insert 2 pricing programs: 2K and 768P
|
|
programs = [
|
|
{
|
|
'id': 'minimax_h3_2k',
|
|
'name': 'MiniMax-H3-2K',
|
|
'description': 'MiniMax-H3 2K分辨率视频生成',
|
|
'unit': 'second',
|
|
'unit_price': 0.80,
|
|
'currency': 'CNY',
|
|
'category': 'video_generation',
|
|
'provider': 'minimax',
|
|
'model': 'MiniMax-H3',
|
|
'resolution': '2K',
|
|
},
|
|
{
|
|
'id': 'minimax_h3_768p',
|
|
'name': 'MiniMax-H3-768P',
|
|
'description': 'MiniMax-H3 768P分辨率视频生成',
|
|
'unit': 'second',
|
|
'unit_price': 0.50,
|
|
'currency': 'CNY',
|
|
'category': 'video_generation',
|
|
'provider': 'minimax',
|
|
'model': 'MiniMax-H3',
|
|
'resolution': '768P',
|
|
},
|
|
]
|
|
for prog in programs:
|
|
existing = await sor.R('pricing_program', {'id': prog['id']})
|
|
if not existing:
|
|
await sor.C('pricing_program', prog)
|
|
results['pricing_' + prog['id']] = 'created'
|
|
else:
|
|
results['pricing_' + prog['id']] = 'exists'
|
|
|
|
return {'status': 'ok', 'results': results}
|