Fix indentation and linting issues
- Fixed tab/space inconsistencies in client.py and __init__.py - Renamed ambiguous variable 'l' to 'line' - All ruff checks now passing
This commit is contained in:
+9
-3
@@ -284,7 +284,7 @@ class Mem0LocalMemoryProvider(MemoryProvider):
|
|||||||
if r.get("text") or r.get("memory")
|
if r.get("text") or r.get("memory")
|
||||||
]
|
]
|
||||||
with self._prefetch_lock:
|
with self._prefetch_lock:
|
||||||
self._prefetch_result = "\n".join(f"- {l}" for l in lines)
|
self._prefetch_result = "\n".join(f"- {line}" for line in lines)
|
||||||
self._record_success()
|
self._record_success()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._record_failure()
|
self._record_failure()
|
||||||
@@ -353,7 +353,7 @@ class Mem0LocalMemoryProvider(MemoryProvider):
|
|||||||
return json.dumps({"result": "\n".join(lines), "count": len(lines)})
|
return json.dumps({"result": "\n".join(lines), "count": len(lines)})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._record_failure()
|
self._record_failure()
|
||||||
return tool_error(f"Failed to fetch profile: {e}")
|
return tool_error(f"Failed to fetch profile: {e}")
|
||||||
|
|
||||||
elif tool_name == "mem0_search":
|
elif tool_name == "mem0_search":
|
||||||
query = args.get("query", "")
|
query = args.get("query", "")
|
||||||
@@ -371,7 +371,13 @@ class Mem0LocalMemoryProvider(MemoryProvider):
|
|||||||
self._record_success()
|
self._record_success()
|
||||||
if not results:
|
if not results:
|
||||||
return json.dumps({"result": "No relevant memories found."})
|
return json.dumps({"result": "No relevant memories found."})
|
||||||
items = [{"memory": r.get("text") or r.get("memory", ""), "score": r.get("score", 0)} for r in results]
|
items = [
|
||||||
|
{
|
||||||
|
"memory": r.get("text") or r.get("memory", ""),
|
||||||
|
"score": r.get("score", 0),
|
||||||
|
}
|
||||||
|
for r in results
|
||||||
|
]
|
||||||
return json.dumps({"results": items, "count": len(items)})
|
return json.dumps({"results": items, "count": len(items)})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._record_failure()
|
self._record_failure()
|
||||||
|
|||||||
@@ -56,17 +56,7 @@ class LocalMem0Client:
|
|||||||
rerank: bool = False,
|
rerank: bool = False,
|
||||||
top_k: int = 10,
|
top_k: int = 10,
|
||||||
) -> List[Dict]:
|
) -> List[Dict]:
|
||||||
"""Search memories by semantic similarity.
|
"""Search memories by semantic similarity."""
|
||||||
|
|
||||||
Args:
|
|
||||||
query: Search query string
|
|
||||||
filters: Filters dict (e.g., {"user_id": "hermes-user"})
|
|
||||||
rerank: Enable reranking for higher precision
|
|
||||||
top_k: Maximum results to return
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of memory dicts with "text", "score", etc.
|
|
||||||
"""
|
|
||||||
payload = {
|
payload = {
|
||||||
"query": query,
|
"query": query,
|
||||||
"user_id": filters.get("user_id"),
|
"user_id": filters.get("user_id"),
|
||||||
@@ -78,35 +68,19 @@ class LocalMem0Client:
|
|||||||
result = self._request("POST", "/search", json=payload)
|
result = self._request("POST", "/search", json=payload)
|
||||||
return self._unwrap_results(result)
|
return self._unwrap_results(result)
|
||||||
|
|
||||||
def get_all(self, filters: Dict[str, Any]) -> List[Dict]:
|
def get_all(self, filters: Dict[str, Any]) -> List[Dict]:
|
||||||
"""Get all memories matching filters.
|
"""Get all memories matching filters."""
|
||||||
|
|
||||||
Args:
|
|
||||||
filters: Filters dict (e.g., {"user_id": "hermes-user"})
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of all matching memory dicts.
|
|
||||||
"""
|
|
||||||
params = filters
|
params = filters
|
||||||
result = self._request("GET", "/memories", params=params)
|
result = self._request("GET", "/memories", params=params)
|
||||||
return self._unwrap_results(result)
|
return self._unwrap_results(result)
|
||||||
|
|
||||||
def add(
|
def add(
|
||||||
self,
|
self,
|
||||||
messages: List[Dict[str, str]],
|
messages: List[Dict[str, str]],
|
||||||
filters: Dict[str, Any],
|
filters: Dict[str, Any],
|
||||||
infer: bool = True,
|
infer: bool = True,
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
"""Add conversation messages for fact extraction.
|
"""Add conversation messages for fact extraction."""
|
||||||
|
|
||||||
Args:
|
|
||||||
messages: List of {"role": "user|assistant", "content": "..."}
|
|
||||||
filters: Filters dict for scoping (user_id, agent_id)
|
|
||||||
infer: Whether to extract facts via LLM (True) or store verbatim (False)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Response dict with added memory IDs.
|
|
||||||
"""
|
|
||||||
payload = {
|
payload = {
|
||||||
"messages": messages,
|
"messages": messages,
|
||||||
"user_id": filters.get("user_id"),
|
"user_id": filters.get("user_id"),
|
||||||
@@ -118,13 +92,8 @@ class LocalMem0Client:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _unwrap_results(response: Any) -> List[Dict]:
|
def _unwrap_results(response: Any) -> List[Dict]:
|
||||||
"""Normalize Mem0 API response.
|
"""Normalize Mem0 API response."""
|
||||||
|
|
||||||
OSS server returns {"memories": [...]} or {"results": [...]}
|
|
||||||
Cloud API returns {"results": [...]}
|
|
||||||
"""
|
|
||||||
if isinstance(response, dict):
|
if isinstance(response, dict):
|
||||||
# Try "memories" first (OSS server), then "results" (cloud/API v2)
|
|
||||||
return response.get("memories", response.get("results", []))
|
return response.get("memories", response.get("results", []))
|
||||||
if isinstance(response, list):
|
if isinstance(response, list):
|
||||||
return response
|
return response
|
||||||
|
|||||||
Reference in New Issue
Block a user