From d7b6e20777953b865b1460d812abe5a097b91e6d Mon Sep 17 00:00:00 2001 From: "jinli.yl" Date: Thu, 27 Jun 2024 14:10:48 +0800 Subject: [PATCH] [dev] rename clazz to class --- config/config.json | 9 ++++----- config/config.yaml | 7 +++---- memory_scope/chat_v2/cli_memory_chat.py | 18 +++++++++--------- memory_scope/cli.py | 6 +++++- memory_scope/memory/operation/base_workflow.py | 2 +- .../memory/service/chat_memory_service.py | 7 ++----- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/config/config.json b/config/config.json index 394cf9e8..e2a4ad5f 100644 --- a/config/config.json +++ b/config/config.json @@ -22,8 +22,7 @@ "read_message": { "class": "memory.operation.read_memory", "workflow": "dummy_worker", - "description": "read session messages of the user", - "contextual_msg_count": 0 + "description": "read session messages of the user" }, "read_memory": { "class": "memory.operation.read_memory", @@ -52,17 +51,17 @@ }, "models": { "dashscope_generation": { - "clazz": "models.llama_index_generation_model", + "class": "models.llama_index_generation_model", "module_name": "dashscope_generation", "model_name": "qwen-max" }, "dashscope_embedding": { - "clazz": "models.llama_index_embedding_model", + "class": "models.llama_index_embedding_model", "module_name": "dashscope_embedding", "model_name": "text-embedding-v2" }, "dashscope_rank": { - "clazz": "models.llama_index_rank_model", + "class": "models.llama_index_rank_model", "module_name": "dashscope_rank", "model_name": "gte-rerank" } diff --git a/config/config.yaml b/config/config.yaml index f6b0f85a..30b70c50 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -19,7 +19,6 @@ memory_service: class: memory.operation.read_memory workflow: dummy_worker description: "read session messages of the user" - contextual_msg_count: 0 read_memory: class: memory.operation.read_memory workflow: dummy_worker @@ -40,15 +39,15 @@ memory_service: interval_time: 300 models: dashscope_generation: - clazz: models.llama_index_generation_model + class: models.llama_index_generation_model module_name: dashscope_generation model_name: qwen-max dashscope_embedding: - clazz: models.llama_index_embedding_model + class: models.llama_index_embedding_model module_name: dashscope_embedding model_name: text-embedding-v2 dashscope_rank: - clazz: models.llama_index_rank_model + class: models.llama_index_rank_model module_name: dashscope_rank model_name: gte-rerank vector_store: diff --git a/memory_scope/chat_v2/cli_memory_chat.py b/memory_scope/chat_v2/cli_memory_chat.py index fa0bead1..c2012bd8 100644 --- a/memory_scope/chat_v2/cli_memory_chat.py +++ b/memory_scope/chat_v2/cli_memory_chat.py @@ -1,8 +1,9 @@ import datetime import time -from typing import Dict, List +from typing import List import questionary + from memory_scope.chat_v2.base_memory_chat import BaseMemoryChat from memory_scope.chat_v2.global_context import G_CONTEXT from memory_scope.enumeration.message_role_enum import MessageRoleEnum @@ -20,11 +21,11 @@ class CliMemoryChat(BaseMemoryChat): "stream": "get stream response" } - def __init__(self, memory_service: str, generation_model: str, **kwargs): - super().__init__(**kwargs) + def __init__(self, memory_service: str, generation_model: str, stream: bool = True, **kwargs): self._memory_service: BaseMemoryService | str = memory_service self._generation_model: BaseModel | str = generation_model - self.stream: bool = True + self.stream: bool = stream + self.kwargs: dict = kwargs @property def memory_service(self) -> BaseMemoryService: @@ -56,18 +57,17 @@ class CliMemoryChat(BaseMemoryChat): time_created = int(datetime.datetime.now().timestamp()) new_message: Message = Message(role=MessageRoleEnum.USER, content=query, time_created=time_created) - self.submit_messages(new_message) + self.memory_service.add_messages(new_message) related_memories: List[str] = self.memory_service.read_memory() system_message: Message = self.get_system_prompt(related_memories, time_created) if self.stream: for result in self.generation_model.call(messages=[system_message, new_message], stream=self.stream): yield result - self.submit_messages(result.text) + self.memory_service.add_messages(result.text) def run(self): - op_description_dict: Dict[str, str] = self.memory_service.get_op_description_dict() - self.USER_COMMANDS.update({f"/{k}": v for k, v in op_description_dict.items()}) + self.USER_COMMANDS.update({f"/{k}": v for k, v in self.memory_service.op_description_dict.items()}) while True: query = questionary.text( @@ -97,7 +97,7 @@ class CliMemoryChat(BaseMemoryChat): elif query == "stream": questionary.print(f"stream: {self.stream}") self.stream = ~self.stream - elif query in op_description_dict: + elif query in self.memory_service.op_description_dict: if not args: result = self.memory_service.do_operation(op_name=query) print(result) diff --git a/memory_scope/cli.py b/memory_scope/cli.py index f888e674..27da1f5d 100644 --- a/memory_scope/cli.py +++ b/memory_scope/cli.py @@ -1,3 +1,7 @@ +import sys + +sys.path.append(".") + import json from concurrent.futures import ThreadPoolExecutor from typing import Dict, Any @@ -58,7 +62,7 @@ class CliJob(object): def run(self, config: str): self.load_config(config) - + self.init_global_content_by_config() with G_CONTEXT.thread_pool: memory_chat = list(G_CONTEXT.memory_chat_dict.values())[0] memory_chat.run() diff --git a/memory_scope/memory/operation/base_workflow.py b/memory_scope/memory/operation/base_workflow.py index 540f6cb8..74ce7943 100644 --- a/memory_scope/memory/operation/base_workflow.py +++ b/memory_scope/memory/operation/base_workflow.py @@ -17,7 +17,7 @@ class BaseWorkflow(object): def __init__(self, name: str, workflow: str, - thread_pool: ThreadPoolExecutor, + thread_pool: ThreadPoolExecutor = G_CONTEXT.thread_pool, **kwargs): self.name: str = name diff --git a/memory_scope/memory/service/chat_memory_service.py b/memory_scope/memory/service/chat_memory_service.py index badd26c8..a2197e91 100644 --- a/memory_scope/memory/service/chat_memory_service.py +++ b/memory_scope/memory/service/chat_memory_service.py @@ -6,9 +6,7 @@ from memory_scope.utils.tool_functions import init_instance_by_config class ChatMemoryService(BaseMemoryService): - def __init__( - self, history_msg_count: int = 32, contextual_msg_count: int = 6, **kwargs - ): + def __init__(self, history_msg_count: int = 32, contextual_msg_count: int = 6, **kwargs): super().__init__(**kwargs) self.history_msg_count: int = history_msg_count self.contextual_msg_count: int = contextual_msg_count @@ -26,8 +24,7 @@ class ChatMemoryService(BaseMemoryService): name=name, chat_messages=self.chat_messages, message_lock=self.message_lock, - contextual_msg_count=self.contextual_msg_count, - ) + contextual_msg_count=self.contextual_msg_count) def add_messages(self, messages: List[Message] | Message): if isinstance(messages, Message):