diff --git a/wwwroot/api/llm_launch_check_api.dspy b/wwwroot/api/llm_launch_check_api.dspy index 092fdc9..c1391dc 100644 --- a/wwwroot/api/llm_launch_check_api.dspy +++ b/wwwroot/api/llm_launch_check_api.dspy @@ -62,27 +62,22 @@ elif action == 'check_charging': if not ppids: return json.dumps({'widgettype':'Error','options':{'text':'无定价项目(ppid)'}}, ensure_ascii=False) - ppid = ppids[0] - - # 检查 pricing_program - async with get_sor_context(request._run_ns, 'pricing') as psor: - pregs = await psor.sqlExe( - "select * from pricing_program where id=${ppid}$", {'ppid': ppid}) - if not pregs: - return json.dumps({'widgettype':'Error','options':{'text':f'定价项目不存在 (ppid={ppid})'}}, ensure_ascii=False) + # 实际调用定价计算 + try: + prices = await llm_query_price(llmid, usages) + if not prices: + return json.dumps({'widgettype':'Error','options':{'text':'定价计算返回空'}}, ensure_ascii=False) - pp = pregs[0] - - # 检查 pricing_program_timing - try: - timings = await psor.sqlExe( - "select * from pricing_program_timing where ppid=${ppid}$", - {'ppid': ppid}) - if timings: - return json.dumps({'widgettype':'Message','options':{'text':f'计费配置验证通过\n定价项目: {pp.name}\n定价数据: {len(timings)}条记录\n测试用量: {json.dumps(usages)}'}}, ensure_ascii=False) - else: - return json.dumps({'widgettype':'Warning','options':{'text':f'定价项目存在但无定价数据\n定价项目: {pp.name}'}}, ensure_ascii=False) - except Exception as e: - return json.dumps({'widgettype':'Error','options':{'text':f'定价数据查询失败: {e}'}}, ensure_ascii=False) + lines = [] + total = 0 + for p in prices: + amount = getattr(p, 'amount', 0) or 0 + name = getattr(p, 'timing_name', '') or '' + total += amount + lines.append(f'{name}: {amount}') + lines.append(f'合计: {total}') + return json.dumps({'widgettype':'Message','options':{'text':f'计费测试通过\n' + chr(10).join(lines)}}, ensure_ascii=False) + except Exception as e: + return json.dumps({'widgettype':'Error','options':{'text':f'计费测试失败: {e}'}}, ensure_ascii=False) return json.dumps({'widgettype':'Error','options':{'text':'无效的操作'}}, ensure_ascii=False) diff --git a/wwwroot/llm_launch_check.ui b/wwwroot/llm_launch_check.ui index 97eedd3..f0d7aa5 100644 --- a/wwwroot/llm_launch_check.ui +++ b/wwwroot/llm_launch_check.ui @@ -80,14 +80,6 @@ } ] }, - { - "widgettype": "Text", - "id": "test_result", - "options": { - "text": "", - "i18n": false - } - }, { "widgettype": "Text", "id": "charge_result", @@ -128,10 +120,16 @@ { "wid": "test_btn", "event": "click", - "actiontype": "urldata", - "target": "test_result", + "actiontype": "urlwidget", + "target": "PopupWindow", + "popup_options": { + "title": "模型体验", + "resizable": true, + "height": "80%", + "width": "80%" + }, "options": { - "url": "/llmage/api/llm_launch_check_api.dspy?llmid={{llmid}}&action=inference" + "url": "{{entire_url('/llmage/llm_dialog.ui')}}?id={{llmid}}" } }, { @@ -140,7 +138,7 @@ "actiontype": "urldata", "target": "charge_result", "options": { - "url": "/llmage/api/llm_launch_check_api.dspy?llmid={{llmid}}&action=check_charging&usages={\"prompt_tokens\":1000,\"completion_tokens\":500}" + "url": "{{entire_url('/llmage/api/llm_launch_check_api.dspy')}}?llmid={{llmid}}&action=check_charging&usages={\"prompt_tokens\":1000,\"completion_tokens\":500}" } } ]