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:
|
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]
|
# 实际调用定价计算
|
||||||
|
try:
|
||||||
|
prices = await llm_query_price(llmid, usages)
|
||||||
|
if not prices:
|
||||||
|
return json.dumps({'widgettype':'Error','options':{'text':'定价计算返回空'}}, ensure_ascii=False)
|
||||||
|
|
||||||
# 检查 pricing_program
|
lines = []
|
||||||
async with get_sor_context(request._run_ns, 'pricing') as psor:
|
total = 0
|
||||||
pregs = await psor.sqlExe(
|
for p in prices:
|
||||||
"select * from pricing_program where id=${ppid}$", {'ppid': ppid})
|
amount = getattr(p, 'amount', 0) or 0
|
||||||
if not pregs:
|
name = getattr(p, 'timing_name', '') or ''
|
||||||
return json.dumps({'widgettype':'Error','options':{'text':f'定价项目不存在 (ppid={ppid})'}}, ensure_ascii=False)
|
total += amount
|
||||||
|
lines.append(f'{name}: {amount}')
|
||||||
pp = pregs[0]
|
lines.append(f'合计: {total}')
|
||||||
|
return json.dumps({'widgettype':'Message','options':{'text':f'计费测试通过\n' + chr(10).join(lines)}}, ensure_ascii=False)
|
||||||
# 检查 pricing_program_timing
|
except Exception as e:
|
||||||
try:
|
return json.dumps({'widgettype':'Error','options':{'text':f'计费测试失败: {e}'}}, ensure_ascii=False)
|
||||||
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)
|
|
||||||
|
|
||||||
return json.dumps({'widgettype':'Error','options':{'text':'无效的操作'}}, 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",
|
"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}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user