改用 pricing.pricing.get_pricing_display() 获取格式化定价明细, 替换原来的 select count(*) 只显示记录条数
40 lines
1.3 KiB
Plaintext
40 lines
1.3 KiB
Plaintext
from pricing.pricing import get_pricing_display
|
|
|
|
llmid = params_kw.get('llmid', '')
|
|
|
|
if not llmid:
|
|
return json.dumps({
|
|
"widgettype": "Text",
|
|
"options": {"text": "❌ 定价数据: 缺少llmid参数", "i18n": False}
|
|
}, ensure_ascii=False)
|
|
|
|
async with get_sor_context(request._run_ns, 'llmage') as sor:
|
|
maps = await sor.sqlExe(
|
|
"select * from llm_api_map where llmid=${llmid}$", {'llmid': llmid})
|
|
ppids = [m.ppid for m in maps if m.ppid] if maps else []
|
|
|
|
if not ppids:
|
|
text = "❌ 定价数据: 无定价项目"
|
|
else:
|
|
ppid = ppids[0]
|
|
try:
|
|
result = await get_pricing_display(ppid)
|
|
if not result:
|
|
text = "❌ 定价数据: 无当前生效的定价记录"
|
|
elif result.get('display_text'):
|
|
lines = [f"✅ 定价项目: {result.get('name', ppid)}"]
|
|
if result.get('pricing_type'):
|
|
lines.append(f" 类型: {result['pricing_type']}")
|
|
lines.append("")
|
|
lines.append(result['display_text'])
|
|
text = '\n'.join(lines)
|
|
else:
|
|
text = f"✅ 定价项目: {result.get('name', ppid)} (无定价明细)"
|
|
except Exception as e:
|
|
text = f"❌ 定价数据: {e}"
|
|
|
|
return json.dumps({
|
|
"widgettype": "Text",
|
|
"options": {"text": text, "i18n": False}
|
|
}, ensure_ascii=False)
|