Add feeback method to client and doc changes (#2435)

This commit is contained in:
Dev Khant
2025-03-25 11:39:19 +05:30
committed by GitHub
parent 1ae2747ff8
commit b54845bcc9
5 changed files with 156 additions and 44 deletions

View File

@@ -0,0 +1,4 @@
---
title: 'Feedback'
openapi: post /v1/feedback/
---

View File

@@ -246,7 +246,8 @@
"api-reference/memory/batch-delete", "api-reference/memory/batch-delete",
"api-reference/memory/delete-memories", "api-reference/memory/delete-memories",
"api-reference/memory/create-memory-export", "api-reference/memory/create-memory-export",
"api-reference/memory/get-memory-export" "api-reference/memory/get-memory-export",
"api-reference/memory/feedback"
] ]
}, },
{ {

View File

@@ -17,9 +17,9 @@ You can give feedback on a memory by calling the `feedback` method on the Mem0 c
<CodeGroup> <CodeGroup>
```python Python ```python Python
from mem0 import Mem0 from mem0 import MemoryClient
client = Mem0(api_key="your_api_key") client = MemoryClient(api_key="your_api_key")
client.feedback(memory_id="your-memory-id", feedback="NEGATIVE", feedback_reason="I don't like this memory because it is not relevant.") client.feedback(memory_id="your-memory-id", feedback="NEGATIVE", feedback_reason="I don't like this memory because it is not relevant.")
``` ```

View File

@@ -2102,6 +2102,95 @@
"x-codegen-request-body-name": "data" "x-codegen-request-body-name": "data"
} }
}, },
"/v1/feedback/": {
"post": {
"tags": [
"feedback"
],
"description": "Submit feedback for a memory.",
"operationId": "submit_feedback",
"requestBody": {
"content": {
"application/json": {
"schema": {
"required": [
"memory_id"
],
"type": "object",
"properties": {
"memory_id": {
"type": "string",
"description": "ID of the memory to provide feedback for"
},
"feedback": {
"type": "string",
"enum": ["POSITIVE", "NEGATIVE", "VERY_NEGATIVE"],
"nullable": true,
"description": "Type of feedback"
},
"feedback_reason": {
"type": "string",
"nullable": true,
"description": "Reason for the feedback"
}
}
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid",
"description": "Feedback ID"
},
"feedback": {
"type": "string",
"enum": ["POSITIVE", "NEGATIVE", "VERY_NEGATIVE"],
"nullable": true,
"description": "Type of feedback"
},
"feedback_reason": {
"type": "string",
"nullable": true,
"description": "Reason for the feedback"
}
}
}
}
}
},
"400": {
"description": "Invalid request"
},
"401": {
"description": "Unauthorized"
}
},
"x-code-samples": [
{
"lang": "Python",
"source": "# To use the Python SDK, install the package:\n# pip install mem0ai\n\nfrom mem0 import MemoryClient\nclient = MemoryClient(api_key=\"your_api_key\")\n\n# Submit feedback for a memory\nfeedback = client.feedback(memory_id=\"memory_id\", feedback=\"POSITIVE\")\nprint(feedback)"
},
{
"lang": "JavaScript",
"source": "// To use the JavaScript SDK, install the package:\n// npm install mem0ai\n\nimport MemoryClient from 'mem0ai';\n\nconst client = new MemoryClient({ apiKey: 'your-api-key'});\n\nclient.feedback({\n memory_id: \"your-memory-id\", \n feedback: \"NEGATIVE\", \n feedback_reason: \"I don't like this memory because it is not relevant.\"\n})"
},
{
"lang": "cURL",
"source": "curl --request POST \\\n --url https://api.mem0.ai/v1/feedback/ \\\n --header 'Authorization: Token <api-key>' \\\n --header 'Content-Type: application/json' \\\n --data '{\"memory_id\": \"memory_id\", \"feedback\": \"POSITIVE\"}'"
}
]
}
},
"/api/v1/orgs/organizations/": { "/api/v1/orgs/organizations/": {
"get": { "get": {
"tags": [ "tags": [

View File

@@ -3,7 +3,6 @@ import os
import warnings import warnings
from functools import wraps from functools import wraps
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
from enum import Enum
import httpx import httpx
@@ -618,6 +617,25 @@ class MemoryClient:
capture_client_event("client.delete_webhook", self, {"webhook_id": webhook_id}) capture_client_event("client.delete_webhook", self, {"webhook_id": webhook_id})
return response.json() return response.json()
@api_error_handler
def feedback(self, memory_id: str, feedback: Optional[str] = None, feedback_reason: Optional[str] = None) -> Dict[str, str]:
VALID_FEEDBACK_VALUES = {"POSITIVE", "NEGATIVE", "VERY_NEGATIVE"}
feedback = feedback.upper() if feedback else None
if feedback is not None and feedback not in VALID_FEEDBACK_VALUES:
raise ValueError(f'feedback must be one of {", ".join(VALID_FEEDBACK_VALUES)} or None')
data = {
"memory_id": memory_id,
"feedback": feedback,
"feedback_reason": feedback_reason
}
response = self.client.post("/v1/feedback/", json=data)
response.raise_for_status()
capture_client_event("client.feedback", self, data)
return response.json()
def _prepare_payload( def _prepare_payload(
self, messages: Union[str, List[Dict[str, str]], None], kwargs: Dict[str, Any] self, messages: Union[str, List[Dict[str, str]], None], kwargs: Dict[str, Any]
) -> Dict[str, Any]: ) -> Dict[str, Any]: