From d8f3201a8e80221bb1994f36f9cc6c67e6b35117 Mon Sep 17 00:00:00 2001 From: "jinli.yl" Date: Thu, 20 Jun 2024 22:36:55 +0800 Subject: [PATCH] [dev] add global context json --- config/config_show.json | 28 +++++++++++++++++++++++++++ memory_scope/chat/base_memory_chat.py | 6 ++++++ memory_scope/chat/memory_chat.py | 8 ++++++++ memory_scope/chat/memory_show.py | 12 ++++++++++++ memory_scope/cli.py | 12 +++--------- 5 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 config/config_show.json create mode 100644 memory_scope/chat/memory_show.py diff --git a/config/config_show.json b/config/config_show.json new file mode 100644 index 00000000..43d53b94 --- /dev/null +++ b/config/config_show.json @@ -0,0 +1,28 @@ +{ + "global_configs": { + "thread_pool_max_count": 5, + "dash_scope_apikey": "", + "open_ai_apikey": "", + "language": "en", + "chat_list": [ + "memory_chat" + ] + }, + "memory_chat": { + "memory_user_name": "用户", + "clazz": "chat.memory_chat", + "retrieve": "parse_params,load_profile,extract_time,es_similar,es_keyword,semantic_rank,fuse_rerank", + "generation_model": "dashscope_generation", + "history_msg_count": 3 + }, + "vector_store": { + "clazz": "storage.base_vector_store", + "index_name": "memory_test", + "password": "" + }, + "monitor": { + "clazz": "storage.base_monitor", + "index_name": "memory_test" + }, + "workers": "workers" +} \ No newline at end of file diff --git a/memory_scope/chat/base_memory_chat.py b/memory_scope/chat/base_memory_chat.py index c20c61bb..3cc92392 100644 --- a/memory_scope/chat/base_memory_chat.py +++ b/memory_scope/chat/base_memory_chat.py @@ -16,3 +16,9 @@ class BaseMemoryChat(metaclass=ABCMeta): :param query: :return: """ + + @abstractmethod + def run(self): + """ + :return: + """ diff --git a/memory_scope/chat/memory_chat.py b/memory_scope/chat/memory_chat.py index d408f7b9..5526561d 100644 --- a/memory_scope/chat/memory_chat.py +++ b/memory_scope/chat/memory_chat.py @@ -50,3 +50,11 @@ class MemoryChat(BaseMemoryChat): all_messages = [system_message] + self.history_message_list # TODO at xian zhe return self.generation_model.call(messages=all_messages, stream=True) + + def run(self): + self.memory_service.start_memory_backend() + while True: + query = input("wait for input:") + if query in ["stop", "停止"]: + break + self.chat_with_memory(query=query) diff --git a/memory_scope/chat/memory_show.py b/memory_scope/chat/memory_show.py new file mode 100644 index 00000000..bf701d51 --- /dev/null +++ b/memory_scope/chat/memory_show.py @@ -0,0 +1,12 @@ +from memory_scope.chat.base_memory_chat import BaseMemoryChat + + +class MemoryShow(BaseMemoryChat): + + def chat_with_memory(self, query: str): + raise NotImplementedError + + def run(self): + self.memory_service.start_memory_backend() + result = self.memory_service.retrieve_all() + print(result) diff --git a/memory_scope/cli.py b/memory_scope/cli.py index d353fa2d..91439b94 100644 --- a/memory_scope/cli.py +++ b/memory_scope/cli.py @@ -90,17 +90,11 @@ class CliJob(object): GLOBAL_CONTEXT.vector_store = init_instance_by_config(self.config["vector_store"]) GLOBAL_CONTEXT.monitor = init_instance_by_config(self.config["monitor"]) - def run(self): + @staticmethod + def run(): with GLOBAL_CONTEXT.thread_pool, Timer("job", log_time=False) as t: memory_chat = list(GLOBAL_CONTEXT.memory_chat_dict.values())[0] - memory_chat.memory_service.start_memory_backend() - while True: - query = input("wait for input:") - if query in ["stop", "停止"]: - break - memory_chat.chat_with_memory(query=query) - - self.logger.info(f"chat complete. cost={t.cost_str}") + memory_chat.run() def main(config_path: str):