improve clarity

This commit is contained in:
fuqingxu 2024-07-03 21:58:11 +08:00
parent 47c1fde3f3
commit 771d444dc2
6 changed files with 63 additions and 16 deletions

View file

@ -1,3 +1,16 @@
[**English**](./README.md) | 中文
# ModelScope
## 概念解释
- service: 在顶层的交互对象用于定义operation的使用范围
- operation: 读写记忆等对于记忆的操作方法是worker的有序组合workflow
- workflow: 在operation中组合worker的方式
- worker: 框架中的基本工作模块

View file

@ -3,62 +3,68 @@ global_config:
max_workers: 5
dash_scope_apikey:
open_ai_apikey:
memory_chat:
cli_memory_chat:
class: chat.cli_memory_chat
class: chat.cli_memory_chat # select class
memory_service: memory_chat_service
generation_model: dashscope_generation
human_name: human
assistant_name: assistant
memory_service:
memory_chat_service:
class: memory.service.chat_memory_service
class: memory.service.chat_memory_service # select class
history_msg_count: 32
contextual_msg_count: 6
read_memory_key: read_memory
memory_operations:
read_message:
read_message: # define operation
class: memory.operation.read_memory
workflow: dummy_worker
workflow: dummy_workflow # select workflow
description: "read session messages of the user"
read_memory:
class: memory.operation.read_memory
workflow: dummy_worker
workflow: dummy_workflow
description: "read related memories of the user"
list_memory:
class: memory.operation.read_memory
workflow: dummy_worker
workflow: dummy_workflow
description: "read all memories of the user"
write_memory:
class: memory.operation.write_memory
workflow: dummy_worker
workflow: dummy_workflow
description: "write observation memories of the user"
interval_time: 60
summary_memory:
class: memory.operation.summary_memory
workflow: dummy_worker
workflow: dummy_workflow
description: "summary observation memories of the user"
interval_time: 300
models:
dashscope_generation:
class: models.llama_index_generation_model
class: models.llama_index_generation_model # select class
module_name: dashscope_generation
model_name: qwen-max
dashscope_embedding:
class: models.llama_index_embedding_model
class: models.llama_index_embedding_model # select class
module_name: dashscope_embedding
model_name: text-embedding-v2
dashscope_rank:
class: models.llama_index_rank_model
class: models.llama_index_rank_model # select class
module_name: dashscope_rank
model_name: gte-rerank
vector_store:
class: storage.dummy_vector_store
class: storage.dummy_vector_store # select class
embedding_model: dashscope_embedding
monitor:
class: storage.dummy_monitor
class: storage.dummy_monitor # select class
worker:
dummy_worker:
dummy_workflow:
class: memory.worker.dummy_worker
generation_model: dashscope_generation
embedding_model: dashscope_embedding

View file

@ -60,6 +60,8 @@ class CliMemoryChat(BaseMemoryChat):
@property
def memory_service(self) -> BaseMemoryService:
if isinstance(self._memory_service, str):
if self._memory_service not in G_CONTEXT.memory_service_dict:
raise ValueError("Missing declaration of memory_service in yaml configuration: " + self._memory_service)
self._memory_service = G_CONTEXT.memory_service_dict[self._memory_service]
self._memory_service.start_service()
return self._memory_service
@ -67,6 +69,8 @@ class CliMemoryChat(BaseMemoryChat):
@property
def generation_model(self) -> BaseModel:
if isinstance(self._generation_model, str):
if self._generation_model not in G_CONTEXT.model_dict:
raise ValueError("Missing declaration of generation model in yaml configuration: " + self._generation_model)
self._generation_model = G_CONTEXT.model_dict[self._generation_model]
return self._generation_model

View file

@ -31,6 +31,7 @@ class CliJob(object):
self.config = json.load(f)
else:
raise RuntimeError("not supported config file type!")
self.init_global_content_by_config()
def set_global_config(self):
G_CONTEXT.global_config = global_config = self.config["global_config"]
@ -67,7 +68,6 @@ 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]

View file

@ -33,7 +33,7 @@ class BaseWorkflow(object):
self.logger: Logger = Logger.get_logger()
if self.workflow:
self._parse_workflow()
self.workflow_worker_list = self._parse_workflow()
self._print_workflow()
def _parse_workflow(self):
@ -63,6 +63,7 @@ class BaseWorkflow(object):
for sub_item in sub_split:
self.worker_dict[sub_item] = is_multi_thread
self.workflow_worker_list.append(line_split_split)
return self.workflow_worker_list
def _print_workflow(self):
self.logger.info(f"----- print_workflow_{self.name}_begin -----")

View file

@ -30,6 +30,29 @@ def init_instance_by_config(config: dict,
default_class_path: str = "memory_scope",
suffix_name: str = "",
**kwargs):
"""
Initialize an instance of a class specified in the configuration dictionary.
This function dynamically imports a class from a module path, allowing for
user-defined classes or default paths. It supports adding a suffix to the
class name, merging additional keyword arguments with the config, and handling
nested module paths.
Args:
config (dict): A dictionary containing the configuration, including
the 'class' key that specifies the class's module path.
default_class_path (str, optional): The default module path prefix
to use if not explicitly defined in
'config'. Defaults to "memory_scope".
suffix_name (str, optional): A string to append to the class name,
ensuring the final class name ends with it.
Defaults to "".
**kwargs: Additional keyword arguments to pass to the class constructor.
Returns:
object: An instance of the class initialized with the provided config and kwargs.
"""
config_copy = deepcopy(config)
origin_class_path: str = config_copy.pop("class")
if not origin_class_path: