mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-10 22:41:06 +00:00
[dev] add kwargs to context
This commit is contained in:
parent
8bfec9c246
commit
623a9fac61
9 changed files with 17 additions and 17 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ RESULT = "result"
|
|||
|
||||
CHAT_MESSAGES = "chat_messages"
|
||||
|
||||
CHAT_KWARGS = "chat_kwargs"
|
||||
|
||||
RELATED_MEMORIES = "related_memories"
|
||||
|
||||
MESSAGES = "messages"
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue