78 lines
2.4 KiB
Plaintext
78 lines
2.4 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
for k,v in list(ns.items()):
|
|
if v == 'NaN' or v == 'null' or v == '' or v is None:
|
|
if k != 'id':
|
|
del ns[k]
|
|
else:
|
|
ns[k] = None if v in ('NaN', 'null') else v
|
|
|
|
|
|
userorgid = await get_userorgid()
|
|
if not userorgid:
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"Authorization Error",
|
|
"timeout":3,
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"message":"Please login"
|
|
}
|
|
}
|
|
ns['userorgid'] = userorgid
|
|
|
|
|
|
|
|
|
|
db = DBPools()
|
|
dbname = get_module_dbname('llmage')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
|
|
ns1 = {
|
|
|
|
"userorgid": userorgid,
|
|
|
|
|
|
"id": params_kw.id
|
|
}
|
|
recs = await sor.R('llm_metrics', ns1)
|
|
if len(recs) < 1:
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"Update Error",
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"timeout":3,
|
|
"message":"Record no exist or with wrong ownership"
|
|
}
|
|
}
|
|
|
|
tblfields = json.loads('[{"name":"id","title":"id","type":"str","length":32},{"name":"userid","title":"用户id","type":"str","length":32},{"name":"userorgid","title":"用户机构","type":"str","length":32},{"name":"llmid","title":"模型","type":"str","length":32},{"name":"use_date","title":"使用日期","type":"date"},{"name":"use_time","title":"使用时间","type":"timestamp"},{"name":"input_tokens","title":"输入tokens","type":"int","default":"0"},{"name":"output_tokens","title":"输出tokens","type":"int","default":"0"},{"name":"total_tokens","title":"总tokens","type":"int","default":"0"},{"name":"amount","title":"金额","type":"float","length":18,"dec":4,"default":"0"},{"name":"responsed_seconds","title":"响应时长(秒)","type":"float","length":18,"dec":2,"nullable":true},{"name":"finish_seconds","title":"完成时长(秒)","type":"float","length":18,"dec":2,"nullable":true},{"name":"status","title":"状态","type":"str","length":32,"nullable":true},{"name":"taskid","title":"任务号","type":"str","length":32,"nullable":true}]')
|
|
tblfname = [ f['name'] for f in tblfields ]
|
|
other_keys = [ k for k in ns.keys() if k in tblfname and k != 'id' ]
|
|
if len(other_keys) > 0:
|
|
r = await sor.U('llm_metrics', ns)
|
|
debug('update success');
|
|
return {
|
|
"widgettype":"Message",
|
|
"options":{
|
|
"title":"Update Success",
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"timeout":3,
|
|
"message":"ok"
|
|
}
|
|
}
|
|
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"Update Error",
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"timeout":3,
|
|
"message":"failed"
|
|
}
|
|
} |