Overview
The Personalized AI Companion leverages Mem0 to retain information across interactions, enabling a tailored learning experience. It creates memories for each user interaction and integrates with OpenAI’s GPT models to provide detailed and context-aware responses to user queries.Setup
Before you begin, ensure you have Node.js installed and create a new project. Install the required dependencies using npm:Full Code Example
Below is the complete code to create and interact with an AI Companion using Mem0:Key Components
-
Initialization
- The code initializes both OpenAI and Mem0 Memory clients
- Uses Node.js’s built-in readline module for command-line interaction
-
Memory Management (chatWithMemories function)
- Retrieves relevant memories using Mem0’s search functionality
- Constructs a system prompt that includes past memories
- Makes API calls to OpenAI for generating responses
- Stores new interactions in memory
-
Interactive Chat Interface (main function)
- Creates a command-line interface for user interaction
- Handles user input and displays AI responses
- Includes graceful exit functionality