📢 Announcing our research paper: Zentry achieves 26% higher accuracy than OpenAI Memory, 91% lower latency, and 90% token savings! Read the paper to learn how we're revolutionizing AI agent memory.
You can create a personalized AI Tutor using Zentry. This guide will walk you through the necessary steps and provide the complete code to get you started.
The Personalized AI Tutor leverages Zentry to retain information across interactions, enabling a tailored learning experience. By integrating with OpenAI’s GPT-4 model, the tutor can provide detailed and context-aware responses to user queries.
Below is the complete code to create and interact with a Personalized AI Tutor using Zentry:
Copy
import os from openai import OpenAIfrom Zentry import Memory# Set the OpenAI API keyos.environ['OPENAI_API_KEY'] = 'sk-xxx'# Initialize the OpenAI clientclient = OpenAI()class PersonalAITutor: def __init__(self): """ Initialize the PersonalAITutor with memory configuration and OpenAI client. """ config = { "vector_store": { "provider": "qdrant", "config": { "host": "localhost", "port": 6333, } }, } self.memory = Memory.from_config(config) self.client = client self.app_id = "app-1" def ask(self, question, user_id=None): """ Ask a question to the AI and store the relevant facts in memory :param question: The question to ask the AI. :param user_id: Optional user ID to associate with the memory. """ # Start a streaming response request to the AI response = self.client.responses.create( model="gpt-4o", instructions="You are a personal AI Tutor.", input=question, stream=True ) # Store the question in memory self.memory.add(question, user_id=user_id, metadata={"app_id": self.app_id}) # Print the response from the AI in real-time for event in response: if event.type == "response.output_text.delta": print(event.delta, end="") def get_memories(self, user_id=None): """ Retrieve all memories associated with the given user ID. :param user_id: Optional user ID to filter memories. :return: List of memories. """ return self.memory.get_all(user_id=user_id)# Instantiate the PersonalAITutorai_tutor = PersonalAITutor()# Define a user IDuser_id = "john_doe"# Ask a questionai_tutor.ask("I am learning introduction to CS. What is queue? Briefly explain.", user_id=user_id)
As the conversation progresses, Zentry’s memory automatically updates based on the interactions, providing a continuously improving personalized learning experience. This setup ensures that the AI Tutor can offer contextually relevant and accurate responses, enhancing the overall educational process.