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 | Create your personal AI Study Buddy that remembers what you’ve studied (and where you struggled), |
| #3 | helps with spaced repetition and topic review, personalizes responses using your past interactions. |
| #4 | Supports both text and PDF/image inputs. |
| #5 | |
| #6 | In order to run this file, you need to set up your Mem0 API at Mem0 platform and also need a OpenAI API key. |
| #7 | export OPENAI_API_KEY="your_openai_api_key" |
| #8 | export MEM0_API_KEY="your_mem0_api_key" |
| #9 | """ |
| #10 | |
| #11 | import asyncio |
| #12 | |
| #13 | from agents import Agent, Runner |
| #14 | |
| #15 | from mem0 import MemoryClient |
| #16 | |
| #17 | client = MemoryClient() |
| #18 | |
| #19 | # Define your study buddy agent |
| #20 | study_agent = Agent( |
| #21 | name="StudyBuddy", |
| #22 | instructions="""You are a helpful study coach. You: |
| #23 | - Track what the user has studied before |
| #24 | - Identify topics the user has struggled with (e.g., "I'm confused", "this is hard") |
| #25 | - Help with spaced repetition by suggesting topics to revisit based on last review time |
| #26 | - Personalize answers using stored memories |
| #27 | - Summarize PDFs or notes the user uploads""", |
| #28 | ) |
| #29 | |
| #30 | |
| #31 | # Upload and store PDF to Mem0 |
| #32 | def upload_pdf(pdf_url: str, user_id: str): |
| #33 | pdf_message = {"role": "user", "content": {"type": "pdf_url", "pdf_url": {"url": pdf_url}}} |
| #34 | client.add([pdf_message], user_id=user_id) |
| #35 | print("✅ PDF uploaded and processed into memory.") |
| #36 | |
| #37 | |
| #38 | # Main interaction loop with your personal study buddy |
| #39 | async def study_buddy(user_id: str, topic: str, user_input: str): |
| #40 | memories = client.search(f"{topic}", user_id=user_id) |
| #41 | memory_context = "n".join(f"- {m['memory']}" for m in memories) |
| #42 | |
| #43 | prompt = f""" |
| #44 | You are helping the user study the topic: {topic}. |
| #45 | Here are past memories from previous sessions: |
| #46 | {memory_context} |
| #47 | |
| #48 | Now respond to the user's new question or comment: |
| #49 | {user_input} |
| #50 | """ |
| #51 | result = await Runner.run(study_agent, prompt) |
| #52 | response = result.final_output |
| #53 | |
| #54 | client.add( |
| #55 | [{"role": "user", "content": f"""Topic: {topic}nUser: {user_input}nnStudy Assistant: {response}"""}], |
| #56 | user_id=user_id, |
| #57 | metadata={"topic": topic}, |
| #58 | ) |
| #59 | |
| #60 | return response |
| #61 | |
| #62 | |
| #63 | # Example usage |
| #64 | async def main(): |
| #65 | user_id = "Ajay" |
| #66 | pdf_url = "https://pages.physics.ua.edu/staff/fabi/ph101/classnotes/8RotD101.pdf" |
| #67 | upload_pdf(pdf_url, user_id) # Upload a relevant lecture PDF to memory |
| #68 | |
| #69 | topic = "Lagrangian Mechanics" |
| #70 | # Demonstrate tracking previously learned topics |
| #71 | print(await study_buddy(user_id, topic, "Can you remind me of what we discussed about generalized coordinates?")) |
| #72 | |
| #73 | # Demonstrate weakness detection |
| #74 | print(await study_buddy(user_id, topic, "I still don’t get what frequency domain really means.")) |
| #75 | |
| #76 | # Demonstrate spaced repetition prompting |
| #77 | topic = "Momentum Conservation" |
| #78 | print( |
| #79 | await study_buddy( |
| #80 | user_id, topic, "I think we covered this last week. Is it time to review momentum conservation again?" |
| #81 | ) |
| #82 | ) |
| #83 | |
| #84 | |
| #85 | if __name__ == "__main__": |
| #86 | asyncio.run(main()) |
| #87 |