feat: 任务详情 LLM 请求数(cost_records 存 completions)
This commit is contained in:
1 parent
2ff8975f43
commit
ccb5a8638d
9 files changed
+215
-77
No files matched your search
+21
-6
@@ -223,6 +223,7 @@ class CostStore:
|
||||
usd_micros INTEGER,
|
||||
source TEXT,
|
||||
fallback_count INTEGER DEFAULT 0,
|
||||
completions INTEGER DEFAULT 0,
|
||||
day TEXT,
|
||||
created_at REAL
|
||||
)"""
|
||||
@@ -246,6 +247,14 @@ class CostStore:
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
if "completions" not in cols:
|
||||
try:
|
||||
conn.execute(
|
||||
"ALTER TABLE cost_records"
|
||||
" ADD COLUMN completions INTEGER DEFAULT 0")
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def __init__(self, db_path):
|
||||
self.db_path = db_path
|
||||
@@ -280,7 +289,7 @@ class CostStore:
|
||||
|
||||
def record(self, task_id, project_id, model, input_tokens=0,
|
||||
output_tokens=0, cached_input_tokens=0, usd_micros=None,
|
||||
source="actual", fallback_count=0):
|
||||
source="actual", fallback_count=0, completions=0):
|
||||
"""Insert one cost record; returns its row id.
|
||||
|
||||
``total_tokens`` is computed as input + output, and ``day`` is
|
||||
@@ -305,11 +314,12 @@ class CostStore:
|
||||
"""INSERT INTO cost_records
|
||||
(task_id, project_id, model, input_tokens, output_tokens,
|
||||
cached_input_tokens, total_tokens, usd_micros, source,
|
||||
fallback_count, day, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
fallback_count, completions, day, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(task_id, project_id, model, input_tokens, output_tokens,
|
||||
cached_input_tokens, total_tokens, usd_micros, source,
|
||||
int(fallback_count or 0), day, created_at),
|
||||
int(fallback_count or 0), int(completions or 0), day,
|
||||
created_at),
|
||||
)
|
||||
conn.commit()
|
||||
return cursor.lastrowid
|
||||
@@ -350,7 +360,8 @@ class CostStore:
|
||||
COALESCE(SUM(cached_input_tokens), 0),
|
||||
COALESCE(SUM(CASE WHEN source = 'actual'
|
||||
AND usd_micros IS NULL
|
||||
THEN total_tokens ELSE 0 END), 0)
|
||||
THEN total_tokens ELSE 0 END), 0),
|
||||
COALESCE(SUM(completions), 0)
|
||||
FROM cost_records WHERE %s""" % where,
|
||||
params,
|
||||
).fetchone()
|
||||
@@ -358,7 +369,7 @@ class CostStore:
|
||||
if conn is not self._conn:
|
||||
conn.close()
|
||||
(total_tokens, usd_micros, turns, fallback_count, actual,
|
||||
estimated, cached, unpriced) = row
|
||||
estimated, cached, unpriced, completions) = row
|
||||
return {
|
||||
"total_tokens": int(total_tokens),
|
||||
"usd_micros": int(usd_micros),
|
||||
@@ -370,6 +381,10 @@ class CostStore:
|
||||
# usd 求和只覆盖有价的行;无价 actual 行的 token 在此,
|
||||
# 不会被静默算成 0 美元。
|
||||
"unpriced_actual_tokens": int(unpriced),
|
||||
# LLM 请求数:host.py 每回合汇总的 completions 之和
|
||||
# (每个 thread/tokenUsage/updated 算一次上游补全);
|
||||
# turns 只是记账行数,两者不是一回事。
|
||||
"llm_requests": int(completions),
|
||||
}
|
||||
|
||||
def report_by_task(self, task_id) -> dict:
|
||||
|
||||
Reference in new issue
Block a user