add-reset-api-for-client (#1783)
This commit is contained in:
@@ -831,6 +831,25 @@ client.delete_users()
|
|||||||
|
|
||||||
</CodeGroup>
|
</CodeGroup>
|
||||||
|
|
||||||
|
### 4.8 Reset Client
|
||||||
|
|
||||||
|
<CodeGroup>
|
||||||
|
|
||||||
|
```python Python
|
||||||
|
client.reset()
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript JavaScript
|
||||||
|
client.reset()
|
||||||
|
.then(result => console.log(result))
|
||||||
|
.catch(error => console.error(error));
|
||||||
|
```
|
||||||
|
|
||||||
|
```json Output
|
||||||
|
{'message': 'Client reset successful. All users and memories deleted.'}
|
||||||
|
```
|
||||||
|
|
||||||
|
</CodeGroup>
|
||||||
|
|
||||||
|
|
||||||
Fun fact: You can also delete the memory using the `add()` method by passing a natural language command:
|
Fun fact: You can also delete the memory using the `add()` method by passing a natural language command:
|
||||||
|
|||||||
@@ -247,23 +247,36 @@ class MemoryClient:
|
|||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
@api_error_handler
|
@api_error_handler
|
||||||
def delete_users(self) -> Dict[str, Any]:
|
def delete_users(self) -> Dict[str, str]:
|
||||||
"""Delete all users, agents, or sessions."""
|
"""Delete all users, agents, or sessions."""
|
||||||
entities = self.users()
|
entities = self.users()
|
||||||
for entity in entities["results"]:
|
for entity in entities["results"]:
|
||||||
response = self.client.delete(f"/v1/entities/{entity['type']}/{entity['id']}/")
|
response = self.client.delete(
|
||||||
|
f"/v1/entities/{entity['type']}/{entity['id']}/"
|
||||||
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
capture_client_event("client.delete_users", self)
|
capture_client_event("client.delete_users", self)
|
||||||
return {"message": "All users, agents, and sessions deleted."}
|
return {"message": "All users, agents, and sessions deleted."}
|
||||||
|
|
||||||
def reset(self):
|
@api_error_handler
|
||||||
"""Reset the client. (Not implemented)
|
def reset(self) -> Dict[str, str]:
|
||||||
|
"""Reset the client by deleting all users and memories.
|
||||||
|
|
||||||
|
This method deletes all users, agents, sessions, and memories associated with the client.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Dict[str, str]: Message client reset successful.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
NotImplementedError: This method is not implemented yet.
|
APIError: If the API request fails.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError("Reset is not implemented yet")
|
# Delete all users, agents, and sessions
|
||||||
|
# This will also delete the memories
|
||||||
|
self.delete_users()
|
||||||
|
|
||||||
|
capture_client_event("client.reset", self)
|
||||||
|
return {"message": "Client reset successful. All users and memories deleted."}
|
||||||
|
|
||||||
def chat(self):
|
def chat(self):
|
||||||
"""Start a chat with the Mem0 AI. (Not implemented)
|
"""Start a chat with the Mem0 AI. (Not implemented)
|
||||||
|
|||||||
Reference in New Issue
Block a user