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 Assistant powered by memory that supports both text and images and remembers your preferences |
| #3 | |
| #4 | In order to run this file, you need to set up your Mem0 API at Mem0 platform and also need a OpenAI API key. |
| #5 | export OPENAI_API_KEY="your_openai_api_key" |
| #6 | export MEM0_API_KEY="your_mem0_api_key" |
| #7 | """ |
| #8 | |
| #9 | import base64 |
| #10 | from pathlib import Path |
| #11 | |
| #12 | from agno.agent import Agent |
| #13 | from agno.media import Image |
| #14 | from agno.models.openai import OpenAIChat |
| #15 | |
| #16 | from mem0 import MemoryClient |
| #17 | |
| #18 | # Initialize the Mem0 client |
| #19 | client = MemoryClient() |
| #20 | |
| #21 | # Define the agent |
| #22 | agent = Agent( |
| #23 | name="Personal Agent", |
| #24 | model=OpenAIChat(id="gpt-4.1-nano-2025-04-14"), |
| #25 | description="You are a helpful personal agent that helps me with day to day activities." |
| #26 | "You can process both text and images.", |
| #27 | markdown=True, |
| #28 | ) |
| #29 | |
| #30 | |
| #31 | # Function to handle user input with memory integration with support for images |
| #32 | def chat_user(user_input: str = None, user_id: str = "user_123", image_path: str = None): |
| #33 | if image_path: |
| #34 | with open(image_path, "rb") as image_file: |
| #35 | base64_image = base64.b64encode(image_file.read()).decode("utf-8") |
| #36 | |
| #37 | # First: the text message |
| #38 | text_msg = {"role": "user", "content": user_input} |
| #39 | |
| #40 | # Second: the image message |
| #41 | image_msg = { |
| #42 | "role": "user", |
| #43 | "content": {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}}, |
| #44 | } |
| #45 | |
| #46 | # Send both as separate message objects |
| #47 | client.add([text_msg, image_msg], user_id=user_id) |
| #48 | print("✅ Image uploaded and stored in memory.") |
| #49 | |
| #50 | if user_input: |
| #51 | memories = client.search(user_input, user_id=user_id) |
| #52 | memory_context = "\n".join(f"- {m['memory']}" for m in memories) |
| #53 | |
| #54 | prompt = f""" |
| #55 | You are a helpful personal assistant who helps user with his day-to-day activities and keep track of everything. |
| #56 | |
| #57 | Your task is to: |
| #58 | 1. Analyze the given image (if present) and extract meaningful details to answer the user's question. |
| #59 | 2. Use your past memory of the user to personalize your answer. |
| #60 | 3. Combine the image content and memory to generate a helpful, context-aware response. |
| #61 | |
| #62 | Here is what remember about the user: |
| #63 | {memory_context} |
| #64 | |
| #65 | User question: |
| #66 | {user_input} |
| #67 | """ |
| #68 | if image_path: |
| #69 | response = agent.run(prompt, images=[Image(filepath=Path(image_path))]) |
| #70 | else: |
| #71 | response = agent.run(prompt) |
| #72 | client.add(f"User: {user_input}\nAssistant: {response.content}", user_id=user_id) |
| #73 | return response.content |
| #74 | |
| #75 | return "No user input or image provided." |
| #76 | |
| #77 | |
| #78 | # Example Usage |
| #79 | user_id = "user_123" |
| #80 | print(chat_user("What did I ask you to remind me about?", user_id)) |
| #81 | # # OUTPUT: You asked me to remind you to call your mom tomorrow. 📞 |
| #82 | # |
| #83 | print(chat_user("When is my test?", user_id=user_id)) |
| #84 | # OUTPUT: Your pilot's test is on your birthday, which is in five days. You're turning 25! |
| #85 | # Good luck with your preparations, and remember to take some time to relax amidst the studying. |
| #86 | |
| #87 | print( |
| #88 | chat_user( |
| #89 | "This is the picture of what I brought with me in the trip to Bahamas", |
| #90 | image_path="travel_items.jpeg", # this will be added to Mem0 memory |
| #91 | user_id=user_id, |
| #92 | ) |
| #93 | ) |
| #94 | print(chat_user("hey can you quickly tell me if brought my sunglasses to my trip, not able to find", user_id=user_id)) |
| #95 | # OUTPUT: Yes, you did bring your sunglasses on your trip to the Bahamas along with your laptop, face masks and other items.. |
| #96 | # Since you can't find them now, perhaps check the pockets of jackets you wore or in your luggage compartments. |
| #97 |