From e27137055cdfe4b488b8cc056ae0a2abc5abd91b Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 2 Jul 2026 14:54:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=93=E9=AA=8C=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E2=86=92=E6=89=93=E5=BC=80llm=5Fdialog=E5=AE=9E=E6=88=98?= =?UTF-8?q?=E6=8E=A8=E7=90=86=EF=BC=9B=E6=A3=80=E6=9F=A5=E8=AE=A1=E8=B4=B9?= =?UTF-8?q?=E2=86=92=E7=9C=9F=E6=AD=A3=E8=B0=83=E7=94=A8llm=5Fquery=5Fpric?= =?UTF-8?q?e=E7=AE=97=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/api/llm_launch_check_api.dspy | 37 ++++++++++++--------------- wwwroot/llm_launch_check.ui | 22 ++++++++-------- 2 files changed, 26 insertions(+), 33 deletions(-) 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}" } } ]