Skip to content

Commit

Permalink
update event
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-Khant committed Oct 29, 2024
1 parent ebeb044 commit 387fdef
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions mem0/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def add(self, messages: Union[str, List[Dict[str, str]]], **kwargs) -> Dict[str,
payload = self._prepare_payload(messages, kwargs)
response = self.client.post("/v1/memories/", json=payload)
response.raise_for_status()
if "metadata" in kwargs:
del kwargs["metadata"]
capture_client_event("client.add", self, {"keys": list(kwargs.keys())})
return response.json()

Expand All @@ -135,7 +137,7 @@ def get(self, memory_id: str) -> Dict[str, Any]:
"""
response = self.client.get(f"/v1/memories/{memory_id}/")
response.raise_for_status()
capture_client_event("client.get", self)
capture_client_event("client.get", self, {"memory_id": memory_id})
return response.json()

@api_error_handler
Expand All @@ -159,6 +161,8 @@ def get_all(self, version: str = "v1", **kwargs) -> List[Dict[str, Any]]:
elif version == "v2":
response = self.client.post(f"/{version}/memories/", json=params)
response.raise_for_status()
if "metadata" in kwargs:
del kwargs["metadata"]
capture_client_event(
"client.get_all",
self,
Expand Down Expand Up @@ -186,6 +190,8 @@ def search(self, query: str, version: str = "v1", **kwargs) -> List[Dict[str, An
payload.update({k: v for k, v in kwargs.items() if v is not None})
response = self.client.post(f"/{version}/memories/search/", json=payload)
response.raise_for_status()
if "metadata" in kwargs:
del kwargs["metadata"]
capture_client_event("client.search", self, {"api_version": version, "keys": list(kwargs.keys())})
return response.json()

Expand All @@ -199,7 +205,7 @@ def update(self, memory_id: str, data: str) -> Dict[str, Any]:
Returns:
Dict[str, Any]: The response from the server.
"""
capture_client_event("client.update", self)
capture_client_event("client.update", self, {"memory_id": memory_id})
response = self.client.put(f"/v1/memories/{memory_id}/", json={"text": data})
response.raise_for_status()
return response.json()
Expand All @@ -219,7 +225,7 @@ def delete(self, memory_id: str) -> Dict[str, Any]:
"""
response = self.client.delete(f"/v1/memories/{memory_id}/")
response.raise_for_status()
capture_client_event("client.delete", self)
capture_client_event("client.delete", self, {"memory_id": memory_id})
return response.json()

@api_error_handler
Expand Down Expand Up @@ -257,7 +263,7 @@ def history(self, memory_id: str) -> List[Dict[str, Any]]:
"""
response = self.client.get(f"/v1/memories/{memory_id}/history/")
response.raise_for_status()
capture_client_event("client.history", self)
capture_client_event("client.history", self, {"memory_id": memory_id})
return response.json()

@api_error_handler
Expand Down Expand Up @@ -390,14 +396,16 @@ async def add(self, messages: Union[str, List[Dict[str, str]]], **kwargs) -> Dic
payload = self.sync_client._prepare_payload(messages, kwargs)
response = await self.async_client.post("/v1/memories/", json=payload)
response.raise_for_status()
if "metadata" in kwargs:
del kwargs["metadata"]
capture_client_event("async_client.add", self.sync_client, {"keys": list(kwargs.keys())})
return response.json()

@api_error_handler
async def get(self, memory_id: str) -> Dict[str, Any]:
response = await self.async_client.get(f"/v1/memories/{memory_id}/")
response.raise_for_status()
capture_client_event("async_client.get", self.sync_client)
capture_client_event("async_client.get", self.sync_client, {"memory_id": memory_id})
return response.json()

@api_error_handler
Expand All @@ -408,6 +416,8 @@ async def get_all(self, version: str = "v1", **kwargs) -> List[Dict[str, Any]]:
elif version == "v2":
response = await self.async_client.post(f"/{version}/memories/", json=params)
response.raise_for_status()
if "metadata" in kwargs:
del kwargs["metadata"]
capture_client_event(
"async_client.get_all", self.sync_client, {"api_version": version, "keys": list(kwargs.keys())}
)
Expand All @@ -419,6 +429,8 @@ async def search(self, query: str, version: str = "v1", **kwargs) -> List[Dict[s
payload.update(self.sync_client._prepare_params(kwargs))
response = await self.async_client.post(f"/{version}/memories/search/", json=payload)
response.raise_for_status()
if "metadata" in kwargs:
del kwargs["metadata"]
capture_client_event(
"async_client.search", self.sync_client, {"api_version": version, "keys": list(kwargs.keys())}
)
Expand All @@ -428,14 +440,14 @@ async def search(self, query: str, version: str = "v1", **kwargs) -> List[Dict[s
async def update(self, memory_id: str, data: str) -> Dict[str, Any]:
response = await self.async_client.put(f"/v1/memories/{memory_id}/", json={"text": data})
response.raise_for_status()
capture_client_event("async_client.update", self.sync_client)
capture_client_event("async_client.update", self.sync_client, {"memory_id": memory_id})
return response.json()

@api_error_handler
async def delete(self, memory_id: str) -> Dict[str, Any]:
response = await self.async_client.delete(f"/v1/memories/{memory_id}/")
response.raise_for_status()
capture_client_event("async_client.delete", self.sync_client)
capture_client_event("async_client.delete", self.sync_client, {"memory_id": memory_id})
return response.json()

@api_error_handler
Expand All @@ -450,7 +462,7 @@ async def delete_all(self, **kwargs) -> Dict[str, str]:
async def history(self, memory_id: str) -> List[Dict[str, Any]]:
response = await self.async_client.get(f"/v1/memories/{memory_id}/history/")
response.raise_for_status()
capture_client_event("async_client.history", self.sync_client)
capture_client_event("async_client.history", self.sync_client, {"memory_id": memory_id})
return response.json()

@api_error_handler
Expand Down

0 comments on commit 387fdef

Please sign in to comment.