feat(memory): integrate Mem0 for enhanced conversational memory
Some checks failed
Build and Push Docker / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker / build-and-push (push) Has been cancelled
This commit is contained in:
78
test_mem0_service.py
Normal file
78
test_mem0_service.py
Normal file
@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Test script for memory module-based chat service."""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from api.chat_service import ChatService
|
||||
|
||||
|
||||
def test_chat_service():
|
||||
"""Test the memory module-based chat service."""
|
||||
print("=== Testing Memory Module-based Chat Service ===\n")
|
||||
|
||||
# Initialize chat service
|
||||
chat_service = ChatService("test_user")
|
||||
chat_service.initialize()
|
||||
|
||||
# Test conversations
|
||||
test_inputs = [
|
||||
"Hi, my name is Alice and I love science fiction movies.",
|
||||
"What kind of movies do I like?",
|
||||
"I also enjoy reading science fiction books.",
|
||||
"Tell me about my hobbies and interests.",
|
||||
"I went to Paris last summer and loved it!",
|
||||
"Where did I travel recently?"
|
||||
]
|
||||
|
||||
print("Starting conversation test...\n")
|
||||
|
||||
for i, user_input in enumerate(test_inputs, 1):
|
||||
print(f"--- Test {i} ---")
|
||||
print(f"User: {user_input}")
|
||||
|
||||
# Get response from chat service
|
||||
result = chat_service.chat(user_input, include_audio=False)
|
||||
|
||||
if result["success"]:
|
||||
print(f"Assistant: {result['response']}")
|
||||
print(f"Status: Success")
|
||||
else:
|
||||
print(f"Error: {result['error']}")
|
||||
print(f"Status: Failed")
|
||||
|
||||
print()
|
||||
|
||||
# Test memory retrieval
|
||||
print("\n--- Testing Memory Retrieval ---")
|
||||
memories_result = chat_service.get_user_memories()
|
||||
|
||||
if memories_result["success"]:
|
||||
print(f"Total memories stored: {memories_result['count']}")
|
||||
print("\nStored memories:")
|
||||
for i, memory in enumerate(memories_result["memories"], 1):
|
||||
print(f"{i}. {memory.get('memory', 'N/A')}")
|
||||
else:
|
||||
print(f"Failed to retrieve memories: {memories_result['error']}")
|
||||
|
||||
# Test memory search
|
||||
print("\n--- Testing Memory Search ---")
|
||||
search_queries = ["movies", "travel", "hobbies"]
|
||||
|
||||
for query in search_queries:
|
||||
print(f"\nSearching for '{query}':")
|
||||
search_result = chat_service.search_memories(query)
|
||||
|
||||
if search_result["success"]:
|
||||
print(f"Found {search_result['count']} memories:")
|
||||
for memory in search_result["memories"]:
|
||||
print(f"- {memory.get('memory', 'N/A')}")
|
||||
else:
|
||||
print(f"Search failed: {search_result['error']}")
|
||||
|
||||
print("\n=== Test completed ===")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_chat_service()
|
Reference in New Issue
Block a user