48 lines
1.7 KiB
Plaintext
48 lines
1.7 KiB
Plaintext
# 复制API配置:从源llm复制所有llm_api_map记录到目标llm
|
||
result = {'widgettype':'Message','options':{'title':'Error','message':'','timeout':3}}
|
||
|
||
try:
|
||
from_llmid = params_kw.get('from_llmid')
|
||
to_llmid = params_kw.get('to_llmid')
|
||
|
||
if not from_llmid or not to_llmid:
|
||
raise Exception('请选择源模型和目标模型')
|
||
if from_llmid == to_llmid:
|
||
raise Exception('源模型和目标模型不能相同')
|
||
|
||
dbname = get_module_dbname('llmage')
|
||
|
||
async with DBPools().sqlorContext(dbname) as sor:
|
||
# 删除目标已有的映射
|
||
await sor.sqlExe("DELETE FROM llm_api_map WHERE llmid=${id}$", {'id': to_llmid})
|
||
|
||
# 复制源的所有映射到目标
|
||
src_sql = "SELECT * FROM llm_api_map WHERE llmid=${id}$"
|
||
src_recs = await sor.sqlExe(src_sql, {'id': from_llmid})
|
||
|
||
count = 0
|
||
for r in src_recs or []:
|
||
await sor.C('llm_api_map', {
|
||
'id': getID(),
|
||
'llmid': to_llmid,
|
||
'llmcatelogid': r.llmcatelogid,
|
||
'apiname': r.apiname,
|
||
'query_apiname': r.query_apiname or '',
|
||
'query_period': r.query_period or 30,
|
||
'ppid': r.ppid or '',
|
||
'isdefaultcatelog': r.isdefaultcatelog or '0',
|
||
})
|
||
count += 1
|
||
|
||
result = {'widgettype':'Message','options':{
|
||
'title':'复制完成','message':f'已复制{count}条API配置','timeout':3,'type':'success'
|
||
}}
|
||
|
||
except Exception as e:
|
||
debug(f'copy_api error: {format_exc()}')
|
||
result = {'widgettype':'Message','options':{
|
||
'title':'复制失败','message':str(e),'timeout':5,'type':'error'
|
||
}}
|
||
|
||
return result
|