mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-30 01:52:29 +00:00
refactor(memory): update profile handler and vector tools with improved formatting and error handling
- Add module docstring to profiles/__init__.py - Add pylint disable comments for no-name-in-module and missing-function-docstring - Format long error message in ProfileHandler.sync_run method for better readability - Reformat parameters in ProfileHandler.aadd method to separate lines - Update model_copy call in reme.py to span multiple lines for better readability - Format aadd_batch call in update_profile.py to span multiple lines
This commit is contained in:
parent
6af3f7df96
commit
375368786a
5 changed files with 22 additions and 4 deletions
|
|
@ -1,5 +1,7 @@
|
|||
"""memory tools"""
|
||||
|
||||
# pylint: disable=no-name-in-module
|
||||
|
||||
from .base_memory_tool import BaseMemoryTool
|
||||
|
||||
# chunk tools
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
"""Profile memory tools."""
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
"""Profile handler facade for filesystem and vector backends."""
|
||||
|
||||
# pylint: disable=missing-function-docstring
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
|
|
@ -66,7 +68,9 @@ class ProfileHandler:
|
|||
asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
return asyncio.run(coro)
|
||||
raise RuntimeError("Synchronous profile access is not available in an active event loop. Use async methods instead.")
|
||||
raise RuntimeError(
|
||||
"Synchronous profile access is not available in an active event loop. Use async methods instead.",
|
||||
)
|
||||
|
||||
async def adelete(self, profile_id: str | list[str]) -> bool | int:
|
||||
return await self.backend.delete(profile_id)
|
||||
|
|
@ -74,7 +78,13 @@ class ProfileHandler:
|
|||
async def adelete_all(self) -> int:
|
||||
return await self.backend.delete_all()
|
||||
|
||||
async def aadd(self, message_time: str, profile_key: str, profile_value: str, ref_memory_id: str = "") -> MemoryNode:
|
||||
async def aadd(
|
||||
self,
|
||||
message_time: str,
|
||||
profile_key: str,
|
||||
profile_value: str,
|
||||
ref_memory_id: str = "",
|
||||
) -> MemoryNode:
|
||||
return await self.backend.add(message_time, profile_key, profile_value, ref_memory_id)
|
||||
|
||||
async def aadd_batch(self, profiles: list[dict], ref_memory_id: str = "") -> list[MemoryNode]:
|
||||
|
|
|
|||
|
|
@ -98,7 +98,10 @@ class UpdateProfile(BaseMemoryTool):
|
|||
# Add profiles for each target
|
||||
for target, target_profiles in profiles_by_target.items():
|
||||
profile_handler = self.get_profile_handler(target)
|
||||
new_nodes = await profile_handler.aadd_batch(profiles=target_profiles, ref_memory_id=self.history_id)
|
||||
new_nodes = await profile_handler.aadd_batch(
|
||||
profiles=target_profiles,
|
||||
ref_memory_id=self.history_id,
|
||||
)
|
||||
self.memory_nodes.extend(new_nodes)
|
||||
added_count += len(new_nodes)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -238,7 +238,9 @@ class ReMe(Application):
|
|||
|
||||
if self.profile_store_name in vector_store_configs:
|
||||
if self.profile_collection_name:
|
||||
vector_store_configs[self.profile_store_name] = vector_store_configs[self.profile_store_name].model_copy(
|
||||
vector_store_configs[self.profile_store_name] = vector_store_configs[
|
||||
self.profile_store_name
|
||||
].model_copy(
|
||||
update={"collection_name": profile_collection_name},
|
||||
)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue