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 | "cells": [ |
| #3 | { |
| #4 | "cell_type": "code", |
| #5 | "execution_count": 1, |
| #6 | "metadata": {}, |
| #7 | "outputs": [], |
| #8 | "source": [ |
| #9 | "import os\n", |
| #10 | "from typing import List, Dict\n", |
| #11 | "from mem0 import Memory\n", |
| #12 | "from datetime import datetime\n", |
| #13 | "import anthropic\n", |
| #14 | "\n", |
| #15 | "# Set up environment variables\n", |
| #16 | "os.environ[\"OPENAI_API_KEY\"] = \"your_openai_api_key\" # needed for embedding model\n", |
| #17 | "os.environ[\"ANTHROPIC_API_KEY\"] = \"your_anthropic_api_key\"" |
| #18 | ] |
| #19 | }, |
| #20 | { |
| #21 | "cell_type": "code", |
| #22 | "execution_count": 2, |
| #23 | "metadata": {}, |
| #24 | "outputs": [], |
| #25 | "source": [ |
| #26 | "class SupportChatbot:\n", |
| #27 | " def __init__(self):\n", |
| #28 | " # Initialize Mem0 with Anthropic's Claude\n", |
| #29 | " self.config = {\n", |
| #30 | " \"llm\": {\n", |
| #31 | " \"provider\": \"anthropic\",\n", |
| #32 | " \"config\": {\n", |
| #33 | " \"model\": \"claude-3-5-sonnet-latest\",\n", |
| #34 | " \"temperature\": 0.1,\n", |
| #35 | " \"max_tokens\": 2000,\n", |
| #36 | " },\n", |
| #37 | " }\n", |
| #38 | " }\n", |
| #39 | " self.client = anthropic.Client(api_key=os.environ[\"ANTHROPIC_API_KEY\"])\n", |
| #40 | " self.memory = Memory.from_config(self.config)\n", |
| #41 | "\n", |
| #42 | " # Define support context\n", |
| #43 | " self.system_context = \"\"\"\n", |
| #44 | " You are a helpful customer support agent. Use the following guidelines:\n", |
| #45 | " - Be polite and professional\n", |
| #46 | " - Show empathy for customer issues\n", |
| #47 | " - Reference past interactions when relevant\n", |
| #48 | " - Maintain consistent information across conversations\n", |
| #49 | " - If you're unsure about something, ask for clarification\n", |
| #50 | " - Keep track of open issues and follow-ups\n", |
| #51 | " \"\"\"\n", |
| #52 | "\n", |
| #53 | " def store_customer_interaction(self, user_id: str, message: str, response: str, metadata: Dict = None):\n", |
| #54 | " \"\"\"Store customer interaction in memory.\"\"\"\n", |
| #55 | " if metadata is None:\n", |
| #56 | " metadata = {}\n", |
| #57 | "\n", |
| #58 | " # Add timestamp to metadata\n", |
| #59 | " metadata[\"timestamp\"] = datetime.now().isoformat()\n", |
| #60 | "\n", |
| #61 | " # Format conversation for storage\n", |
| #62 | " conversation = [{\"role\": \"user\", \"content\": message}, {\"role\": \"assistant\", \"content\": response}]\n", |
| #63 | "\n", |
| #64 | " # Store in Mem0\n", |
| #65 | " self.memory.add(conversation, user_id=user_id, metadata=metadata)\n", |
| #66 | "\n", |
| #67 | " def get_relevant_history(self, user_id: str, query: str) -> List[Dict]:\n", |
| #68 | " \"\"\"Retrieve relevant past interactions.\"\"\"\n", |
| #69 | " return self.memory.search(\n", |
| #70 | " query=query,\n", |
| #71 | " user_id=user_id,\n", |
| #72 | " limit=5, # Adjust based on needs\n", |
| #73 | " )\n", |
| #74 | "\n", |
| #75 | " def handle_customer_query(self, user_id: str, query: str) -> str:\n", |
| #76 | " \"\"\"Process customer query with context from past interactions.\"\"\"\n", |
| #77 | "\n", |
| #78 | " # Get relevant past interactions\n", |
| #79 | " relevant_history = self.get_relevant_history(user_id, query)\n", |
| #80 | "\n", |
| #81 | " # Build context from relevant history\n", |
| #82 | " context = \"Previous relevant interactions:\\n\"\n", |
| #83 | " for memory in relevant_history:\n", |
| #84 | " context += f\"Customer: {memory['memory']}\\n\"\n", |
| #85 | " context += f\"Support: {memory['memory']}\\n\"\n", |
| #86 | " context += \"---\\n\"\n", |
| #87 | "\n", |
| #88 | " # Prepare prompt with context and current query\n", |
| #89 | " prompt = f\"\"\"\n", |
| #90 | " {self.system_context}\n", |
| #91 | "\n", |
| #92 | " {context}\n", |
| #93 | "\n", |
| #94 | " Current customer query: {query}\n", |
| #95 | "\n", |
| #96 | " Provide a helpful response that takes into account any relevant past interactions.\n", |
| #97 | " \"\"\"\n", |
| #98 | "\n", |
| #99 | " # Generate response using Claude\n", |
| #100 | " response = self.client.messages.create(\n", |
| #101 | " model=\"claude-3-5-sonnet-latest\",\n", |
| #102 | " messages=[{\"role\": \"user\", \"content\": prompt}],\n", |
| #103 | " max_tokens=2000,\n", |
| #104 | " temperature=0.1,\n", |
| #105 | " )\n", |
| #106 | "\n", |
| #107 | " # Store interaction\n", |
| #108 | " self.store_customer_interaction(\n", |
| #109 | " user_id=user_id, message=query, response=response, metadata={\"type\": \"support_query\"}\n", |
| #110 | " )\n", |
| #111 | "\n", |
| #112 | " return response.content[0].text" |
| #113 | ] |
| #114 | }, |
| #115 | { |
| #116 | "cell_type": "code", |
| #117 | "execution_count": 3, |
| #118 | "metadata": {}, |
| #119 | "outputs": [ |
| #120 | { |
| #121 | "name": "stdout", |
| #122 | "output_type": "stream", |
| #123 | "text": [ |
| #124 | "Welcome to Customer Support! Type 'exit' to end the conversation.\n", |
| #125 | "Customer: Hi, I'm having trouble connecting my new smartwatch to the mobile app. It keeps showing a connection error.\n" |
| #126 | ] |
| #127 | }, |
| #128 | { |
| #129 | "name": "stderr", |
| #130 | "output_type": "stream", |
| #131 | "text": [ |
| #132 | "/var/folders/5x/9kmqjfm947g5yh44m7fjk75r0000gn/T/ipykernel_99777/1076713094.py:55: DeprecationWarning: The current get_all API output format is deprecated. To use the latest format, set `api_version='v1.1'`. The current format will be removed in mem0ai 1.1.0 and later versions.\n", |
| #133 | " return self.memory.search(\n", |
| #134 | "/var/folders/5x/9kmqjfm947g5yh44m7fjk75r0000gn/T/ipykernel_99777/1076713094.py:47: DeprecationWarning: The current add API output format is deprecated. To use the latest format, set `api_version='v1.1'`. The current format will be removed in mem0ai 1.1.0 and later versions.\n", |
| #135 | " self.memory.add(\n" |
| #136 | ] |
| #137 | }, |
| #138 | { |
| #139 | "name": "stdout", |
| #140 | "output_type": "stream", |
| #141 | "text": [ |
| #142 | "Support: Hello! Thank you for reaching out about the connection issue with your smartwatch. I understand how frustrating it can be when a new device won't connect properly. I'll be happy to help you resolve this.\n", |
| #143 | "\n", |
| #144 | "To better assist you, could you please provide me with:\n", |
| #145 | "1. The model of your smartwatch\n", |
| #146 | "2. The type of phone you're using (iOS or Android)\n", |
| #147 | "3. Whether you've already installed the companion app on your phone\n", |
| #148 | "4. If you've tried pairing the devices before\n", |
| #149 | "\n", |
| #150 | "These details will help me provide you with the most accurate troubleshooting steps. In the meantime, here are some general tips that might help:\n", |
| #151 | "- Make sure Bluetooth is enabled on your phone\n", |
| #152 | "- Keep your smartwatch and phone within close range (within 3 feet) during pairing\n", |
| #153 | "- Ensure both devices have sufficient battery power\n", |
| #154 | "- Check if your phone's operating system meets the minimum requirements for the smartwatch\n", |
| #155 | "\n", |
| #156 | "Please provide the requested information, and I'll guide you through the specific steps to resolve the connection error.\n", |
| #157 | "\n", |
| #158 | "Is there anything else you'd like to share about the issue? \n", |
| #159 | "\n", |
| #160 | "\n", |
| #161 | "Customer: The connection issue is still happening even after trying the steps you suggested.\n", |
| #162 | "Support: I apologize that you're still experiencing connection issues with your smartwatch. I understand how frustrating it must be to have this problem persist even after trying the initial troubleshooting steps. Let's try some additional solutions to resolve this.\n", |
| #163 | "\n", |
| #164 | "Before we proceed, could you please confirm:\n", |
| #165 | "1. Which specific steps you've already attempted?\n", |
| #166 | "2. Are you seeing any particular error message?\n", |
| #167 | "3. What model of smartwatch and phone are you using?\n", |
| #168 | "\n", |
| #169 | "This information will help me provide more targeted solutions and avoid suggesting steps you've already tried. In the meantime, here are a few advanced troubleshooting steps we can consider:\n", |
| #170 | "\n", |
| #171 | "1. Completely resetting the Bluetooth connection\n", |
| #172 | "2. Checking for any software updates for both the watch and phone\n", |
| #173 | "3. Testing the connection with a different mobile device to isolate the issue\n", |
| #174 | "\n", |
| #175 | "Would you be able to provide those details so I can better assist you? I'll make sure to document this ongoing issue to help track its resolution. \n", |
| #176 | "\n", |
| #177 | "\n", |
| #178 | "Customer: exit\n", |
| #179 | "Thank you for using our support service. Goodbye!\n" |
| #180 | ] |
| #181 | } |
| #182 | ], |
| #183 | "source": [ |
| #184 | "chatbot = SupportChatbot()\n", |
| #185 | "user_id = \"customer_bot\"\n", |
| #186 | "print(\"Welcome to Customer Support! Type 'exit' to end the conversation.\")\n", |
| #187 | "\n", |
| #188 | "while True:\n", |
| #189 | " # Get user input\n", |
| #190 | " query = input()\n", |
| #191 | " print(\"Customer:\", query)\n", |
| #192 | "\n", |
| #193 | " # Check if user wants to exit\n", |
| #194 | " if query.lower() == \"exit\":\n", |
| #195 | " print(\"Thank you for using our support service. Goodbye!\")\n", |
| #196 | " break\n", |
| #197 | "\n", |
| #198 | " # Handle the query and print the response\n", |
| #199 | " response = chatbot.handle_customer_query(user_id, query)\n", |
| #200 | " print(\"Support:\", response, \"\\n\\n\")" |
| #201 | ] |
| #202 | } |
| #203 | ], |
| #204 | "metadata": { |
| #205 | "kernelspec": { |
| #206 | "display_name": ".venv", |
| #207 | "language": "python", |
| #208 | "name": "python3" |
| #209 | }, |
| #210 | "language_info": { |
| #211 | "codemirror_mode": { |
| #212 | "name": "ipython", |
| #213 | "version": 3 |
| #214 | }, |
| #215 | "file_extension": ".py", |
| #216 | "mimetype": "text/x-python", |
| #217 | "name": "python", |
| #218 | "nbconvert_exporter": "python", |
| #219 | "pygments_lexer": "ipython3", |
| #220 | "version": "3.12.4" |
| #221 | } |
| #222 | }, |
| #223 | "nbformat": 4, |
| #224 | "nbformat_minor": 2 |
| #225 | } |
| #226 |