File size: 1,476 Bytes
f43df85 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import logging
from collections import Counter
logger = logging.getLogger("ONYX")
class MemoryIntelligenceEngine:
def __init__(self, memory_manager):
self.memory_manager = memory_manager
# =========================
# ANALYZE MEMORY
# =========================
def analyze(self):
try:
history = self.memory_manager.load_memory()
themes = []
for exchange in history:
user_message = exchange.get("user", "")
if user_message:
themes.append(user_message.lower())
if not themes:
return {
"top_topics": [],
"count": 0
}
counter = Counter(themes)
most_common = counter.most_common(5)
return {
"top_topics": most_common,
"count": len(themes)
}
except Exception as e:
logger.error(f"Memory analysis error: {e}")
return {
"top_topics": [],
"count": 0
}
# =========================
# SUGGEST NEXT TOPIC
# =========================
def suggest_topic(self):
analysis = self.analyze()
if not analysis["top_topics"]:
return None
topic = analysis["top_topics"][0][0]
logger.info(f"Suggested topic from memory: {topic}")
return topic |