Fix dependency and tests and updated docstring (#3337)
This commit is contained in:
+13
-3
@@ -265,12 +265,17 @@ class MemoryClient:
|
|||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Update a memory by ID.
|
Update a memory by ID.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
memory_id (str): Memory ID.
|
memory_id (str): Memory ID.
|
||||||
text (str, optional): Data to update in the memory.
|
text (str, optional): New content to update the memory with.
|
||||||
metadata (dict, optional): Metadata to update in the memory.
|
metadata (dict, optional): Metadata to update in the memory.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict[str, Any]: The response from the server.
|
Dict[str, Any]: The response from the server.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>>> client.update(memory_id="mem_123", text="Likes to play tennis on weekends")
|
||||||
"""
|
"""
|
||||||
if text is None and metadata is None:
|
if text is None and metadata is None:
|
||||||
raise ValueError("Either text or metadata must be provided for update.")
|
raise ValueError("Either text or metadata must be provided for update.")
|
||||||
@@ -1054,13 +1059,18 @@ class AsyncMemoryClient:
|
|||||||
self, memory_id: str, text: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None
|
self, memory_id: str, text: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Update a memory by ID.
|
Update a memory by ID asynchronously.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
memory_id (str): Memory ID.
|
memory_id (str): Memory ID.
|
||||||
text (str, optional): Data to update in the memory.
|
text (str, optional): New content to update the memory with.
|
||||||
metadata (dict, optional): Metadata to update in the memory.
|
metadata (dict, optional): Metadata to update in the memory.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict[str, Any]: The response from the server.
|
Dict[str, Any]: The response from the server.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>>> await client.update(memory_id="mem_123", text="Likes to play tennis on weekends")
|
||||||
"""
|
"""
|
||||||
if text is None and metadata is None:
|
if text is None and metadata is None:
|
||||||
raise ValueError("Either text or metadata must be provided for update.")
|
raise ValueError("Either text or metadata must be provided for update.")
|
||||||
|
|||||||
+2
-2
@@ -32,10 +32,10 @@ class MemoryBase(ABC):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
memory_id (str): ID of the memory to update.
|
memory_id (str): ID of the memory to update.
|
||||||
data (dict): Data to update the memory with.
|
data (str): New content to update the memory with.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Updated memory.
|
dict: Success message indicating the memory was updated.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
+21
-4
@@ -730,10 +730,14 @@ class Memory(MemoryBase):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
memory_id (str): ID of the memory to update.
|
memory_id (str): ID of the memory to update.
|
||||||
data (dict): Data to update the memory with.
|
data (str): New content to update the memory with.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Updated memory.
|
dict: Success message indicating the memory was updated.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>>> m.update(memory_id="mem_123", data="Likes to play tennis on weekends")
|
||||||
|
{'message': 'Memory updated successfully!'}
|
||||||
"""
|
"""
|
||||||
capture_event("mem0.update", self, {"memory_id": memory_id, "sync_type": "sync"})
|
capture_event("mem0.update", self, {"memory_id": memory_id, "sync_type": "sync"})
|
||||||
|
|
||||||
@@ -994,6 +998,15 @@ class AsyncMemory(MemoryBase):
|
|||||||
else:
|
else:
|
||||||
self.graph = None
|
self.graph = None
|
||||||
|
|
||||||
|
self.config.vector_store.config.collection_name = "mem0migrations"
|
||||||
|
if self.config.vector_store.provider in ["faiss", "qdrant"]:
|
||||||
|
provider_path = f"migrations_{self.config.vector_store.provider}"
|
||||||
|
self.config.vector_store.config.path = os.path.join(mem0_dir, provider_path)
|
||||||
|
os.makedirs(self.config.vector_store.config.path, exist_ok=True)
|
||||||
|
self._telemetry_vector_store = VectorStoreFactory.create(
|
||||||
|
self.config.vector_store.provider, self.config.vector_store.config
|
||||||
|
)
|
||||||
|
|
||||||
capture_event("mem0.init", self, {"sync_type": "async"})
|
capture_event("mem0.init", self, {"sync_type": "async"})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -1580,10 +1593,14 @@ class AsyncMemory(MemoryBase):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
memory_id (str): ID of the memory to update.
|
memory_id (str): ID of the memory to update.
|
||||||
data (dict): Data to update the memory with.
|
data (str): New content to update the memory with.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Updated memory.
|
dict: Success message indicating the memory was updated.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>>> await m.update(memory_id="mem_123", data="Likes to play tennis on weekends")
|
||||||
|
{'message': 'Memory updated successfully!'}
|
||||||
"""
|
"""
|
||||||
capture_event("mem0.update", self, {"memory_id": memory_id, "sync_type": "async"})
|
capture_event("mem0.update", self, {"memory_id": memory_id, "sync_type": "async"})
|
||||||
|
|
||||||
|
|||||||
+5
-10
@@ -11,16 +11,11 @@ import mem0
|
|||||||
try:
|
try:
|
||||||
import litellm
|
import litellm
|
||||||
except ImportError:
|
except ImportError:
|
||||||
user_input = input("The 'litellm' library is required. Install it now? [y/N]: ")
|
try:
|
||||||
if user_input.lower() == "y":
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "litellm"])
|
||||||
try:
|
import litellm
|
||||||
subprocess.check_call([sys.executable, "-m", "pip", "install", "litellm"])
|
except subprocess.CalledProcessError:
|
||||||
import litellm
|
print("Failed to install 'litellm'. Please install it manually using 'pip install litellm'.")
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
print("Failed to install 'litellm'. Please install it manually using 'pip install litellm'.")
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
raise ImportError("The required 'litellm' library is not installed.")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
from mem0 import Memory, MemoryClient
|
from mem0 import Memory, MemoryClient
|
||||||
|
|||||||
+3
-2
@@ -14,7 +14,7 @@ requires-python = ">=3.9,<4.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"qdrant-client>=1.9.1",
|
"qdrant-client>=1.9.1",
|
||||||
"pydantic>=2.7.3",
|
"pydantic>=2.7.3",
|
||||||
"openai>=1.33.0",
|
"openai>=1.90.0,<1.100.0",
|
||||||
"posthog>=3.5.0",
|
"posthog>=3.5.0",
|
||||||
"pytz>=2024.1",
|
"pytz>=2024.1",
|
||||||
"sqlalchemy>=2.0.31",
|
"sqlalchemy>=2.0.31",
|
||||||
@@ -46,7 +46,8 @@ vector_stores = [
|
|||||||
llms = [
|
llms = [
|
||||||
"groq>=0.3.0",
|
"groq>=0.3.0",
|
||||||
"together>=0.2.10",
|
"together>=0.2.10",
|
||||||
"litellm>=0.1.0",
|
"litellm>=1.74.0",
|
||||||
|
"openai>=1.90.0,<1.100.0",
|
||||||
"ollama>=0.1.0",
|
"ollama>=0.1.0",
|
||||||
"vertexai>=0.1.0",
|
"vertexai>=0.1.0",
|
||||||
"google-generativeai>=0.3.0",
|
"google-generativeai>=0.3.0",
|
||||||
|
|||||||
+9
-1
@@ -151,7 +151,15 @@ def search_memories(search_req: SearchRequest):
|
|||||||
|
|
||||||
@app.put("/memories/{memory_id}", summary="Update a memory")
|
@app.put("/memories/{memory_id}", summary="Update a memory")
|
||||||
def update_memory(memory_id: str, updated_memory: Dict[str, Any]):
|
def update_memory(memory_id: str, updated_memory: Dict[str, Any]):
|
||||||
"""Update an existing memory."""
|
"""Update an existing memory with new content.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
memory_id (str): ID of the memory to update
|
||||||
|
updated_memory (str): New content to update the memory with
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: Success message indicating the memory was updated
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return MEMORY_INSTANCE.update(memory_id=memory_id, data=updated_memory)
|
return MEMORY_INSTANCE.update(memory_id=memory_id, data=updated_memory)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user