77 lines
3.3 KiB
Plaintext
77 lines
3.3 KiB
Plaintext
# card_popup.dspy — 模型治理功能卡片弹窗(2026-09-07 用户定夺:卡片点击一律弹窗处理,不在页面下方展示)
|
||
# 参数:target=白名单内的 CRUD 目录名;模型注册弹窗额外带「自动配置/上线检查」工具按钮
|
||
|
||
import json as _json
|
||
|
||
uid = await get_user()
|
||
if not uid:
|
||
return _json.dumps({
|
||
"widgettype": "PopupWindow",
|
||
"options": {"title": "提示", "cwidth": 30, "cheight": 8, "auto_open": True},
|
||
"subwidgets": [{"widgettype": "Text", "options": {"text": "请先登录", "padding": "20px"}}]
|
||
}, ensure_ascii=False)
|
||
|
||
target = ((params_kw or {}).get('target', '') or '').strip()
|
||
titles = {
|
||
'llm_vendor': '供应商与端点',
|
||
'llm_model': '模型注册',
|
||
'llm_api_profile': '适配模板',
|
||
'llm_org_policy': '组织容错策略',
|
||
'llm_org_quota': '组织限额限流',
|
||
'llm_user_quota': '个人限额限流',
|
||
'llm_usage': '用量流水',
|
||
}
|
||
if target not in titles:
|
||
return _json.dumps({
|
||
"widgettype": "PopupWindow",
|
||
"options": {"title": "提示", "cwidth": 40, "cheight": 10, "auto_open": True},
|
||
"subwidgets": [{"widgettype": "Text", "options": {
|
||
"text": "无效的功能入口:" + target, "padding": "20px"}}]
|
||
}, ensure_ascii=False)
|
||
|
||
subwidgets = []
|
||
if target == 'llm_model':
|
||
# 模型注册工具栏:自动配置(内部助手全链)+ 上线检查(真实调用测试+记账检查)
|
||
auto_url = entire_url('/pipeline-llm/api/auto_config_popup.dspy')
|
||
check_url = entire_url('/pipeline-llm/api/online_check_popup.dspy')
|
||
auto_script = (
|
||
"var old=bricks.getWidgetById('llm_auto_cfg_pw',bricks.app);"
|
||
"if(old&&old.destroy){old.destroy();}"
|
||
"var r=await fetch(" + _json.dumps(auto_url) + ");"
|
||
"var d=await r.json();if(d&&d.widgettype){bricks.widgetBuild(d,bricks.app);}")
|
||
check_script = (
|
||
"var old=bricks.getWidgetById('llm_online_chk_pw',bricks.app);"
|
||
"if(old&&old.destroy){old.destroy();}"
|
||
"var r=await fetch(" + _json.dumps(check_url) + ");"
|
||
"var d=await r.json();if(d&&d.widgettype){bricks.widgetBuild(d,bricks.app);}")
|
||
subwidgets.append({
|
||
"widgettype": "HBox",
|
||
"options": {"gap": "8px", "padding": "0 0 10px 0", "alignItems": "center"},
|
||
"subwidgets": [
|
||
{"widgettype": "Button",
|
||
"options": {"label": "🤖 自动配置", "css": "small"},
|
||
"binds": [{"wid": "self", "event": "click", "actiontype": "script",
|
||
"target": "self", "script": auto_script}]},
|
||
{"widgettype": "Button",
|
||
"options": {"label": "✅ 上线检查", "css": "small"},
|
||
"binds": [{"wid": "self", "event": "click", "actiontype": "script",
|
||
"target": "self", "script": check_script}]},
|
||
{"widgettype": "Text",
|
||
"options": {"text": "自动配置:粘贴 API/定价文档链接或正文,内部助手全链完成并汇报模型状态;上线检查:选择模型后真实调用测试+记账检查",
|
||
"cfontsize": 0.85, "color": "#94a3b8", "halign": "left"}},
|
||
]})
|
||
subwidgets.append({
|
||
"widgettype": "urlwidget",
|
||
"options": {"url": entire_url('/pipeline-llm/' + target)}})
|
||
|
||
resp = {
|
||
"widgettype": "PopupWindow",
|
||
"id": "llm_card_pw",
|
||
"options": {"title": titles[target], "width": "85%", "height": "85%", "auto_open": True},
|
||
"subwidgets": [{
|
||
"widgettype": "VBox",
|
||
"options": {"css": "filler", "width": "100%", "height": "100%", "padding": "12px"},
|
||
"subwidgets": subwidgets}]
|
||
}
|
||
return _json.dumps(resp, ensure_ascii=False)
|