mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-06 08:16:00 +00:00
[dev] rename operation
This commit is contained in:
parent
08e15f2848
commit
375f7857c6
6 changed files with 23 additions and 17 deletions
|
|
@ -11,21 +11,25 @@ memory_chat:
|
|||
memory_service:
|
||||
memory_chat_service:
|
||||
class: memory.base_memory_service
|
||||
history_msg_count: 10
|
||||
history_msg_count: 32
|
||||
contextual_msg_count: 6
|
||||
memory_operations:
|
||||
read_user_message:
|
||||
class: memory.operation.read_memory
|
||||
workflow: dummy
|
||||
read_memory:
|
||||
class: memory.operation.read_operation
|
||||
class: memory.operation.read_memory
|
||||
workflow: dummy
|
||||
list_memory:
|
||||
class: memory.operation.read_operation
|
||||
class: memory.operation.read_memory
|
||||
workflow: dummy
|
||||
write_memory:
|
||||
class: memory.operation.write_operation
|
||||
class: memory.operation.write_memory
|
||||
workflow: dummy
|
||||
interval_time: 60
|
||||
contextual_msg_count: 6
|
||||
summary_memory:
|
||||
class: memory.operation.summary_operation
|
||||
class: memory.operation.summary_memory
|
||||
workflow: dummy
|
||||
interval_time: 300
|
||||
models:
|
||||
|
|
|
|||
|
|
@ -6,19 +6,20 @@ from memory_scope.memory.operation.base_workflow import BaseWorkflow
|
|||
from memory_scope.scheme.message import Message
|
||||
|
||||
|
||||
class ReadOperation(BaseWorkflow, BaseOperation):
|
||||
class ReadMemory(BaseWorkflow, BaseOperation):
|
||||
operation_type: OPERATION_TYPE = "frontend"
|
||||
|
||||
def __init__(self, chat_messages: List[Message], his_msg_count: int = 0, **kwargs):
|
||||
def __init__(self, chat_messages: List[Message], his_msg_count: int = 0, contextual_msg_count: int = 0, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.chat_messages: List[Message] = chat_messages
|
||||
self.his_msg_count: int = his_msg_count
|
||||
self.contextual_msg_count: int = contextual_msg_count
|
||||
|
||||
def init_workflow(self):
|
||||
self.init_workers()
|
||||
|
||||
def run_operation(self):
|
||||
max_count = 1 + self.his_msg_count
|
||||
max_count = 1 + max(self.his_msg_count, self.contextual_msg_count)
|
||||
self.context[CHAT_MESSAGES] = [x.copy() for x in self.chat_messages[-max_count:]]
|
||||
self.run_workflow()
|
||||
result = self.context.get(RESULT)
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
import time
|
||||
|
||||
from memory_scope.memory.base_workflow import BaseWorkflow
|
||||
|
||||
from memory_scope.chat_v2.global_context import G_CONTEXT
|
||||
from memory_scope.memory.operation.base_operation import BaseOperation, OPERATION_TYPE
|
||||
from memory_scope.memory.operation.base_workflow import BaseWorkflow
|
||||
|
||||
|
||||
class SummaryOperation(BaseWorkflow, BaseOperation):
|
||||
class SummaryMemory(BaseWorkflow, BaseOperation):
|
||||
operation_type: OPERATION_TYPE = "backend"
|
||||
|
||||
def __init__(self, interval_time: int = 300, **kwargs):
|
||||
|
|
@ -8,7 +8,7 @@ from memory_scope.memory.operation.base_workflow import BaseWorkflow
|
|||
from memory_scope.scheme.message import Message
|
||||
|
||||
|
||||
class WriteOperation(BaseOperation, BaseWorkflow):
|
||||
class WriteMemory(BaseOperation, BaseWorkflow):
|
||||
operation_type: OPERATION_TYPE = "backend"
|
||||
|
||||
def __init__(self,
|
||||
|
|
@ -9,5 +9,5 @@ class BaseMemoryService(metaclass=ABCMeta):
|
|||
self.kwargs = kwargs
|
||||
|
||||
@abstractmethod
|
||||
def get_short_memory(self):
|
||||
def do_operation(self, op_name: str):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class ChatMemoryService(BaseMemoryService):
|
|||
self.op_dict: Dict[str, BaseOperation] = self._init_operation(memory_operations)
|
||||
self.history_msg_count: int = history_msg_count
|
||||
self.contextual_msg_count: int = contextual_msg_count
|
||||
assert self.history_msg_count >= self.contextual_msg_count
|
||||
|
||||
self.chat_messages: List[Message] = []
|
||||
self.message_lock = threading.Lock
|
||||
|
|
@ -36,7 +37,10 @@ class ChatMemoryService(BaseMemoryService):
|
|||
contextual_msg_count=self.contextual_msg_count)
|
||||
return op_dict
|
||||
|
||||
def submit_message(self, messages: List[Message]):
|
||||
def submit_messages(self, messages: List[Message] | Message):
|
||||
if isinstance(messages, Message):
|
||||
messages = [messages]
|
||||
|
||||
messages = sorted(messages, key=lambda x: x.time_created)
|
||||
self.chat_messages.extend(messages)
|
||||
if len(self.chat_messages) > self.history_msg_count:
|
||||
|
|
@ -54,6 +58,4 @@ class ChatMemoryService(BaseMemoryService):
|
|||
if op_name not in self.op_dict:
|
||||
self.logger.warning(f"op_name={op_name} is not inited!")
|
||||
return
|
||||
|
||||
operation = self.op_dict[op_name]
|
||||
return operation.run_operation()
|
||||
return self.op_dict[op_name].run_operation()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue