fix: 体验一次→打开llm_dialog实战推理;检查计费→真正调用llm_query_price算价
This commit is contained in:
parent
57fb8c3c8f
commit
e27137055c
@ -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)
|
||||
|
||||
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)
|
||||
prices = await llm_query_price(llmid, usages)
|
||||
if not prices:
|
||||
return json.dumps({'widgettype':'Error','options':{'text':'定价计算返回空'}}, 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':f'计费测试失败: {e}'}}, ensure_ascii=False)
|
||||
|
||||
return json.dumps({'widgettype':'Error','options':{'text':'无效的操作'}}, ensure_ascii=False)
|
||||
|
||||
@ -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}"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user