""" 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()