diff --git a/memory_scope/chat/cli_memory_chat.py b/memory_scope/chat/cli_memory_chat.py index d30c8faa..3ce61358 100644 --- a/memory_scope/chat/cli_memory_chat.py +++ b/memory_scope/chat/cli_memory_chat.py @@ -112,7 +112,7 @@ class CliMemoryChat(BaseMemoryChat): questionary.print(text=f" {desc}") elif command == "stream": - self.stream = ~self.stream + self.stream = not self.stream questionary.print(f"set stream: {self.stream}") elif command in self.memory_service.op_description_dict: @@ -130,7 +130,7 @@ class CliMemoryChat(BaseMemoryChat): questionary.print(result) else: - questionary.print("unknown command received. Please try again!") + questionary.print(f"Unknown command={command} received.") return continue_run diff --git a/memory_scope/constants/common_constants.py b/memory_scope/constants/common_constants.py index 81a65558..23c05c88 100644 --- a/memory_scope/constants/common_constants.py +++ b/memory_scope/constants/common_constants.py @@ -4,6 +4,8 @@ RESULT = "result" CHAT_MESSAGES = "chat_messages" +CHAT_KWARGS = "chat_kwargs" + RELATED_MEMORIES = "related_memories" MESSAGES = "messages" diff --git a/memory_scope/memory/operation/read_memory.py b/memory_scope/memory/operation/read_memory.py index 862675d7..05089392 100644 --- a/memory_scope/memory/operation/read_memory.py +++ b/memory_scope/memory/operation/read_memory.py @@ -1,6 +1,6 @@ from typing import List -from memory_scope.constants.common_constants import RESULT, CHAT_MESSAGES +from memory_scope.constants.common_constants import RESULT, CHAT_MESSAGES, CHAT_KWARGS from memory_scope.memory.operation.base_operation import BaseOperation, OPERATION_TYPE from memory_scope.memory.operation.base_workflow import BaseWorkflow from memory_scope.scheme.message import Message @@ -28,8 +28,7 @@ class ReadMemory(BaseWorkflow, BaseOperation): def run_operation(self, **kwargs): max_count = 1 + max(self.his_msg_count, self.contextual_msg_count) self.context[CHAT_MESSAGES] = [x.copy(deep=True) for x in self.chat_messages[-max_count:]] - for k, v in kwargs: - self.context[k] = v + self.context[CHAT_KWARGS] = kwargs self.run_workflow() result = self.context.get(RESULT) self.context.clear() diff --git a/memory_scope/memory/operation/summary_memory.py b/memory_scope/memory/operation/summary_memory.py index ccb2ef2f..2cc7d00c 100644 --- a/memory_scope/memory/operation/summary_memory.py +++ b/memory_scope/memory/operation/summary_memory.py @@ -1,7 +1,7 @@ import time from memory_scope.chat.global_context import G_CONTEXT -from memory_scope.constants.common_constants import RESULT +from memory_scope.constants.common_constants import RESULT, CHAT_KWARGS from memory_scope.memory.operation.base_operation import BaseOperation, OPERATION_TYPE from memory_scope.memory.operation.base_workflow import BaseWorkflow @@ -31,8 +31,7 @@ class SummaryMemory(BaseWorkflow, BaseOperation): return self._operation_status_run = True - for k, v in kwargs: - self.context[k] = v + self.context[CHAT_KWARGS] = kwargs self.run_workflow() result = self.context.get(RESULT) self.context.clear() diff --git a/memory_scope/memory/operation/write_memory.py b/memory_scope/memory/operation/write_memory.py index 41599d25..edfd9746 100644 --- a/memory_scope/memory/operation/write_memory.py +++ b/memory_scope/memory/operation/write_memory.py @@ -2,7 +2,7 @@ import time from typing import List from memory_scope.chat.global_context import G_CONTEXT -from memory_scope.constants.common_constants import CHAT_MESSAGES, RESULT +from memory_scope.constants.common_constants import CHAT_MESSAGES, RESULT, CHAT_KWARGS from memory_scope.memory.operation.base_operation import BaseOperation, OPERATION_TYPE from memory_scope.memory.operation.base_workflow import BaseWorkflow from memory_scope.scheme.message import Message @@ -51,8 +51,7 @@ class WriteMemory(BaseWorkflow, BaseOperation): return self._operation_status_run = True - for k, v in kwargs: - self.context[k] = v + self.context[CHAT_KWARGS] = kwargs not_memorized_size = self.not_memorized_size if not_memorized_size < self.contextual_msg_count: return diff --git a/memory_scope/memory/service/base_memory_service.py b/memory_scope/memory/service/base_memory_service.py index 7a99ae87..bfac4780 100644 --- a/memory_scope/memory/service/base_memory_service.py +++ b/memory_scope/memory/service/base_memory_service.py @@ -35,7 +35,7 @@ class BaseMemoryService(metaclass=ABCMeta): pass @abstractmethod - def do_operation(self, op_name: str, *args, **kwargs): + def do_operation(self, op_name: str, **kwargs): raise NotImplementedError @property diff --git a/memory_scope/memory/service/chat_memory_service.py b/memory_scope/memory/service/chat_memory_service.py index f3667dfd..118a1f9a 100644 --- a/memory_scope/memory/service/chat_memory_service.py +++ b/memory_scope/memory/service/chat_memory_service.py @@ -43,11 +43,11 @@ class ChatMemoryService(BaseMemoryService): if operation.operation_type == "backend": operation.run_operation_backend() - def do_operation(self, op_name: str, *args, **kwargs): + def do_operation(self, op_name: str, **kwargs): if op_name not in self._operation_dict: self.logger.warning(f"op_name={op_name} is not inited!") return - return self._operation_dict[op_name].run_operation() + return self._operation_dict[op_name].run_operation(**kwargs) def stop_service(self): for _, operation in self._operation_dict.items(): diff --git a/memory_scope/memory/worker/dummy_worker.py b/memory_scope/memory/worker/dummy_worker.py index 0485ca89..239a422c 100644 --- a/memory_scope/memory/worker/dummy_worker.py +++ b/memory_scope/memory/worker/dummy_worker.py @@ -1,12 +1,13 @@ import datetime -from memory_scope.constants.common_constants import RESULT, WORKFLOW_NAME +from memory_scope.constants.common_constants import RESULT, WORKFLOW_NAME, CHAT_KWARGS from memory_scope.memory.worker.base_worker import BaseWorker class DummyWorker(BaseWorker): def _run(self): workflow_name = self.get_context(WORKFLOW_NAME) + chat_kwargs = self.get_context(CHAT_KWARGS) self.logger.info(f"enter workflow={workflow_name}.dummy_worker!") ts = int(datetime.datetime.now().timestamp()) - self.set_context(RESULT, f"test {workflow_name} \nts={ts}") + self.set_context(RESULT, f"test {workflow_name} kwargs={chat_kwargs} \nts={ts}") diff --git a/memory_scope/memory/worker/memory_base_worker.py b/memory_scope/memory/worker/memory_base_worker.py index 4c0d7878..fbf7ade5 100644 --- a/memory_scope/memory/worker/memory_base_worker.py +++ b/memory_scope/memory/worker/memory_base_worker.py @@ -79,4 +79,4 @@ class MemoryBaseWorker(BaseWorker, metaclass=ABCMeta): @staticmethod def get_prompt(prompt: dict) -> str: - return prompt[G_CONTEXT.global_configs["language"]] + return prompt[G_CONTEXT.language]