Add feeback method to client and doc changes (#2435)
This commit is contained in:
4
docs/api-reference/memory/feedback.mdx
Normal file
4
docs/api-reference/memory/feedback.mdx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
title: 'Feedback'
|
||||||
|
openapi: post /v1/feedback/
|
||||||
|
---
|
||||||
@@ -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"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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.")
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -509,33 +509,33 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"post": {
|
"post": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"exports"
|
"exports"
|
||||||
],
|
],
|
||||||
"summary": "Create an export job with schema",
|
"summary": "Create an export job with schema",
|
||||||
"description": "Create a structured export of memories based on a provided schema.",
|
"description": "Create a structured export of memories based on a provided schema.",
|
||||||
"operationId": "exports_create",
|
"operationId": "exports_create",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["schema"],
|
"required": ["schema"],
|
||||||
"properties": {
|
"properties": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Schema definition for the export"
|
"description": "Schema definition for the export"
|
||||||
},
|
},
|
||||||
"user_id": {
|
"user_id": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Filter exports by user ID"
|
"description": "Filter exports by user ID"
|
||||||
},
|
},
|
||||||
"run_id": {
|
"run_id": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Filter exports by run ID"
|
"description": "Filter exports by run ID"
|
||||||
},
|
},
|
||||||
"session_id": {
|
"session_id": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Filter exports by session ID"
|
"description": "Filter exports by session ID"
|
||||||
},
|
},
|
||||||
"app_id": {
|
"app_id": {
|
||||||
@@ -549,28 +549,28 @@
|
|||||||
"project_id": {
|
"project_id": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Filter exports by project ID"
|
"description": "Filter exports by project ID"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"201": {
|
||||||
"description": "Export created successfully",
|
"description": "Export created successfully",
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "Memory export request received. The export will be ready in a few seconds."
|
"example": "Memory export request received. The export will be ready in a few seconds."
|
||||||
},
|
},
|
||||||
"id": {
|
"id": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "uuid",
|
"format": "uuid",
|
||||||
"example": "550e8400-e29b-41d4-a716-446655440000"
|
"example": "550e8400-e29b-41d4-a716-446655440000"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -587,15 +587,15 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "Schema is required and must be a valid object"
|
"example": "Schema is required and must be a valid object"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"x-code-samples": [
|
"x-code-samples": [
|
||||||
{
|
{
|
||||||
"lang": "Python",
|
"lang": "Python",
|
||||||
@@ -622,7 +622,7 @@
|
|||||||
"source": "import com.mashape.unirest.http.HttpResponse;\nimport com.mashape.unirest.http.JsonNode;\nimport com.mashape.unirest.http.Unirest;\nimport org.json.JSONObject;\n\nJSONObject data = new JSONObject()\n .put(\"schema\", new JSONObject()) // Your schema here\n .put(\"user_id\", \"your_user_id\");\n\nHttpResponse<JsonNode> response = Unirest.post(\"https://api.mem0.ai/v1/exports/\")\n .header(\"Authorization\", \"Token <api-key>\")\n .header(\"Content-Type\", \"application/json\")\n .body(data.toString())\n .asJson();"
|
"source": "import com.mashape.unirest.http.HttpResponse;\nimport com.mashape.unirest.http.JsonNode;\nimport com.mashape.unirest.http.Unirest;\nimport org.json.JSONObject;\n\nJSONObject data = new JSONObject()\n .put(\"schema\", new JSONObject()) // Your schema here\n .put(\"user_id\", \"your_user_id\");\n\nHttpResponse<JsonNode> response = Unirest.post(\"https://api.mem0.ai/v1/exports/\")\n .header(\"Authorization\", \"Token <api-key>\")\n .header(\"Content-Type\", \"application/json\")\n .body(data.toString())\n .asJson();"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/v1/memories/": {
|
"/v1/memories/": {
|
||||||
"get": {
|
"get": {
|
||||||
@@ -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": [
|
||||||
@@ -3140,7 +3229,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "Unauthorized to create projects in this organization."
|
"example": "Unauthorized to create projects in this organization."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3506,7 +3595,7 @@
|
|||||||
"description": "Unauthorized to modify this project",
|
"description": "Unauthorized to modify this project",
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"message": {
|
"message": {
|
||||||
|
|||||||
@@ -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]:
|
||||||
@@ -1007,7 +1025,7 @@ class AsyncMemoryClient:
|
|||||||
feedback = feedback.upper() if feedback else None
|
feedback = feedback.upper() if feedback else None
|
||||||
if feedback is not None and feedback not in VALID_FEEDBACK_VALUES:
|
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')
|
raise ValueError(f'feedback must be one of {", ".join(VALID_FEEDBACK_VALUES)} or None')
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"memory_id": memory_id,
|
"memory_id": memory_id,
|
||||||
"feedback": feedback,
|
"feedback": feedback,
|
||||||
|
|||||||
Reference in New Issue
Block a user