Add update method in client (#1615)

This commit is contained in:
Dev Khant
2024-07-31 11:43:30 +05:30
committed by GitHub
parent f2ddc573f6
commit 47afe52296
2 changed files with 56 additions and 1 deletions

View File

@@ -495,7 +495,48 @@ curl -X GET "https://api.mem0.ai/v1/memories/<memory-id-here>/history/" \
``` ```
</CodeGroup> </CodeGroup>
### 4.5 Delete Memory ### 4.5 Update Memory
Update a memory with new data.
<CodeGroup>
```python Python
message = "I recently tried chicken and I loved it. I'm thinking of trying more non-vegetarian dishes.."
client.update(memory_id, message)
```
```javascript JavaScript
const message = "I recently tried chicken and I loved it. I'm thinking of trying more non-vegetarian dishes..";
client.update("memory-id-here", message)
.then(result => console.log(result))
.catch(error => console.error(error));
```
```bash cURL
curl -X PUT "https://api.mem0.ai/v1/memories/memory-id-here" \
-H "Authorization: Token your-api-key" \
-H "Content-Type: application/json" \
-d '{
"message": "I recently tried chicken and I loved it. I'm thinking of trying more non-vegetarian dishes.."
}'
```
```json Output
{
"id":"c190ab1a-a2f1-4f6f-914a-495e9a16b76e",
"memory":"I recently tried chicken and I loved it. I'm thinking of trying more non-vegetarian dishes..",
"agent_id":"travel-assistant",
"hash":"af1161983e03667063d1abb60e6d5c06",
"metadata":"None",
"created_at":"2024-07-30T22:46:40.455758-07:00",
"updated_at":"2024-07-30T22:48:35.257828-07:00"
}
```
</CodeGroup>
### 4.6 Delete Memory
Delete specific memory: Delete specific memory:

View File

@@ -168,6 +168,20 @@ class MemoryClient:
capture_client_event("client.search", self, {"limit": kwargs.get("limit", 100)}) capture_client_event("client.search", self, {"limit": kwargs.get("limit", 100)})
return response.json() return response.json()
@api_error_handler
def update(self, memory_id: str, data: str) -> Dict[str, Any]:
"""
Update a memory by ID.
Args:
memory_id (str): Memory ID.
data (str): Data to update in the memory.
Returns:
Dict[str, Any]: The response from the server.
"""
capture_client_event("client.update", self)
response = self.client.put(f"/memories/{memory_id}/", json={"text": data})
return response.json()
@api_error_handler @api_error_handler
def delete(self, memory_id: str) -> Dict[str, Any]: def delete(self, memory_id: str) -> Dict[str, Any]:
"""Delete a specific memory by ID. """Delete a specific memory by ID.