diff --git a/apps/api/src/api/v1/stats.py b/apps/api/src/api/v1/stats.py index f48ddf926..57eff5869 100644 --- a/apps/api/src/api/v1/stats.py +++ b/apps/api/src/api/v1/stats.py @@ -538,12 +538,33 @@ async def get_feedback_summary( negative += 1 # 萃取主題 (從 learning_notes) + # TODO Phase 7: 整合 OpenClaw LLM 進行智能主題萃取 notes = o.get("learning_notes") or o.get("notes") or "" if notes: - # 簡單關鍵字萃取 (未來可用 NLP) - for keyword in ["timeout", "memory", "network", "disk", "cpu", "connection"]: - if keyword.lower() in notes.lower(): - themes[keyword] = themes.get(keyword, 0) + 1 + notes_lower = notes.lower() + # 增強版關鍵字萃取 (按領域分類) + theme_keywords = { + # 效能類 + "timeout": ["timeout", "超時", "timed out", "deadline"], + "latency": ["latency", "延遲", "slow", "慢", "p99", "p95"], + "memory": ["memory", "記憶體", "oom", "heap", "內存"], + "cpu": ["cpu", "處理器", "high load", "負載"], + # 網路類 + "network": ["network", "網路", "dns", "connection refused"], + "connection": ["connection", "連線", "socket", "tcp"], + # 儲存類 + "disk": ["disk", "磁碟", "storage", "io", "iops"], + "database": ["database", "資料庫", "db", "query", "deadlock"], + # 容器類 + "pod": ["pod", "container", "restart", "crashloop"], + "scaling": ["scale", "擴容", "replica", "hpa"], + # 應用類 + "error": ["error", "錯誤", "exception", "fail"], + "config": ["config", "配置", "env", "secret"], + } + for theme, keywords in theme_keywords.items(): + if any(kw in notes_lower for kw in keywords): + themes[theme] = themes.get(theme, 0) + 1 # 取前 5 個常見主題 sorted_themes = sorted(themes.items(), key=lambda x: x[1], reverse=True)[:5]