fix: 体验一次→打开llm_dialog实战推理;检查计费→真正调用llm_query_price算价

This commit is contained in:
yumoqing 2026-07-02 14:54:50 +08:00
parent 57fb8c3c8f
commit e27137055c
2 changed files with 26 additions and 33 deletions

View File

@ -62,27 +62,22 @@ elif action == 'check_charging':
if not ppids: if not ppids:
return json.dumps({'widgettype':'Error','options':{'text':'无定价项目(ppid)'}}, ensure_ascii=False) 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)
pp = pregs[0]
# 检查 pricing_program_timing
try: try:
timings = await psor.sqlExe( prices = await llm_query_price(llmid, usages)
"select * from pricing_program_timing where ppid=${ppid}$", if not prices:
{'ppid': ppid}) return json.dumps({'widgettype':'Error','options':{'text':'定价计算返回空'}}, ensure_ascii=False)
if timings:
return json.dumps({'widgettype':'Message','options':{'text':f'计费配置验证通过\n定价项目: {pp.name}\n定价数据: {len(timings)}条记录\n测试用量: {json.dumps(usages)}'}}, ensure_ascii=False) lines = []
else: total = 0
return json.dumps({'widgettype':'Warning','options':{'text':f'定价项目存在但无定价数据\n定价项目: {pp.name}'}}, ensure_ascii=False) 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: except Exception as e:
return json.dumps({'widgettype':'Error','options':{'text':f'定价数据查询失败: {e}'}}, ensure_ascii=False) return json.dumps({'widgettype':'Error','options':{'text':f'计费测试失败: {e}'}}, ensure_ascii=False)
return json.dumps({'widgettype':'Error','options':{'text':'无效的操作'}}, ensure_ascii=False) return json.dumps({'widgettype':'Error','options':{'text':'无效的操作'}}, ensure_ascii=False)

View File

@ -80,14 +80,6 @@
} }
] ]
}, },
{
"widgettype": "Text",
"id": "test_result",
"options": {
"text": "",
"i18n": false
}
},
{ {
"widgettype": "Text", "widgettype": "Text",
"id": "charge_result", "id": "charge_result",
@ -128,10 +120,16 @@
{ {
"wid": "test_btn", "wid": "test_btn",
"event": "click", "event": "click",
"actiontype": "urldata", "actiontype": "urlwidget",
"target": "test_result", "target": "PopupWindow",
"popup_options": {
"title": "模型体验",
"resizable": true,
"height": "80%",
"width": "80%"
},
"options": { "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", "actiontype": "urldata",
"target": "charge_result", "target": "charge_result",
"options": { "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}"
} }
} }
] ]