better:优化统计和心流提示词

This commit is contained in:
SengokuCola
2025-03-28 09:34:21 +08:00
parent de8d2aba68
commit 94a554699e
6 changed files with 29 additions and 20 deletions

View File

@@ -44,13 +44,19 @@ class LLMStatistics:
def _record_online_time(self):
"""记录在线时间"""
try:
current_time = datetime.now()
# 检查5分钟内是否已有记录
recent_record = db.online_time.find_one({
"timestamp": {
"$gte": current_time - timedelta(minutes=5)
}
})
if not recent_record:
db.online_time.insert_one({
"timestamp": datetime.now(),
"timestamp": current_time,
"duration": 5 # 5分钟
})
except Exception:
logger.exception("记录在线时间失败")
def _collect_statistics_for_period(self, start_time: datetime) -> Dict[str, Any]:
"""收集指定时间段的LLM请求统计数据