fix: 修复llm_launch_check_page.dspy缩进和错误处理

This commit is contained in:
Hermes Agent 2026-06-16 15:46:16 +08:00
parent 5deecc67ce
commit 75fe89ac2e

View File

@ -2,11 +2,10 @@
# 服务端渲染模型上线检查页面输出bricks widget JSON
# 所有检查在服务端async执行结果直接嵌入widget
import html as html_mod
try:
llmid = params_kw.get('id', '')
llmid = params_kw.get('id', '')
if not llmid:
if not llmid:
return json.dumps({
"widgettype": "VBox",
"options": {"width": "100%", "height": "100%", "spacing": 10},
@ -16,19 +15,19 @@ if not llmid:
]
}, ensure_ascii=False)
# --- 服务端执行所有检查 ---
checks = []
all_passed = True
llm_name = ''
llm_model = ''
# --- 服务端执行所有检查 ---
checks = []
all_passed = True
llm_name = ''
llm_model = ''
async def add_check(name, passed, detail=''):
async def add_check(name, passed, detail=''):
global all_passed
checks.append({'name': name, 'passed': passed, 'detail': detail})
if not passed:
all_passed = False
async with get_sor_context(request._run_ns, 'llmage') as sor:
async with get_sor_context(request._run_ns, 'llmage') as sor:
recs = await sor.sqlExe(
"select * from llm where id=${llmid}$", {'llmid': llmid})
if not recs:
@ -96,13 +95,13 @@ async with get_sor_context(request._run_ns, 'llmage') as sor:
await add_check('定价项目(pricing_program)', False, 'llm_api_map中无ppid')
await add_check('定价数据(pricingdata)', False, '无定价项目')
# --- 构建widget JSON ---
api_url = entire_url('./api/llm_launch_check_api.dspy')
status_text = '全部通过 ✅' if all_passed else '存在问题 ❌ 请检查下方详情'
# --- 构建widget JSON ---
api_url = entire_url('./api/llm_launch_check_api.dspy')
status_text = '全部通过 ✅' if all_passed else '存在问题 ❌ 请检查下方详情'
# 检查项列表每项一行Text widget
check_widgets = []
for c in checks:
# 检查项列表每项一行Text widget
check_widgets = []
for c in checks:
icon = '✅' if c['passed'] else '❌'
text = f"{icon} {c['name']}: {c['detail']}"
check_widgets.append({
@ -110,13 +109,13 @@ for c in checks:
"options": {"text": text, "i18n": False}
})
# 按钮和结果显示区
subwidgets = [
# 按钮和结果显示区
subwidgets = [
{"widgettype": "Title", "options": {"text": f"模型上线检查 — {llm_name}", "level": 2}},
{"widgettype": "Text", "options": {"text": status_text, "i18n": False}},
] + check_widgets
] + check_widgets
if all_passed:
if all_passed:
subwidgets.append({
"widgettype": "Button",
"options": {"name": "test_btn", "label": "体验一次", "i18n": False},
@ -152,10 +151,20 @@ if all_passed:
"options": {"name": "charge_result", "text": "", "i18n": False}
})
widget = {
widget = {
"widgettype": "VBox",
"options": {"width": "100%", "height": "100%", "spacing": 10},
"subwidgets": subwidgets
}
}
return json.dumps(widget, ensure_ascii=False)
return json.dumps(widget, ensure_ascii=False)
except Exception as e:
return json.dumps({
"widgettype": "VBox",
"options": {"width": "100%", "height": "100%", "spacing": 10},
"subwidgets": [
{"widgettype": "Title", "options": {"text": "模型上线检查", "level": 2}},
{"widgettype": "Text", "options": {"text": f"执行错误: {format_exc()}", "i18n": False}}
]
}, ensure_ascii=False)