fix: 修复llm_launch_check_page.dspy缩进和错误处理
This commit is contained in:
parent
5deecc67ce
commit
75fe89ac2e
@ -2,11 +2,10 @@
|
|||||||
# 服务端渲染模型上线检查页面,输出bricks widget JSON
|
# 服务端渲染模型上线检查页面,输出bricks widget JSON
|
||||||
# 所有检查在服务端async执行,结果直接嵌入widget
|
# 所有检查在服务端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({
|
return json.dumps({
|
||||||
"widgettype": "VBox",
|
"widgettype": "VBox",
|
||||||
"options": {"width": "100%", "height": "100%", "spacing": 10},
|
"options": {"width": "100%", "height": "100%", "spacing": 10},
|
||||||
@ -16,19 +15,19 @@ if not llmid:
|
|||||||
]
|
]
|
||||||
}, ensure_ascii=False)
|
}, ensure_ascii=False)
|
||||||
|
|
||||||
# --- 服务端执行所有检查 ---
|
# --- 服务端执行所有检查 ---
|
||||||
checks = []
|
checks = []
|
||||||
all_passed = True
|
all_passed = True
|
||||||
llm_name = ''
|
llm_name = ''
|
||||||
llm_model = ''
|
llm_model = ''
|
||||||
|
|
||||||
async def add_check(name, passed, detail=''):
|
async def add_check(name, passed, detail=''):
|
||||||
global all_passed
|
global all_passed
|
||||||
checks.append({'name': name, 'passed': passed, 'detail': detail})
|
checks.append({'name': name, 'passed': passed, 'detail': detail})
|
||||||
if not passed:
|
if not passed:
|
||||||
all_passed = False
|
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(
|
recs = await sor.sqlExe(
|
||||||
"select * from llm where id=${llmid}$", {'llmid': llmid})
|
"select * from llm where id=${llmid}$", {'llmid': llmid})
|
||||||
if not recs:
|
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('定价项目(pricing_program)', False, 'llm_api_map中无ppid')
|
||||||
await add_check('定价数据(pricingdata)', False, '无定价项目')
|
await add_check('定价数据(pricingdata)', False, '无定价项目')
|
||||||
|
|
||||||
# --- 构建widget JSON ---
|
# --- 构建widget JSON ---
|
||||||
api_url = entire_url('./api/llm_launch_check_api.dspy')
|
api_url = entire_url('./api/llm_launch_check_api.dspy')
|
||||||
status_text = '全部通过 ✅' if all_passed else '存在问题 ❌ 请检查下方详情'
|
status_text = '全部通过 ✅' if all_passed else '存在问题 ❌ 请检查下方详情'
|
||||||
|
|
||||||
# 检查项列表:每项一行Text widget
|
# 检查项列表:每项一行Text widget
|
||||||
check_widgets = []
|
check_widgets = []
|
||||||
for c in checks:
|
for c in checks:
|
||||||
icon = '✅' if c['passed'] else '❌'
|
icon = '✅' if c['passed'] else '❌'
|
||||||
text = f"{icon} {c['name']}: {c['detail']}"
|
text = f"{icon} {c['name']}: {c['detail']}"
|
||||||
check_widgets.append({
|
check_widgets.append({
|
||||||
@ -110,13 +109,13 @@ for c in checks:
|
|||||||
"options": {"text": text, "i18n": False}
|
"options": {"text": text, "i18n": False}
|
||||||
})
|
})
|
||||||
|
|
||||||
# 按钮和结果显示区
|
# 按钮和结果显示区
|
||||||
subwidgets = [
|
subwidgets = [
|
||||||
{"widgettype": "Title", "options": {"text": f"模型上线检查 — {llm_name}", "level": 2}},
|
{"widgettype": "Title", "options": {"text": f"模型上线检查 — {llm_name}", "level": 2}},
|
||||||
{"widgettype": "Text", "options": {"text": status_text, "i18n": False}},
|
{"widgettype": "Text", "options": {"text": status_text, "i18n": False}},
|
||||||
] + check_widgets
|
] + check_widgets
|
||||||
|
|
||||||
if all_passed:
|
if all_passed:
|
||||||
subwidgets.append({
|
subwidgets.append({
|
||||||
"widgettype": "Button",
|
"widgettype": "Button",
|
||||||
"options": {"name": "test_btn", "label": "体验一次", "i18n": False},
|
"options": {"name": "test_btn", "label": "体验一次", "i18n": False},
|
||||||
@ -152,10 +151,20 @@ if all_passed:
|
|||||||
"options": {"name": "charge_result", "text": "", "i18n": False}
|
"options": {"name": "charge_result", "text": "", "i18n": False}
|
||||||
})
|
})
|
||||||
|
|
||||||
widget = {
|
widget = {
|
||||||
"widgettype": "VBox",
|
"widgettype": "VBox",
|
||||||
"options": {"width": "100%", "height": "100%", "spacing": 10},
|
"options": {"width": "100%", "height": "100%", "spacing": 10},
|
||||||
"subwidgets": subwidgets
|
"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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user