feat(fam-edge): 云端模型调用统计 - 新增 model_calls 表(provider/model/时间/耗时/成功/失败原因),gemini/nvidia 每次请求经 model_call_hook 记录并随 sync delta 下发;gemini 支持模型级 model_timeouts(lite 实测22.6s×4≈90s)

This commit is contained in:
ericwyuan
2026-08-21 12:21:49 +08:00
parent 1b0f62e5e9
commit b87b38b140
6 changed files with 90 additions and 3 deletions

View File

@@ -81,8 +81,21 @@ class OracleDB:
key TEXT PRIMARY KEY,
value TEXT
);
CREATE TABLE IF NOT EXISTS model_calls (
id INTEGER PRIMARY KEY AUTOINCREMENT,
provider TEXT,
model TEXT,
video_id INTEGER,
filename TEXT,
started_at TEXT,
duration_sec REAL,
success INTEGER DEFAULT 0,
error TEXT,
created_at TEXT
);
CREATE INDEX IF NOT EXISTS idx_videos_updated ON videos(updated_at);
CREATE INDEX IF NOT EXISTS idx_events_video ON events(video_id);
CREATE INDEX IF NOT EXISTS idx_model_calls_created ON model_calls(created_at);
""")
# 兼容旧库:补 retry_count 列(生产-消费队列重试上限用)
cols = [r[1] for r in c.execute("PRAGMA table_info(videos)").fetchall()]
@@ -101,6 +114,20 @@ class OracleDB:
cur = self._conn.execute("SELECT * FROM videos WHERE id=?", (video_id,))
return cur.fetchone()
def record_model_call(self, provider: str, model: str,
video_id, filename,
started_at: str, duration_sec: float,
success: bool, error: str = ''):
"""记录一次云端模型调用(前端统计成功/失败/耗时/失败原因)"""
now = _now_iso()
self._conn.execute(
"INSERT INTO model_calls (provider, model, video_id, filename, "
"started_at, duration_sec, success, error, created_at) "
"VALUES (?,?,?,?,?,?,?,?,?)",
(provider, model, video_id, filename, started_at,
duration_sec, 1 if success else 0, error or '', now))
self._conn.commit()
def ensure_video(self, filename: str, local_path: str,
camera_name: str = '', event_start_time: str = '',
duration_sec: float = 0.0, drive_file_id: str = '') -> int:
@@ -220,6 +247,10 @@ class OracleDB:
people = self._conn.execute(
"SELECT * FROM people WHERE updated_at > ? ORDER BY id ASC", (since_iso,)
).fetchall()
# 模型调用统计created_at >= since 配合 NAS 端幂等 upsert 防漏同秒记录)
model_calls = self._conn.execute(
"SELECT * FROM model_calls WHERE created_at >= ? ORDER BY id ASC",
(since_iso,)).fetchall()
def _ser(row):
d = dict(row)
@@ -229,6 +260,7 @@ class OracleDB:
"videos": [_ser(v) for v in videos],
"events": [_ser(e) for e in events],
"people": [_ser(p) for p in people],
"model_calls": [_ser(m) for m in model_calls],
"server_time": _now_iso(),
}