llmage/wwwroot/llm_api_map/get_llm_api_map.dspy

98 lines
2.5 KiB
Plaintext

ns = params_kw.copy()
debug_params('get_llm_api_map', ns)
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = 'id'
sql = '''select a.*, b.llmid_text, c.llmcatelogid_text, d.ppid_text
from (select * from llm_api_map where 1=1 [[filterstr]]) a left join (select id as llmid,
name as llmid_text from llm where 1 = 1) b on a.llmid = b.llmid left join (select id as llmcatelogid,
name as llmcatelogid_text from llmcatelog where 1 = 1) c on a.llmcatelogid = c.llmcatelogid left join (select id as ppid,
name as ppid_text from pricing_program where 1 = 1) d on a.ppid = d.ppid'''
filterjson = params_kw.get('data_filter')
fields_str=r'''[
{
"name": "id",
"type": "varchar(32)",
"not_null": true,
"title": "主键ID"
},
{
"name": "llmid",
"type": "varchar(32)",
"not_null": true,
"title": "模型ID"
},
{
"name": "llmcatelogid",
"type": "varchar(32)",
"not_null": true,
"title": "模型分类ID"
},
{
"name": "apiname",
"type": "varchar(100)",
"not_null": true,
"title": "接口名称"
},
{
"name": "query_apiname",
"type": "varchar(100)",
"title": "任务结果查询接口名称"
},
{
"name": "query_period",
"type": "bigint",
"default": 30,
"title": "任务查询间隔(秒)"
},
{
"name": "ppid",
"type": "varchar(32)",
"title": "定价ID"
},
{
"name": "isdefaultcatelog",
"type": "varchar(1)",
"not_null": true,
"title": "缺省分类"
}
]'''
ori_fields = json.loads(fields_str)
if not filterjson:
fields = [ f['name'] for f in ori_fields ]
filterjson = default_filterjson(fields, ns)
filterdic = ns.copy()
filterdic['filterstr'] = ''
filterdic['userorgid'] = '${userorgid}$'
filterdic['userid'] = '${userid}$'
if filterjson:
dbf = DBFilter(filterjson)
conds = dbf.gen(ns)
if conds:
ns.update(dbf.consts)
conds = f' and {conds}'
filterdic['filterstr'] = conds
ac = ArgsConvert('[[', ']]')
vars = ac.findAllVariables(sql)
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
filterdic.update(NameSpace)
sql = ac.convert(sql, filterdic)
debug(f'sql({len(sql)}ch): {sql[:200]}')
db = DBPools()
dbname = get_module_dbname('llm')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}