sage/wwwroot/dialog/list_mti_models.dspy
2025-07-16 14:28:41 +08:00

73 lines
2.0 KiB
Plaintext

ns = params_kw.copy()
if page not in ns.keys():
ns['page'] = 1
ns['sort'] = 'name'
debug(f'list_mti_models.dspy:{ns=}')
sql = """
select a.*,
b.name,
b.title,
b.icon_url,
b.providerid,
c.modeltypeid,
e.input_fields,
e.input_view,
e.output_view,
e.name as modeltypename,
d.use_session,
d.response_mode,
d.system_msg_format,
d.user_msg_format,
d.llm_msg_format,
d.apiinfo
from modelinstance a, models b, modelapi c, httpapi d, modeltype e
where
c.modeltypeid = e.id
and a.modelid = c.modelid
and a.modelid = b.id
and c.apiid = d.id
and a.id != ${mii}$
and c.modeltypeid = ${mti}$
"""
db = DBPools()
async with db.sqlorContext('sage') as sor:
sql = """select a.*, b.modeltypeid from modelinstance a, modelapi b
where
a.modelid = b.modelid and
a.orgid is null and
a.id != ${mii}$ and
b.modeltypeid = ${mti}$
"""
recs = await sor.sqlPaging(sql, ns.copy())
models = []
for row in recs['rows']:
output_view = json.loads(row.output_view) \
if row.output_view else None;
model = {
"id":row.id,
"name":row.name,
"description":row.description,
"enable_date":row.enable_date,
"modelinstanceid":row.id,
"modeltypeid":row.modeltypeid,
"output_view":row.output_view,
"use_session":True if row.use_session == '1' else False,
"input_from":"userinput",
"response_mode":row.response_mode,
"system_message_format":{'role':'system', 'content':'${content}'} if row.system_msg_format is None or row.system_msg_format == '' else json.loads(row.system_msg_format),
"user_message_format":None if row.user_msg_format is None or row.user_msg_format == '' else json.loads(row.user_msg_format),
"llm_message_format":{'role':'assistant', 'content':'${content}'} if row.llm_msg_format is None or row.llm_msg_format == '' else json.loads(row.llm_msg_format),
"icon":entire_url(row.icon_url or '/imgs/ollama.png'),
"url":entire_url('/llm/universe_llm.dspy'),
"model":row.name
}
models.append(model)
return {
"total":recs['total'],
"rows":models
}
return {
"total":0,
"rows":[]
}