- 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
154 lines
3.8 KiB
XML
154 lines
3.8 KiB
XML
{% if get_user() %}
|
||
{% set userid = get_user() %}
|
||
{% set userorgid = get_userorgid() %}
|
||
{% if params_kw.id %}
|
||
{% if checkCustomerBalance(params_kw.id, userid, userorgid) %}
|
||
{% set catelogs = get_llm_catelogs(params_kw.id) %}
|
||
{% 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 %}
|
||
{% 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 %}
|
||
{
|
||
"widgettype":"VBox",
|
||
"options":{
|
||
"width":"100%",
|
||
"height":"100%"
|
||
},
|
||
"subwidgets":[
|
||
{
|
||
"widgettype":"HBox",
|
||
"options":{
|
||
"cheight":3,
|
||
"css":"card",
|
||
"padding":"8px"
|
||
},
|
||
"subwidgets":[
|
||
{% for c in catelogs %}
|
||
{
|
||
"widgettype":"Button",
|
||
"options":{
|
||
"label":"{{c.catelogname}}",
|
||
"actiontype":"link",
|
||
{% if c.catelogid == ns.active_catelogid %}
|
||
"css":"primary",
|
||
{% endif %}
|
||
"url":"{{entire_url('/llmage/llm_dialog.ui')}}?id={{params_kw.id}}&catelogid={{c.catelogid}}"
|
||
}
|
||
}{% if not loop.last %},{% endif %}
|
||
{% endfor %}
|
||
]
|
||
},
|
||
{
|
||
"widgettype":"LlmIO",
|
||
"options":{
|
||
"width":"100%",
|
||
"height":"100%",
|
||
"title":"{{llm.name}}",
|
||
{% if len(kdbs) > 0 %}
|
||
"enabled_kdb": true,
|
||
"kdb_setting":{},
|
||
"get_kdb_url": "{{entire_url('/rag/get_my_kdbs.dspy')}}",
|
||
{% endif %}
|
||
"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":"{{ns.active_catelogid}}",
|
||
"response_mode": "{{llm.stream}}",
|
||
"icon":"{{entire_url('/appbase/show_icon.dspy')}}?id={{llm.iconid}}",
|
||
"url":"{{entire_url('/llmage/llminference.dspy')}}",
|
||
{% if llm.stream == 'stream' %}
|
||
"stream": true,
|
||
{% endif %}
|
||
{% if llm.stream =='async' %}
|
||
"query_url": "{{entire_url('/llmage/tasks')}}",
|
||
{% endif %}
|
||
"model":"{{llm.model}}",
|
||
"modelname":"{{llm.name}}"
|
||
}
|
||
]
|
||
}
|
||
}
|
||
]
|
||
}
|
||
{% else %}
|
||
{
|
||
"widgettype":"LlmIO",
|
||
"options":{
|
||
"width":"100%",
|
||
"height":"100%",
|
||
"title":"{{llm.name}}",
|
||
{% if len(kdbs) > 0 %}
|
||
"enabled_kdb": true,
|
||
"kdb_setting":{},
|
||
"get_kdb_url": "{{entire_url('/rag/get_my_kdbs.dspy')}}",
|
||
{% 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 ns.active_catelogid %}
|
||
"llmcatelogid":"{{ns.active_catelogid}}",
|
||
{% endif %}
|
||
"response_mode": "{{llm.stream}}",
|
||
"icon":"{{entire_url('/appbase/show_icon.dspy')}}?id={{llm.iconid}}",
|
||
"url":"{{entire_url('/llmage/llminference.dspy')}}",
|
||
{% if llm.stream == 'stream' %}
|
||
"stream": true,
|
||
{% endif %}
|
||
{% if llm.stream =='async' %}
|
||
"query_url": "{{entire_url('/llmage/tasks')}}",
|
||
{% endif %}
|
||
"model":"{{llm.model}}",
|
||
"modelname":"{{llm.name}}"
|
||
}
|
||
]
|
||
}
|
||
}
|
||
{% endif %}
|
||
{% else %}
|
||
{
|
||
"widgettype":"Text",
|
||
"options":{
|
||
"otext": "没找到模型",
|
||
"i18n":true
|
||
}
|
||
}
|
||
{% endif %}
|
||
{% else %}
|
||
{
|
||
"widgettype":"Text",
|
||
"options":{
|
||
"otext":"Not enrogh balance to use llm",
|
||
"i18n":true
|
||
}
|
||
}
|
||
{% endif %}
|
||
{% else %}
|
||
{
|
||
"widgettype":"Text",
|
||
"options":{
|
||
"otext":"无效的参数,未找到模型ID",
|
||
"i18n":true
|
||
}
|
||
}
|
||
{% endif %}
|
||
{% else %}
|
||
{
|
||
"widgettype":"Text",
|
||
"options":{
|
||
"otext":"You need login to use llm",
|
||
"i18n":true
|
||
}
|
||
}
|
||
{% endif %}
|