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 | Memory-Powered Movie Recommendation Assistant (Grok 3 + Mem0) |
| #3 | This script builds a personalized movie recommender that remembers your preferences |
| #4 | (e.g. dislikes horror, loves romcoms) using Mem0 as a memory layer and Grok 3 for responses. |
| #5 | |
| #6 | In order to run this file, you need to set up your Mem0 API at Mem0 platform and also need an XAI API key. |
| #7 | export XAI_API_KEY="your_xai_api_key" |
| #8 | export MEM0_API_KEY="your_mem0_api_key" |
| #9 | """ |
| #10 | |
| #11 | import os |
| #12 | |
| #13 | from openai import OpenAI |
| #14 | |
| #15 | from mem0 import Memory |
| #16 | |
| #17 | # Configure Mem0 with Grok 3 and Qdrant |
| #18 | config = { |
| #19 | "vector_store": {"provider": "qdrant", "config": {"embedding_model_dims": 384}}, |
| #20 | "llm": { |
| #21 | "provider": "xai", |
| #22 | "config": { |
| #23 | "model": "grok-3-beta", |
| #24 | "temperature": 0.1, |
| #25 | "max_tokens": 2000, |
| #26 | }, |
| #27 | }, |
| #28 | "embedder": { |
| #29 | "provider": "huggingface", |
| #30 | "config": { |
| #31 | "model": "all-MiniLM-L6-v2" # open embedding model |
| #32 | }, |
| #33 | }, |
| #34 | } |
| #35 | |
| #36 | # Instantiate memory layer |
| #37 | memory = Memory.from_config(config) |
| #38 | |
| #39 | # Initialize Grok 3 client |
| #40 | grok_client = OpenAI( |
| #41 | api_key=os.getenv("XAI_API_KEY"), |
| #42 | base_url="https://api.x.ai/v1", |
| #43 | ) |
| #44 | |
| #45 | |
| #46 | def recommend_movie_with_memory(user_id: str, user_query: str): |
| #47 | # Retrieve prior memory about movies |
| #48 | past_memories = memory.search("movie preferences", user_id=user_id) |
| #49 | |
| #50 | prompt = user_query |
| #51 | if past_memories: |
| #52 | prompt += f"\nPreviously, the user mentioned: {past_memories}" |
| #53 | |
| #54 | # Generate movie recommendation using Grok 3 |
| #55 | response = grok_client.chat.completions.create(model="grok-3-beta", messages=[{"role": "user", "content": prompt}]) |
| #56 | recommendation = response.choices[0].message.content |
| #57 | |
| #58 | # Store conversation in memory |
| #59 | memory.add( |
| #60 | [{"role": "user", "content": user_query}, {"role": "assistant", "content": recommendation}], |
| #61 | user_id=user_id, |
| #62 | metadata={"category": "movie"}, |
| #63 | ) |
| #64 | |
| #65 | return recommendation |
| #66 | |
| #67 | |
| #68 | # Example Usage |
| #69 | if __name__ == "__main__": |
| #70 | user_id = "arshi" |
| #71 | recommend_movie_with_memory(user_id, "I'm looking for a movie to watch tonight. Any suggestions?") |
| #72 | # OUTPUT: You have watched Intersteller last weekend and you don't like horror movies, maybe you can watch "Purple Hearts" today. |
| #73 | recommend_movie_with_memory( |
| #74 | user_id, "Can we skip the tearjerkers? I really enjoyed Notting Hill and Crazy Rich Asians." |
| #75 | ) |
| #76 | # OUTPUT: Got it — no sad endings! You might enjoy "The Proposal" or "Love, Rosie". They’re both light-hearted romcoms with happy vibes. |
| #77 | recommend_movie_with_memory(user_id, "Any light-hearted movie I can watch after work today?") |
| #78 | # OUTPUT: Since you liked Crazy Rich Asians and The Proposal, how about "The Intern" or "Isn’t It Romantic"? Both are upbeat, funny, and perfect for relaxing. |
| #79 | recommend_movie_with_memory(user_id, "I’ve already watched The Intern. Something new maybe?") |
| #80 | # OUTPUT: No problem! Try "Your Place or Mine" - romcoms that match your taste and are tear-free! |
| #81 |