|
""" |
|
Simple test script for conversation history. |
|
""" |
|
|
|
from utils import SocialGraphManager |
|
|
|
|
|
graph_manager = SocialGraphManager("social_graph.json") |
|
|
|
|
|
person_id = "emma" |
|
person_context = graph_manager.get_person_context(person_id) |
|
|
|
|
|
print(f"\nConversation history for {person_context.get('name')}:") |
|
conversation_history = person_context.get("conversation_history", []) |
|
|
|
if not conversation_history: |
|
print("No conversation history found.") |
|
else: |
|
for i, conversation in enumerate(conversation_history): |
|
print(f"\nConversation {i+1}:") |
|
|
|
|
|
timestamp = conversation.get("timestamp", "") |
|
print(f"Timestamp: {timestamp}") |
|
|
|
|
|
messages = conversation.get("messages", []) |
|
for message in messages: |
|
speaker = message.get("speaker", "Unknown") |
|
text = message.get("text", "") |
|
print(f" {speaker}: \"{text}\"") |
|
|
|
|
|
print("\nAdding a new conversation...") |
|
new_messages = [ |
|
{"speaker": "Emma", "text": "How are you feeling this afternoon?"}, |
|
{"speaker": "Will", "text": "A bit tired, but the new medication seems to be helping with the muscle stiffness."}, |
|
{"speaker": "Emma", "text": "That's good to hear. Do you want me to bring you anything?"}, |
|
{"speaker": "Will", "text": "A cup of tea would be lovely, thanks."} |
|
] |
|
|
|
success = graph_manager.add_conversation(person_id, new_messages) |
|
if success: |
|
print("New conversation added successfully.") |
|
else: |
|
print("Failed to add new conversation.") |
|
|
|
|
|
updated_person_context = graph_manager.get_person_context(person_id) |
|
updated_conversation_history = updated_person_context.get("conversation_history", []) |
|
|
|
|
|
print("\nUpdated conversation history:") |
|
if not updated_conversation_history: |
|
print("No conversation history found.") |
|
else: |
|
|
|
print(f"Found {len(updated_conversation_history)} conversations.") |
|
|
|
|
|
most_recent = sorted( |
|
updated_conversation_history, |
|
key=lambda x: x.get("timestamp", ""), |
|
reverse=True |
|
)[0] |
|
|
|
|
|
timestamp = most_recent.get("timestamp", "") |
|
print(f"Most recent timestamp: {timestamp}") |
|
|
|
|
|
messages = most_recent.get("messages", []) |
|
for message in messages: |
|
speaker = message.get("speaker", "Unknown") |
|
text = message.get("text", "") |
|
print(f" {speaker}: \"{text}\"") |
|
|
|
print("\nTest completed.") |
|
|