From 4d455da18c162267445583469e3f9389daca781e Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 11 Jun 2026 19:29:22 +0800 Subject: [PATCH] fix: catelog selection logic and backward compatibility - 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 --- llmage/utils.py | 9 +++++++-- wwwroot/list_paging_catelog_llms.dspy | 6 +++++- wwwroot/llm_dialog.ui | 22 +++++++++++----------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/llmage/utils.py b/llmage/utils.py index 2bfc334..5a5fb72 100644 --- a/llmage/utils.py +++ b/llmage/utils.py @@ -258,9 +258,14 @@ where 1=1 """ ns = {} if llmid: - sql += " and a.id = ${llmid}$ and m.isdefaultcatelog = '1'" + sql += " and a.id = ${llmid}$" ns['llmid'] = llmid - if catelogid: + if catelogid: + sql += " and m.llmcatelogid = ${catelogid}$" + ns['catelogid'] = catelogid + else: + sql += " and m.isdefaultcatelog = '1'" + elif catelogid: sql += " and m.llmcatelogid = ${catelogid}$" ns['catelogid'] = catelogid sql += " order by m.llmcatelogid, a.id" diff --git a/wwwroot/list_paging_catelog_llms.dspy b/wwwroot/list_paging_catelog_llms.dspy index beeab80..090ba2c 100644 --- a/wwwroot/list_paging_catelog_llms.dspy +++ b/wwwroot/list_paging_catelog_llms.dspy @@ -33,14 +33,18 @@ 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 x.id != ${llmid}$ +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 diff --git a/wwwroot/llm_dialog.ui b/wwwroot/llm_dialog.ui index aa1751d..a04a083 100644 --- a/wwwroot/llm_dialog.ui +++ b/wwwroot/llm_dialog.ui @@ -4,12 +4,12 @@ {% if params_kw.id %} {% if checkCustomerBalance(params_kw.id, userid, userorgid) %} {% set catelogs = get_llm_catelogs(params_kw.id) %} -{% set active_catelogid = params_kw.get('catelogid', '') %} -{% if not active_catelogid and catelogs %} -{% for c in catelogs %}{% if c.isdefault %}{% set active_catelogid = c.catelogid %}{% endif %}{% endfor %} -{% if not active_catelogid and catelogs %}{% set active_catelogid = catelogs[0].catelogid %}{% endif %} +{% set ns = namespace(active_catelogid=params_kw.get('catelogid', '')) %} +{% if not ns.active_catelogid %} +{% for c in catelogs %}{% if c.isdefault and not ns.active_catelogid %}{% set ns.active_catelogid = c.catelogid %}{% endif %}{% endfor %} {% endif %} -{% set llm = get_llm(params_kw.id, active_catelogid) %} +{% if not ns.active_catelogid and catelogs %}{% set ns.active_catelogid = catelogs[0].catelogid %}{% endif %} +{% set llm = get_llm(params_kw.id, ns.active_catelogid) %} {% set kdbs = get_user_kdbs(request) %} {% if llm %} {% if len(catelogs) > 1 %} @@ -34,7 +34,7 @@ "options":{ "label":"{{c.catelogname}}", "actiontype":"link", -{% if c.catelogid == active_catelogid %} +{% if c.catelogid == ns.active_catelogid %} "css":"primary", {% endif %} "url":"{{entire_url('/llmage/llm_dialog.ui')}}?id={{params_kw.id}}&catelogid={{c.catelogid}}" @@ -54,13 +54,13 @@ "kdb_setting":{}, "get_kdb_url": "{{entire_url('/rag/get_my_kdbs.dspy')}}", {% endif %} - "list_models_url":"{{entire_url('list_paging_catelog_llms.dspy')}}?llmcatelogid={{active_catelogid}}", + "list_models_url":"{{entire_url('list_paging_catelog_llms.dspy')}}?llmcatelogid={{ns.active_catelogid}}", "estimate_url":"{{entire_url('model_estimate.dspy')}}", "input_fields":{{llm.input_fields}}, "models":[ { "llmid":"{{llm.id}}", - "llmcatelogid":"{{active_catelogid}}", + "llmcatelogid":"{{ns.active_catelogid}}", "response_mode": "{{llm.stream}}", "icon":"{{entire_url('/appbase/show_icon.dspy')}}?id={{llm.iconid}}", "url":"{{entire_url('/llmage/llminference.dspy')}}", @@ -90,14 +90,14 @@ "kdb_setting":{}, "get_kdb_url": "{{entire_url('/rag/get_my_kdbs.dspy')}}", {% endif %} - "list_models_url":"{{entire_url('list_paging_catelog_llms.dspy')}}{% if active_catelogid %}?llmcatelogid={{active_catelogid}}{% endif %}", + "list_models_url":"{{entire_url('list_paging_catelog_llms.dspy')}}{% if ns.active_catelogid %}?llmcatelogid={{ns.active_catelogid}}{% endif %}", "estimate_url":"{{entire_url('model_estimate.dspy')}}", "input_fields":{{llm.input_fields}}, "models":[ { "llmid":"{{llm.id}}", -{% if active_catelogid %} - "llmcatelogid":"{{active_catelogid}}", +{% if ns.active_catelogid %} + "llmcatelogid":"{{ns.active_catelogid}}", {% endif %} "response_mode": "{{llm.stream}}", "icon":"{{entire_url('/appbase/show_icon.dspy')}}?id={{llm.iconid}}",