File size: 3,222 Bytes
0919d5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""
Test script to verify the Memory Chat application works correctly.
"""

import sys
import os

# Add the project directory to the Python path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

def test_memory_manager():
    """Test the memory manager functionality."""
    print("Testing Memory Manager...")

    from memory_manager import MemoryManager

    # Create a test memory manager
    mm = MemoryManager("test_memories")

    # Test adding a memory
    memory = mm.add_memory(
        content="I love pizza and hate mushrooms",
        context="Testing memory recording",
        memory_type="preference"
    )

    print(f"Added memory: {memory['content']}")
    print(f"Memory ID: {memory['id']}")

    # Test retrieving memories
    relevant = mm.retrieve_memories("What do I like to eat?")
    print(f"Found {len(relevant)} relevant memories")

    # Test summary
    summary = mm.get_summary()
    print(f"Total memories: {summary['total_memories']}")
    print(f"Memory types: {summary['memory_types']}")

    # Test timeline
    print(f"Timeline file: {mm.timeline_file}")

    print("✓ Memory Manager tests passed!")
    return True

def test_chat_interface():
    """Test the chat interface functionality."""
    print("\nTesting Chat Interface...")

    from chat_interface import HuggingFaceChat

    # Create a test chat interface
    chat = HuggingFaceChat(model_name="microsoft/DialoGPT-small")

    # Test model info
    info = chat.get_model_info()
    print(f"Model: {info['model_name']}")
    print(f"Device: {info['device']}")
    print(f"Available: {info['available']}")

    if info['available']:
        # Test generating a response
        response = chat.generate_response("Hello, how are you?", max_length=50)
        print(f"Generated response: {response[:50]}...")
        print("✓ Chat Interface tests passed!")
    else:
        print("⚠ Model not available - skipping response generation test")

    return True

def test_main_app():
    """Test the main application functionality."""
    print("\nTesting Main Application...")

    from app import MemoryChatApp

    # Create the main app
    app = MemoryChatApp()

    # Test memory recording logic
    should_record = app.should_record_memory(
        "Remember that I love pizza and hate mushrooms",
        "I'll remember that you love pizza and hate mushrooms"
    )
    print(f"Should record memory: {should_record}")

    # Test memory extraction
    content = app.extract_memory_content(
        "My name is John and I live in New York",
        "Nice to meet you, John!"
    )
    print(f"Extracted content: {content}")

    print("✓ Main Application tests passed!")
    return True

def main():
    """Run all tests."""
    print("🧪 Running Memory Chat Application Tests\n")

    try:
        test_memory_manager()
        test_chat_interface()
        test_main_app()

        print("\n🎉 All tests passed successfully!")
        print("\nTo run the application, use:")
        print("python app.py")

    except Exception as e:
        print(f"\n❌ Test failed with error: {e}")
        import traceback
        traceback.print_exc()
        return False

if __name__ == "__main__":
    main()