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

@@ -3,7 +3,6 @@ import os
import warnings
from functools import wraps
from typing import Any, Dict, List, Optional, Union
from enum import Enum
import httpx
@@ -618,6 +617,25 @@ class MemoryClient:
capture_client_event("client.delete_webhook", self, {"webhook_id": webhook_id})
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(
self, messages: Union[str, List[Dict[str, str]], None], kwargs: Dict[str, Any]
) -> Dict[str, Any]:
@@ -1007,7 +1025,7 @@ class AsyncMemoryClient:
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,