fix(llmage): 修复backup_accounted_llmusage中sor.execute()返回值误用(MySQL cursor.execute返回None非rowcount)

This commit is contained in:
yumoqing 2026-05-24 22:02:52 +08:00
parent 7911750127
commit 02366c9748
4 changed files with 71 additions and 10 deletions

53
dat/qwen3.7-max.txt Normal file
View 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 uapiOpenAI兼容接口
3. 如果qwen3.7-max有特殊的推理模式如思考/非思考切换),可能需要额外的配置
4. 之前提到的 startReasoning is not defined 前端报错问题需要单独排查可能与harnessed_reasoning的bricks前端代码有关

Binary file not shown.

View File

@ -240,28 +240,36 @@ async def llm_accoung_failed(luid, reason=None):
async def backup_accounted_llmusage(cutoff_date): async def backup_accounted_llmusage(cutoff_date):
"""Backup accounted records with use_date < cutoff_date to history table using single SQL statements.""" """Backup accounted records with use_date < cutoff_date to history table."""
env = ServerEnv() env = ServerEnv()
ts = env.timestampstr() ts = env.timestampstr()
async with get_sor_context(env, 'llmage') as sor: async with get_sor_context(env, 'llmage') as sor:
# Step 0: Count records to backup
count_sql = """SELECT COUNT(*) as cnt FROM llmusage
WHERE accounting_status='accounted' AND use_date < ${cutoff_date}$"""
count_recs = await sor.sqlExe(count_sql, {'cutoff_date': cutoff_date})
total = count_recs[0].cnt if count_recs else 0
if total == 0:
debug(f'backup_accounted_llmusage: no records to backup for use_date < {cutoff_date}')
return 0
debug(f'backup_accounted_llmusage: {total} records to backup')
# Step 1: INSERT INTO history SELECT from main table # Step 1: INSERT INTO history SELECT from main table
insert_sql = """INSERT INTO llmusage_history insert_sql = """INSERT INTO llmusage_history
(id, llmid, use_date, use_time, userid, usages, ioinfo, transno, responsed_seconds, finish_seconds, status, taskid, amount, cost, userorgid, ownerid, accounting_status, backup_time) (id, llmid, use_date, use_time, userid, usages, ioinfo, transno, responsed_seconds, finish_seconds, status, taskid, amount, cost, userorgid, ownerid, accounting_status, backup_time)
SELECT id, llmid, use_date, use_time, userid, usages, ioinfo, transno, responsed_seconds, finish_seconds, status, taskid, amount, cost, userorgid, ownerid, accounting_status, ${ts}$ SELECT id, llmid, use_date, use_time, userid, usages, ioinfo, transno, responsed_seconds, finish_seconds, status, taskid, amount, cost, userorgid, ownerid, accounting_status, ${ts}$
FROM llmusage FROM llmusage
WHERE accounting_status='accounted' AND use_date < ${cutoff_date}$""" WHERE accounting_status='accounted' AND use_date < ${cutoff_date}$"""
result = await sor.execute(insert_sql, {'cutoff_date': cutoff_date, 'ts': ts}) await sor.execute(insert_sql, {'cutoff_date': cutoff_date, 'ts': ts})
inserted = result if isinstance(result, int) else 0 debug(f'backup_accounted_llmusage: inserted {total} records to history')
debug(f'backup_accounted_llmusage: {inserted} records inserted to history')
if inserted > 0: # Step 2: DELETE from main table
# Step 2: DELETE from main table delete_sql = """DELETE FROM llmusage
delete_sql = """DELETE FROM llmusage
WHERE accounting_status='accounted' AND use_date < ${cutoff_date}$""" WHERE accounting_status='accounted' AND use_date < ${cutoff_date}$"""
await sor.execute(delete_sql, {'cutoff_date': cutoff_date}) await sor.execute(delete_sql, {'cutoff_date': cutoff_date})
debug(f'backup_accounted_llmusage: {inserted} records deleted from main table') debug(f'backup_accounted_llmusage: deleted {total} records from main table')
return inserted return total
async def get_failed_accounting_records(filters=None, page=1, page_size=50): async def get_failed_accounting_records(filters=None, page=1, page_size=50):

Binary file not shown.