# usage_logger.py import os, json, time STATS_FILE = "/data/ai_stats.json" def log_request(user_id: str): if os.path.exists(STATS_FILE): with open(STATS_FILE, "r") as f: stats = json.load(f) else: stats = {"total": 0, "users": {}} stats["total"] += 1 stats["users"][user_id] = stats["users"].get(user_id, 0) + 1 stats["last_request"] = time.strftime("%Y-%m-%d %H:%M:%S") with open(STATS_FILE, "w") as f: json.dump(stats, f, indent=2) def get_stats(): if os.path.exists(STATS_FILE): with open(STATS_FILE, "r") as f: return json.load(f) return {"message": "No stats found."}