feat: add llmage module stat cards - model count, today's usage, amount, catalog count
- Create stats.py with get_llmage_stats() helper function - Add 4 stat widgets: stat_total_models, stat_today_calls, stat_today_amount, stat_catelog_count - Update index.ui to display stat cards row above navigation cards - Register get_llmage_stats in load_llmage()
This commit is contained in:
parent
ae61193454
commit
6d14347ebc
53
dat/qwen3.7-max.txt
Normal file
53
dat/qwen3.7-max.txt
Normal file
@ -0,0 +1,53 @@
|
||||
已生成完整的 qwen3.7-max 配置SQL。以下是配置方案:
|
||||
|
||||
模型摘要
|
||||
- 模型名称: 千问3.7-Max
|
||||
- API model: qwen3.7-max (严格按API文档填写)
|
||||
- 分类: text2text (文生文)
|
||||
- 供应商: 阿里百炼 (ali-qwen)
|
||||
- 接口: OpenAI兼容 /chat/completions,同步流式
|
||||
|
||||
复用vs新建
|
||||
- upapp: 复用 ali-qwen (阿里百炼)
|
||||
- upappkey: 复用 gCMl-BnrTrfoqWAEPPoH8 (API Key已配置)
|
||||
- uapi: 复用 t2t (BY2cA4RD_axNxTG4m9Coa)
|
||||
- uapiio: 复用 Is8l4TGkcZcqFSjbbeIK2 (文本会话)
|
||||
- llm: 新建
|
||||
- llm_api_map: 新建
|
||||
- pricing_program: 新建
|
||||
- pricing_program_timing: 新建
|
||||
|
||||
生成的SQL (4条)
|
||||
|
||||
sql
|
||||
-- 1. llm表
|
||||
INSERT INTO llm VALUES ('Jt26VKlUFsJxABuVLauBc','千问3.7-Max','qwen3.7-max','通义千问3.7系列旗舰模型,相较3.6版本在推理能力、代码能力、多模态理解等方面全面升级。适用于复杂任务处理、智能体开发、代码生成等高级应用场景。','text2text','qwen','ali-qwen','t2t','6fadgewjraOyvxC_EkHou','0','2026-05-23','9999-12-31','',NULL,10.00);
|
||||
|
||||
-- 2. llm_api_map表
|
||||
INSERT INTO llm_api_map VALUES ('rFS0Ag-epBUxE5LCF6glW','Jt26VKlUFsJxABuVLauBc','text2text','t2t',NULL,NULL,'0B-JNSUEelsY5TQ_Sawa7','1');
|
||||
|
||||
-- 3. pricing_program表
|
||||
INSERT INTO pricing_program VALUES ('0B-JNSUEelsY5TQ_Sawa7','qwen3.7-max定价','fields:\r\n formula:\r\n label: 计算公式\r\n type: str\r\n model:\r\n label: 模型\r\n type: str\r\n prompt_tokens:\r\n label: 输入词元数\r\n type: int\r\n value_mode: between\r\nformula: null\r\npricings:\r\n- formula: 2.5 prompt_tokens / 1000000 + completion_tokens 10 /1000000\r\n model: qwen3.7-max\r\n prompt_tokens: -0.1 ~= 32000\r\n- formula: 4 prompt_tokens / 1000000 + completion_tokens 16 /1000000\r\n model: qwen3.7-max\r\n prompt_tokens: 32000 ~= 128000\r\n- formula: 7 prompt_tokens / 1000000 + completion_tokens 28 /1000000\r\n model: qwen3.7-max\r\n prompt_tokens: 128000 ~= 256000\r\n- formula: 10 prompt_tokens / 1000000 + completion_tokens 40 /1000000\r\n model: qwen3.7-max\r\n prompt_tokens: 256000 ~= 1000000','2026-05-23','9999-12-31');
|
||||
|
||||
-- 4. pricing_program_timing表
|
||||
INSERT INTO pricing_program_timing VALUES ('C-IIEG_9_O9beN8S2vdUI','0B-JNSUEelsY5TQ_Sawa7','qwen3.7-max计费','fields:\r\n formula:\r\n label: 计算公式\r\n type: str\r\n model:\r\n label: 模型\r\n type: str\r\n prompt_tokens:\r\n label: 输入词元数\r\n type: int\r\n value_mode: between\r\nformula: null\r\npricings:\r\n- formula: 2.5 prompt_tokens / 1000000 + completion_tokens 10 /1000000\r\n model: qwen3.7-max\r\n prompt_tokens: -0.1 ~= 32000\r\n- formula: 4 prompt_tokens / 1000000 + completion_tokens 16 /1000000\r\n model: qwen3.7-max\r\n prompt_tokens: 32000 ~= 128000\r\n- formula: 7 prompt_tokens / 1000000 + completion_tokens 28 /1000000\r\n model: qwen3.7-max\r\n prompt_tokens: 128000 ~= 256000\r\n- formula: 10 prompt_tokens / 1000000 + completion_tokens 40 /1000000\r\n model: qwen3.7-max\r\n prompt_tokens: 256000 ~= 1000000','2026-05-23','9999-12-31');
|
||||
|
||||
|
||||
验证查询
|
||||
sql
|
||||
SELECT id, name, model, upappid, apiname FROM llm WHERE model = 'qwen3.7-max';
|
||||
SELECT id, llmid, llmcatelogid, apiname, ppid FROM llm_api_map WHERE llmid = 'Jt26VKlUFsJxABuVLauBc';
|
||||
SELECT id, name FROM pricing_program WHERE id = '0B-JNSUEelsY5TQ_Sawa7';
|
||||
|
||||
|
||||
ppid三处一致
|
||||
- pricing_program.id = 0B-JNSUEelsY5TQ_Sawa7
|
||||
- pricing_program_timing.ppid = 0B-JNSUEelsY5TQ_Sawa7
|
||||
- llm_api_map.ppid = 0B-JNSUEelsY5TQ_Sawa7
|
||||
|
||||
注意事项
|
||||
1. 定价参考qwen3.6-plus的阶梯式计费模式,具体价格需根据百炼官方定价调整
|
||||
2. qwen3.7-max使用已有的t2t uapi,OpenAI兼容接口
|
||||
3. 如果qwen3.7-max有特殊的推理模式(如思考/非思考切换),可能需要额外的配置
|
||||
4. 之前提到的 startReasoning is not defined 前端报错问题需要单独排查,可能与harnessed_reasoning的bricks前端代码有关
|
||||
|
||||
BIN
llmage/__pycache__/accounting.cpython-310.pyc
Normal file
BIN
llmage/__pycache__/accounting.cpython-310.pyc
Normal file
Binary file not shown.
@ -32,6 +32,7 @@ from .accounting import (
|
||||
get_failed_accounting_records,
|
||||
llm_accoung_failed
|
||||
)
|
||||
from .stats import get_llmage_stats
|
||||
|
||||
from .asyncinference import (
|
||||
get_asynctask_status,
|
||||
@ -63,6 +64,7 @@ def load_llmage():
|
||||
env.get_llms_by_catelog_to_customer = get_llms_by_catelog_to_customer
|
||||
env.backup_accounted_llmusage = backup_accounted_llmusage
|
||||
env.get_failed_accounting_records = get_failed_accounting_records
|
||||
env.get_llmage_stats = get_llmage_stats
|
||||
rf = RegisterFunction()
|
||||
rf.register('jimeng_auth_headers', jimeng_auth_headers)
|
||||
|
||||
|
||||
69
llmage/stats.py
Normal file
69
llmage/stats.py
Normal file
@ -0,0 +1,69 @@
|
||||
from sqlor.dbpools import get_sor_context
|
||||
from appPublic.timeUtils import curDateString, timestampstr
|
||||
from datetime import datetime, timedelta
|
||||
from appPublic.log import debug, exception
|
||||
|
||||
async def get_llmage_stats(request):
|
||||
"""Get llmage module statistics"""
|
||||
env = request._run_ns
|
||||
userorgid = await env.get_userorgid()
|
||||
today = curDateString()
|
||||
tomorrow = (datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d')
|
||||
|
||||
stats = {
|
||||
'total_models': 0,
|
||||
'today_usage_count': 0,
|
||||
'today_amount': 0,
|
||||
'catelog_count': 0
|
||||
}
|
||||
|
||||
async with get_sor_context(env, 'llmage') as sor:
|
||||
# Total enabled models
|
||||
sql_models = """
|
||||
SELECT COUNT(DISTINCT id) as cnt FROM llm
|
||||
WHERE enabled_date <= ${today}$
|
||||
AND expired_date > ${today}$
|
||||
"""
|
||||
recs = await sor.sqlExe(sql_models, {'today': today})
|
||||
if recs:
|
||||
stats['total_models'] = int(recs[0].cnt or 0)
|
||||
|
||||
# Today's usage count
|
||||
sql_usage = """
|
||||
SELECT COUNT(*) as cnt FROM llmusage
|
||||
WHERE userorgid = ${userorgid}$
|
||||
AND use_date >= ${today}$
|
||||
AND use_date < ${tomorrow}$
|
||||
"""
|
||||
recs = await sor.sqlExe(sql_usage, {
|
||||
'userorgid': userorgid,
|
||||
'today': today,
|
||||
'tomorrow': tomorrow
|
||||
})
|
||||
if recs:
|
||||
stats['today_usage_count'] = int(recs[0].cnt or 0)
|
||||
|
||||
# Today's total amount
|
||||
sql_amount = """
|
||||
SELECT COALESCE(SUM(amount), 0) as total FROM llmusage
|
||||
WHERE userorgid = ${userorgid}$
|
||||
AND use_date >= ${today}$
|
||||
AND use_date < ${tomorrow}$
|
||||
"""
|
||||
recs = await sor.sqlExe(sql_amount, {
|
||||
'userorgid': userorgid,
|
||||
'today': today,
|
||||
'tomorrow': tomorrow
|
||||
})
|
||||
if recs:
|
||||
stats['today_amount'] = float(recs[0].total or 0)
|
||||
|
||||
# Catalog count
|
||||
sql_catelog = """
|
||||
SELECT COUNT(*) as cnt FROM llmcatelog
|
||||
"""
|
||||
recs = await sor.sqlExe(sql_catelog, {})
|
||||
if recs:
|
||||
stats['catelog_count'] = int(recs[0].cnt or 0)
|
||||
|
||||
return stats
|
||||
@ -35,6 +35,40 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "ResponsableBox",
|
||||
"options": {
|
||||
"gap": "16px",
|
||||
"minWidth": "200px",
|
||||
"marginBottom": "24px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "urlwidget",
|
||||
"options": {
|
||||
"url": "{{entire_url('/llmage/stat_total_models.ui')}}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "urlwidget",
|
||||
"options": {
|
||||
"url": "{{entire_url('/llmage/stat_today_calls.ui')}}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "urlwidget",
|
||||
"options": {
|
||||
"url": "{{entire_url('/llmage/stat_today_amount.ui')}}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "urlwidget",
|
||||
"options": {
|
||||
"url": "{{entire_url('/llmage/stat_catelog_count.ui')}}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "ResponsableBox",
|
||||
"options": {
|
||||
|
||||
53
wwwroot/stat_catelog_count.ui
Normal file
53
wwwroot/stat_catelog_count.ui
Normal file
@ -0,0 +1,53 @@
|
||||
{% set stats = get_llmage_stats(request) %}
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"options": {
|
||||
"bgcolor": "#1E293B",
|
||||
"padding": "20px",
|
||||
"borderRadius": "12px",
|
||||
"border": "1px solid #334155",
|
||||
"flex": "1",
|
||||
"minHeight": "110px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"alignItems": "center",
|
||||
"marginBottom": "12px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Svg",
|
||||
"options": {
|
||||
"svg": "<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#8B5CF6\" stroke-width=\"2\"><path d=\"M3.75 6A2.25 2.25 0 016 3.75h2.25A2.25 2.25 0 0110.5 6v2.25a2.25 2.25 0 01-2.25 2.25H6a2.25 2.25 0 01-2.25-2.25V6zM3.75 15.75A2.25 2.25 0 016 13.5h2.25a2.25 2.25 0 012.25 2.25V18a2.25 2.25 0 01-2.25 2.25H6A2.25 2.25 0 013.75 18v-2.25zM13.5 6a2.25 2.25 0 012.25-2.25H18A2.25 2.25 0 0120.25 6v2.25A2.25 2.25 0 0118 10.5h-2.25a2.25 2.25 0 01-2.25-2.25V6zM13.5 15.75a2.25 2.25 0 012.25-2.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-2.25A2.25 2.25 0 0113.5 18v-2.25z\"/></svg>",
|
||||
"width": "24px",
|
||||
"height": "24px"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Filler"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "{{stats.catelog_count}}",
|
||||
"fontSize": "32px",
|
||||
"fontWeight": "700",
|
||||
"color": "#F1F5F9",
|
||||
"lineHeight": "1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "模型分类",
|
||||
"fontSize": "14px",
|
||||
"color": "#94A3B8",
|
||||
"marginTop": "4px"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
53
wwwroot/stat_today_amount.ui
Normal file
53
wwwroot/stat_today_amount.ui
Normal file
@ -0,0 +1,53 @@
|
||||
{% set stats = get_llmage_stats(request) %}
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"options": {
|
||||
"bgcolor": "#1E293B",
|
||||
"padding": "20px",
|
||||
"borderRadius": "12px",
|
||||
"border": "1px solid #334155",
|
||||
"flex": "1",
|
||||
"minHeight": "110px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"alignItems": "center",
|
||||
"marginBottom": "12px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Svg",
|
||||
"options": {
|
||||
"svg": "<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#F59E0B\" stroke-width=\"2\"><path d=\"M12 6v12m-3-2.818l.879.659c1.171.879 3.07.879 4.242 0 1.172-.879 1.172-2.303 0-3.182C13.536 12.219 12.768 12 12 12c-.725 0-1.45-.22-2.003-.659-1.106-.879-1.106-2.303 0-3.182s2.9-.879 4.006 0l.415.33M21 12a9 9 0 11-18 0 9 9 0 0118 0z\"/></svg>",
|
||||
"width": "24px",
|
||||
"height": "24px"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Filler"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "¥{{'%.2f' % stats.today_amount}}",
|
||||
"fontSize": "32px",
|
||||
"fontWeight": "700",
|
||||
"color": "#F1F5F9",
|
||||
"lineHeight": "1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "今日消费",
|
||||
"fontSize": "14px",
|
||||
"color": "#94A3B8",
|
||||
"marginTop": "4px"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
53
wwwroot/stat_today_calls.ui
Normal file
53
wwwroot/stat_today_calls.ui
Normal file
@ -0,0 +1,53 @@
|
||||
{% set stats = get_llmage_stats(request) %}
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"options": {
|
||||
"bgcolor": "#1E293B",
|
||||
"padding": "20px",
|
||||
"borderRadius": "12px",
|
||||
"border": "1px solid #334155",
|
||||
"flex": "1",
|
||||
"minHeight": "110px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"alignItems": "center",
|
||||
"marginBottom": "12px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Svg",
|
||||
"options": {
|
||||
"svg": "<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#22C55E\" stroke-width=\"2\"><path d=\"M7.5 21L3 16.5m0 0L7.5 12M12 9v7.5m0 0l4.5-4.5M12 9l4.5 4.5m0 0L12 16.5\"/><path d=\"M21 12h-4.5M12 3v4.5m0 0L7.5 12\"/></svg>",
|
||||
"width": "24px",
|
||||
"height": "24px"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Filler"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "{{stats.today_usage_count}}",
|
||||
"fontSize": "32px",
|
||||
"fontWeight": "700",
|
||||
"color": "#F1F5F9",
|
||||
"lineHeight": "1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "今日调用",
|
||||
"fontSize": "14px",
|
||||
"color": "#94A3B8",
|
||||
"marginTop": "4px"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
53
wwwroot/stat_total_models.ui
Normal file
53
wwwroot/stat_total_models.ui
Normal file
@ -0,0 +1,53 @@
|
||||
{% set stats = get_llmage_stats(request) %}
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"options": {
|
||||
"bgcolor": "#1E293B",
|
||||
"padding": "20px",
|
||||
"borderRadius": "12px",
|
||||
"border": "1px solid #334155",
|
||||
"flex": "1",
|
||||
"minHeight": "110px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"alignItems": "center",
|
||||
"marginBottom": "12px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Svg",
|
||||
"options": {
|
||||
"svg": "<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#3B82F6\" stroke-width=\"2\"><path d=\"M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.455 2.456L21.75 6l-1.036.259a3.375 3.375 0 00-2.455 2.456zM16.894 20.567L16.5 21.75l-.394-1.183a2.25 2.25 0 00-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 001.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 001.423 1.423l1.183.394-1.183.394a2.25 2.25 0 00-1.423 1.423z\"/></svg>",
|
||||
"width": "24px",
|
||||
"height": "24px"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Filler"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "{{stats.total_models}}",
|
||||
"fontSize": "32px",
|
||||
"fontWeight": "700",
|
||||
"color": "#F1F5F9",
|
||||
"lineHeight": "1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "可用模型数",
|
||||
"fontSize": "14px",
|
||||
"color": "#94A3B8",
|
||||
"marginTop": "4px"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user