Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

User_id creation for client and formatting (#2264)

Dev Khantecff6315e793
diff --git a/mem0/client/main.py b/mem0/client/main.py
index 1c5d19afc..bf0bbe606 100644
--- a/mem0/client/main.py
+++ b/mem0/client/main.py
@@ -6,12 +6,16 @@ from typing import Any, Dict, List, Optional, Union
import httpx
+from mem0.memory.setup import setup_config, get_user_id
from mem0.memory.telemetry import capture_client_event
logger = logging.getLogger(__name__)
warnings.filterwarnings("default", category=DeprecationWarning)
+# Setup user config
+setup_config()
+
class APIError(Exception):
"""Exception raised for errors in the API."""
@@ -74,13 +78,14 @@ class MemoryClient:
self.host = host or "https://api.mem0.ai"
self.org_id = org_id
self.project_id = project_id
+ self.user_id = get_user_id()
if not self.api_key:
raise ValueError("Mem0 API Key not provided. Please provide an API Key.")
self.client = httpx.Client(
base_url=self.host,
- headers={"Authorization": f"Token {self.api_key}"},
+ headers={"Authorization": f"Token {self.api_key}", "Mem0-User-ID": self.user_id},
timeout=300,
)
self.user_email = self._validate_api_key()
diff --git a/mem0/llms/configs.py b/mem0/llms/configs.py
index 4c095e966..40287ce12 100644
--- a/mem0/llms/configs.py
+++ b/mem0/llms/configs.py
@@ -23,7 +23,7 @@ class LlmConfig(BaseModel):
"azure_openai_structured",
"gemini",
"deepseek",
- "xai"
+ "xai",
):
return v
else:
diff --git a/mem0/llms/xai.py b/mem0/llms/xai.py
index 60210e116..5309eb57d 100644
--- a/mem0/llms/xai.py
+++ b/mem0/llms/xai.py
@@ -18,11 +18,7 @@ class XAILLM(LLMBase):
base_url = self.config.xai_base_url or os.getenv("XAI_API_BASE") or "https://api.x.ai/v1"
self.client = OpenAI(api_key=api_key, base_url=base_url)
- def generate_response(
- self,
- messages: List[Dict[str, str]],
- response_format=None
- ):
+ def generate_response(self, messages: List[Dict[str, str]], response_format=None):
"""
Generate a response based on the given messages using XAI.
diff --git a/mem0/proxy/main.py b/mem0/proxy/main.py
index 821766e12..52776971b 100644
--- a/mem0/proxy/main.py
+++ b/mem0/proxy/main.py
@@ -143,7 +143,7 @@ class Completions:
api_key=api_key,
model_list=model_list,
)
- capture_client_event("mem0.chat.create", self)
+ capture_client_event("mem0.chat.create", self.mem0_client)
return response
def _prepare_messages(self, messages: List[dict]) -> List[dict]: