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: Smart Travel Assistant |
| #3 | description: "Plan itineraries that remember traveler preferences across trips." |
| #4 | --- |
| #5 | |
| #6 | |
| #7 | Create a personalized AI Travel Assistant using Mem0. This guide provides step-by-step instructions and the complete code to get you started. |
| #8 | |
| #9 | ## Overview |
| #10 | |
| #11 | The Personalized AI Travel Assistant uses Mem0 to store and retrieve information across interactions, enabling a tailored travel planning experience. It integrates with OpenAI's GPT-4 model to provide detailed and context-aware responses to user queries. |
| #12 | |
| #13 | ## Setup |
| #14 | |
| #15 | Install the required dependencies using pip: |
| #16 | |
| #17 | ```bash |
| #18 | pip install openai mem0ai |
| #19 | ``` |
| #20 | |
| #21 | ## Full Code Example |
| #22 | |
| #23 | Here's the complete code to create and interact with a Personalized AI Travel Assistant using Mem0: |
| #24 | |
| #25 | <CodeGroup> |
| #26 | |
| #27 | ```python After v1.1 |
| #28 | import os |
| #29 | from openai import OpenAI |
| #30 | from mem0 import Memory |
| #31 | |
| #32 | # Set the OpenAI API key |
| #33 | os.environ['OPENAI_API_KEY'] = "sk-xxx" |
| #34 | |
| #35 | config = { |
| #36 | "llm": { |
| #37 | "provider": "openai", |
| #38 | "config": { |
| #39 | "model": "gpt-4.1-nano-2025-04-14", |
| #40 | "temperature": 0.1, |
| #41 | "max_tokens": 2000, |
| #42 | } |
| #43 | }, |
| #44 | "embedder": { |
| #45 | "provider": "openai", |
| #46 | "config": { |
| #47 | "model": "text-embedding-3-large" |
| #48 | } |
| #49 | }, |
| #50 | "vector_store": { |
| #51 | "provider": "qdrant", |
| #52 | "config": { |
| #53 | "collection_name": "test", |
| #54 | "embedding_model_dims": 3072, |
| #55 | } |
| #56 | }, |
| #57 | "version": "v1.1", |
| #58 | } |
| #59 | |
| #60 | class PersonalTravelAssistant: |
| #61 | def __init__(self): |
| #62 | self.client = OpenAI() |
| #63 | self.memory = Memory.from_config(config) |
| #64 | self.messages = [{"role": "system", "content": "You are a personal AI Assistant."}] |
| #65 | |
| #66 | def ask_question(self, question, user_id): |
| #67 | # Fetch previous related memories |
| #68 | previous_memories = self.search_memories(question, user_id=user_id) |
| #69 | |
| #70 | # Build the prompt |
| #71 | system_message = "You are a personal AI Assistant." |
| #72 | |
| #73 | if previous_memories: |
| #74 | prompt = f"{system_message}\n\nUser input: {question}\nPrevious memories: {', '.join(previous_memories)}" |
| #75 | else: |
| #76 | prompt = f"{system_message}\n\nUser input: {question}" |
| #77 | |
| #78 | # Generate response using Responses API |
| #79 | response = self.client.responses.create( |
| #80 | model="gpt-4.1-nano-2025-04-14", |
| #81 | input=prompt |
| #82 | ) |
| #83 | |
| #84 | # Extract answer from the response |
| #85 | answer = response.output[0].content[0].text |
| #86 | |
| #87 | # Store the question in memory |
| #88 | self.memory.add(question, user_id=user_id) |
| #89 | return answer |
| #90 | |
| #91 | def get_memories(self, user_id): |
| #92 | memories = self.memory.get_all(user_id=user_id) |
| #93 | return [m['memory'] for m in memories['results']] |
| #94 | |
| #95 | def search_memories(self, query, user_id): |
| #96 | memories = self.memory.search(query, user_id=user_id) |
| #97 | return [m['memory'] for m in memories['results']] |
| #98 | |
| #99 | # Usage example |
| #100 | user_id = "traveler_123" |
| #101 | ai_assistant = PersonalTravelAssistant() |
| #102 | |
| #103 | def main(): |
| #104 | while True: |
| #105 | question = input("Question: ") |
| #106 | if question.lower() in ['q', 'exit']: |
| #107 | print("Exiting...") |
| #108 | break |
| #109 | |
| #110 | answer = ai_assistant.ask_question(question, user_id=user_id) |
| #111 | print(f"Answer: {answer}") |
| #112 | memories = ai_assistant.get_memories(user_id=user_id) |
| #113 | print("Memories:") |
| #114 | for memory in memories: |
| #115 | print(f"- {memory}") |
| #116 | print("-----") |
| #117 | |
| #118 | if __name__ == "__main__": |
| #119 | main() |
| #120 | ``` |
| #121 | |
| #122 | ```python Before v1.1 |
| #123 | import os |
| #124 | from openai import OpenAI |
| #125 | from mem0 import Memory |
| #126 | |
| #127 | # Set the OpenAI API key |
| #128 | os.environ['OPENAI_API_KEY'] = 'sk-xxx' |
| #129 | |
| #130 | class PersonalTravelAssistant: |
| #131 | def __init__(self): |
| #132 | self.client = OpenAI() |
| #133 | self.memory = Memory() |
| #134 | self.messages = [{"role": "system", "content": "You are a personal AI Assistant."}] |
| #135 | |
| #136 | def ask_question(self, question, user_id): |
| #137 | # Fetch previous related memories |
| #138 | previous_memories = self.search_memories(question, user_id=user_id) |
| #139 | prompt = question |
| #140 | if previous_memories: |
| #141 | prompt = f"User input: {question}\n Previous memories: {previous_memories}" |
| #142 | self.messages.append({"role": "user", "content": prompt}) |
| #143 | |
| #144 | # Generate response using gpt-4.1-nano |
| #145 | response = self.client.chat.completions.create( |
| #146 | model="gpt-4.1-nano-2025-04-14"2025-04-14", |
| #147 | messages=self.messages |
| #148 | ) |
| #149 | answer = response.choices[0].message.content |
| #150 | self.messages.append({"role": "assistant", "content": answer}) |
| #151 | |
| #152 | # Store the question in memory |
| #153 | self.memory.add(question, user_id=user_id) |
| #154 | return answer |
| #155 | |
| #156 | def get_memories(self, user_id): |
| #157 | memories = self.memory.get_all(user_id=user_id) |
| #158 | return [m['memory'] for m in memories.get('results', [])] |
| #159 | |
| #160 | def search_memories(self, query, user_id): |
| #161 | memories = self.memory.search(query, user_id=user_id) |
| #162 | return [m['memory'] for m in memories.get('results', [])] |
| #163 | |
| #164 | # Usage example |
| #165 | user_id = "traveler_123" |
| #166 | ai_assistant = PersonalTravelAssistant() |
| #167 | |
| #168 | def main(): |
| #169 | while True: |
| #170 | question = input("Question: ") |
| #171 | if question.lower() in ['q', 'exit']: |
| #172 | print("Exiting...") |
| #173 | break |
| #174 | |
| #175 | answer = ai_assistant.ask_question(question, user_id=user_id) |
| #176 | print(f"Answer: {answer}") |
| #177 | memories = ai_assistant.get_memories(user_id=user_id) |
| #178 | print("Memories:") |
| #179 | for memory in memories: |
| #180 | print(f"- {memory}") |
| #181 | print("-----") |
| #182 | |
| #183 | if __name__ == "__main__": |
| #184 | main() |
| #185 | ``` |
| #186 | </CodeGroup> |
| #187 | |
| #188 | |
| #189 | ## Key Components |
| #190 | |
| #191 | - **Initialization**: The `PersonalTravelAssistant` class is initialized with the OpenAI client and Mem0 memory setup. |
| #192 | - **Asking Questions**: The `ask_question` method sends a question to the AI, incorporates previous memories, and stores new information. |
| #193 | - **Memory Management**: The `get_memories` and search_memories methods handle retrieval and searching of stored memories. |
| #194 | |
| #195 | ## Usage |
| #196 | |
| #197 | 1. Set your OpenAI API key in the environment variable. |
| #198 | 2. Instantiate the `PersonalTravelAssistant`. |
| #199 | 3. Use the `main()` function to interact with the assistant in a loop. |
| #200 | |
| #201 | ## Conclusion |
| #202 | |
| #203 | This Personalized AI Travel Assistant leverages Mem0's memory capabilities to provide context-aware responses. As you interact with it, the assistant learns and improves, offering increasingly personalized travel advice and information. |
| #204 | |
| #205 | --- |
| #206 | |
| #207 | <CardGroup cols={2}> |
| #208 | <Card title="Tag and Organize Memories" icon="tag" href="/cookbooks/essentials/tagging-and-organizing-memories"> |
| #209 | Use categories to organize travel preferences, destinations, and user context. |
| #210 | </Card> |
| #211 | <Card title="AI Tutor with Mem0" icon="graduation-cap" href="/cookbooks/companions/ai-tutor"> |
| #212 | Build an educational companion that remembers learning progress and preferences. |
| #213 | </Card> |
| #214 | </CardGroup> |
| #215 |