File size: 2,777 Bytes
b5cc3fd |
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 74 75 76 77 78 79 80 81 |
"""
Simple test script for conversation history.
"""
from utils import SocialGraphManager
# Initialize the social graph manager
graph_manager = SocialGraphManager("social_graph.json")
# Get a person with conversation history
person_id = "emma" # Emma has conversation history
person_context = graph_manager.get_person_context(person_id)
# Print the person's conversation history
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}:")
# Print the timestamp
timestamp = conversation.get("timestamp", "")
print(f"Timestamp: {timestamp}")
# Print the messages
messages = conversation.get("messages", [])
for message in messages:
speaker = message.get("speaker", "Unknown")
text = message.get("text", "")
print(f" {speaker}: \"{text}\"")
# Test adding a new conversation
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.")
# Get the updated person context
updated_person_context = graph_manager.get_person_context(person_id)
updated_conversation_history = updated_person_context.get("conversation_history", [])
# Print the updated conversation history
print("\nUpdated conversation history:")
if not updated_conversation_history:
print("No conversation history found.")
else:
# Count the conversations
print(f"Found {len(updated_conversation_history)} conversations.")
# Get the most recent conversation
most_recent = sorted(
updated_conversation_history,
key=lambda x: x.get("timestamp", ""),
reverse=True
)[0]
# Print the timestamp
timestamp = most_recent.get("timestamp", "")
print(f"Most recent timestamp: {timestamp}")
# Print the messages
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.")
|