User_id creation for client and formatting (#2264)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -23,7 +23,7 @@ class LlmConfig(BaseModel):
|
||||
"azure_openai_structured",
|
||||
"gemini",
|
||||
"deepseek",
|
||||
"xai"
|
||||
"xai",
|
||||
):
|
||||
return v
|
||||
else:
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user