repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: Personalized AI Tutor |
| #3 | description: "Keep student progress and preferences persistent across tutoring sessions." |
| #4 | --- |
| #5 | |
| #6 | |
| #7 | You can create a personalized AI Tutor using Mem0. This guide will walk you through the necessary steps and provide the complete code to get you started. |
| #8 | |
| #9 | ## Overview |
| #10 | |
| #11 | The Personalized AI Tutor leverages Mem0 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. |
| #12 | |
| #13 | ## Setup |
| #14 | |
| #15 | Before you begin, ensure you have the required dependencies installed. You can install the necessary packages using pip: |
| #16 | |
| #17 | ```bash |
| #18 | pip install openai mem0ai |
| #19 | ``` |
| #20 | |
| #21 | ## Full Code Example |
| #22 | |
| #23 | Below is the complete code to create and interact with a Personalized AI Tutor using Mem0: |
| #24 | |
| #25 | ```python |
| #26 | import os |
| #27 | from openai import OpenAI |
| #28 | from mem0 import Memory |
| #29 | |
| #30 | # Set the OpenAI API key |
| #31 | os.environ['OPENAI_API_KEY'] = 'sk-xxx' |
| #32 | |
| #33 | # Initialize the OpenAI client |
| #34 | client = OpenAI() |
| #35 | |
| #36 | class PersonalAITutor: |
| #37 | def __init__(self): |
| #38 | """ |
| #39 | Initialize the PersonalAITutor with memory configuration and OpenAI client. |
| #40 | """ |
| #41 | config = { |
| #42 | "vector_store": { |
| #43 | "provider": "qdrant", |
| #44 | "config": { |
| #45 | "host": "localhost", |
| #46 | "port": 6333, |
| #47 | } |
| #48 | }, |
| #49 | } |
| #50 | self.memory = Memory.from_config(config) |
| #51 | self.client = client |
| #52 | self.app_id = "app-1" |
| #53 | |
| #54 | def ask(self, question, user_id=None): |
| #55 | """ |
| #56 | Ask a question to the AI and store the relevant facts in memory |
| #57 | |
| #58 | :param question: The question to ask the AI. |
| #59 | :param user_id: Optional user ID to associate with the memory. |
| #60 | """ |
| #61 | # Start a streaming response request to the AI |
| #62 | response = self.client.responses.create( |
| #63 | model="gpt-4.1-nano-2025-04-14", |
| #64 | instructions="You are a personal AI Tutor.", |
| #65 | input=question, |
| #66 | stream=True |
| #67 | ) |
| #68 | |
| #69 | # Store the question in memory |
| #70 | self.memory.add(question, user_id=user_id, metadata={"app_id": self.app_id}) |
| #71 | |
| #72 | # Print the response from the AI in real-time |
| #73 | for event in response: |
| #74 | if event.type == "response.output_text.delta": |
| #75 | print(event.delta, end="") |
| #76 | |
| #77 | def get_memories(self, user_id=None): |
| #78 | """ |
| #79 | Retrieve all memories associated with the given user ID. |
| #80 | |
| #81 | :param user_id: Optional user ID to filter memories. |
| #82 | :return: List of memories. |
| #83 | """ |
| #84 | return self.memory.get_all(user_id=user_id) |
| #85 | |
| #86 | # Instantiate the PersonalAITutor |
| #87 | ai_tutor = PersonalAITutor() |
| #88 | |
| #89 | # Define a user ID |
| #90 | user_id = "john_doe" |
| #91 | |
| #92 | # Ask a question |
| #93 | ai_tutor.ask("I am learning introduction to CS. What is queue? Briefly explain.", user_id=user_id) |
| #94 | ``` |
| #95 | |
| #96 | ### Fetching Memories |
| #97 | |
| #98 | You can fetch all the memories at any point in time using the following code: |
| #99 | |
| #100 | ```python |
| #101 | memories = ai_tutor.get_memories(user_id=user_id) |
| #102 | for m in memories['results']: |
| #103 | print(m['memory']) |
| #104 | ``` |
| #105 | |
| #106 | ## Key Points |
| #107 | |
| #108 | - **Initialization**: The PersonalAITutor class is initialized with the necessary memory configuration and OpenAI client setup |
| #109 | - **Asking Questions**: The ask method sends a question to the AI and stores the relevant information in memory |
| #110 | - **Retrieving Memories**: The get_memories method fetches all stored memories associated with a user |
| #111 | |
| #112 | ## Conclusion |
| #113 | |
| #114 | As the conversation progresses, Mem0'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. |
| #115 | |
| #116 | --- |
| #117 | |
| #118 | <CardGroup cols={2}> |
| #119 | <Card title="Build a Mem0 Companion" icon="users" href="/cookbooks/essentials/building-ai-companion"> |
| #120 | Learn the foundations of memory-powered companions with production-ready patterns. |
| #121 | </Card> |
| #122 | <Card title="Travel Assistant with Mem0" icon="plane" href="/cookbooks/companions/travel-assistant"> |
| #123 | Build a travel companion that remembers preferences and past conversations. |
| #124 | </Card> |
| #125 | </CardGroup> |
| #126 |