45 lines
1.5 KiB
Plaintext
45 lines
1.5 KiB
Plaintext
# 可写入/更新的字段(不含 id、created_at、updated_at)
|
||
_MODEL_FIELDS = (
|
||
'llmid', 'provider', 'model_name', 'display_name', 'model_type',
|
||
'context_length', 'input_token_price', 'output_token_price',
|
||
'cache_hit_input_price', 'billing_method', 'billing_unit',
|
||
'capabilities', 'limitations', 'highlights', 'is_active',
|
||
'description', 'listing_status',
|
||
)
|
||
|
||
|
||
def _escape(value):
|
||
if value is None:
|
||
return None
|
||
return str(value).replace("'", "''")
|
||
|
||
|
||
def _build_model_dict(ns, include_listing_status=False):
|
||
data = {}
|
||
for field in _MODEL_FIELDS:
|
||
if field in ns and ns.get(field) is not None and ns.get(field) != '':
|
||
data[field] = ns.get(field)
|
||
if include_listing_status and 'listing_status' not in data:
|
||
data['listing_status'] = ns.get('listing_status', 0)
|
||
return data
|
||
|
||
async def model_management_update(ns={}):
|
||
"""编辑模型,id 必传"""
|
||
model_id = ns.get('id')
|
||
if not model_id:
|
||
return {'status': False, 'msg': 'id is required'}
|
||
|
||
ns_dic = _build_model_dict(ns)
|
||
ns_dic['id'] = model_id
|
||
|
||
db = DBPools()
|
||
async with db.sqlorContext('kboss') as sor:
|
||
try:
|
||
await sor.U('model_management', ns_dic)
|
||
return {'status': True, 'msg': 'update model success'}
|
||
except Exception as e:
|
||
await sor.rollback()
|
||
return {'status': False, 'msg': 'update model failed, %s' % str(e)}
|
||
|
||
ret = await model_management_update(params_kw)
|
||
return ret |