- utils.py: get_llmage_llm - when catelogid provided, use it instead of forcing isdefaultcatelog=1 - list_paging_catelog_llms.dspy: handle missing llmid in SQL, add llmcatelogid to returned rows - llm_dialog.ui: use Jinja2 namespace for variable scoping in for loop
55 lines
1.6 KiB
Plaintext
55 lines
1.6 KiB
Plaintext
if int(params_kw._is_mobile) == 1:
|
|
pagerows = 80
|
|
else:
|
|
pagerows = 260
|
|
page = int(params_kw.get('page', 1))
|
|
dbname = get_module_dbname('llmage')
|
|
db = DBPools()
|
|
async with db.sqlorContext(dbname) as sor:
|
|
# If llmcatelogid not provided, derive it from llmid via llm_api_map
|
|
llmcatelogid = params_kw.get('llmcatelogid')
|
|
if not llmcatelogid:
|
|
llmid = params_kw.get('llmid')
|
|
if llmid:
|
|
recs = await sor.sqlExe("select llmcatelogid from llm_api_map where llmid=${llmid}$ limit 1", {'llmid': llmid})
|
|
if recs:
|
|
llmcatelogid = recs[0].llmcatelogid
|
|
if not llmcatelogid:
|
|
return {}
|
|
params_kw.llmcatelogid = llmcatelogid
|
|
sql = """select x.*,
|
|
z.input_fields,
|
|
y.system_message,
|
|
y.user_message,
|
|
y.assisant_message
|
|
from (
|
|
select distinct a.*, b.hfid, e.ioid, e.stream
|
|
from llm a
|
|
join llm_api_map m on a.id = m.llmid
|
|
join llmcatelog b on m.llmcatelogid = b.id
|
|
join upapp c on a.upappid = c.id
|
|
join uapi e on c.id = e.upappid and m.apiname = e.name
|
|
where a.status = 'published'
|
|
and m.llmcatelogid = ${llmcatelogid}$
|
|
) x left join historyformat y on x.hfid = y.id
|
|
left join uapiio z on x.ioid = z.id
|
|
where 1=1
|
|
"""
|
|
llmid = params_kw.get('llmid')
|
|
if llmid:
|
|
sql += " and x.id != ${llmid}$"
|
|
ns = params_kw.copy()
|
|
ns.page = page
|
|
ns.pagerows = pagerows
|
|
recs = await sor.sqlPaging(sql, ns)
|
|
for r in recs.get('rows', []):
|
|
r.llmid = r.id
|
|
r.llmcatelogid = llmcatelogid
|
|
r.modelname = r.name
|
|
r.description = ''.join(''.join(r.description.split('\n')).split('\r'))
|
|
r.response_mode = r.stream
|
|
r.icon = entire_url('/appbase/show_icon.dspy') + f'?id={r.iconid}'
|
|
r.url = entire_url('/llmage/llminference.dspy')
|
|
return recs
|
|
return {}
|