Deepseek / analysis_tools.py
Leonydis137's picture
Update analysis_tools.py
86e1533 verified
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
from memory_manager import retrieve_relevant
def analyze_sentiment_topics(conversation: list) -> dict:
"""Return placeholder sentiment and key topics."""
sentiments = ["Positive", "Neutral", "Negative"]
sentiment = np.random.choice(sentiments, p=[0.4, 0.4, 0.2])
topics = ["AI Ethics", "Policy", "Culture", "Technology", "Future"]
return {
"sentiment": sentiment,
"topics": np.random.choice(topics, 3, replace=False).tolist()
}
def plot_participation(conversation: list, save_path: str) -> str:
"""Save agent participation bar chart."""
agents = [msg['agent'] for msg in conversation]
counts = {agent: agents.count(agent) for agent in set(agents)}
plt.figure()
plt.bar(counts.keys(), counts.values())
plt.title("Agent Participation")
plt.tight_layout()
plt.savefig(save_path)
return save_path
def generate_knowledge_graph(conversation: list, save_path: str) -> str:
"""Save a simple directed graph of agent interactions."""
G = nx.DiGraph()
# Add nodes for each unique agent
agents = [msg['agent'] for msg in conversation]
for agent in set(agents):
G.add_node(agent)
# Randomly connect nodes
import random
nodes = list(G.nodes)
for _ in range(len(nodes) * 2):
a, b = random.sample(nodes, 2)
G.add_edge(a, b)
plt.figure()
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels=True, node_size=1500)
plt.title("Knowledge Graph")
plt.savefig(save_path)
return save_path