[dev] modify prompt handler

This commit is contained in:
jinli.yl 2024-07-01 15:09:28 +08:00
parent a350fb131a
commit 64fa3badcc
4 changed files with 102 additions and 4 deletions

77
config/test_config.yaml Normal file
View file

@ -0,0 +1,77 @@
global_config:
language: cn
max_workers: 5
dash_scope_apikey:
open_ai_apikey:
memory_chat:
cli_memory_chat:
class: chat.cli_memory_chat
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
history_msg_count: 32
contextual_msg_count: 6
read_memory_key: read_memory
memory_operations:
read_message:
class: memory.operation.read_memory
workflow: dummy_worker
description: "read session messages of the user"
read_memory:
class: memory.operation.read_memory
workflow: dummy_worker
description: "read related memories of the user"
list_memory:
class: memory.operation.read_memory
workflow: dummy_worker
description: "read all memories of the user"
write_memory:
class: memory.operation.write_memory
workflow: dummy_worker
description: "write observation memories of the user"
interval_time: 60
summary_memory:
class: memory.operation.summary_memory
workflow: dummy_worker
description: "summary observation memories of the user"
interval_time: 300
models:
dashscope_generation:
class: models.llama_index_generation_model
module_name: dashscope_generation
model_name: qwen-max
dashscope_embedding:
class: models.llama_index_embedding_model
module_name: dashscope_embedding
model_name: text-embedding-v2
dashscope_rank:
class: models.llama_index_rank_model
module_name: dashscope_rank
model_name: gte-rerank
vector_store:
class: storage.dummy_vector_store
embedding_model: dashscope_embedding
monitor:
class: storage.dummy_monitor
worker:
dummy_worker:
class: memory.worker.dummy_worker
generation_model: dashscope_generation
embedding_model: dashscope_embedding
rank_model: dashscope_rank
retrieve_store_worker:
class: memory.worker.read.retrieve_store_worker
retrieve_obs_top_k: 100
retrieve_ins_pf_top_k: 100
fuse_rerank_worker:
class: memory.worker.read.fuse_rerank_worker
fuse_score_threshold: 0.1
fuse_ratio_dict:
observation: 1
fuse_time_ratio: 2.0
fuse_rerank_top_k: 10

View file

@ -0,0 +1,20 @@
from typing import Dict, List
from memory_scope.models.base_model import BaseModel
from memory_scope.scheme.memory_node import MemoryNode
from memory_scope.storage.base_vector_store import BaseVectorStore
class DummyVectorStore(BaseVectorStore):
def __init__(self, embedding_model: BaseModel, **kwargs):
self.embedding_model: BaseModel = embedding_model
def retrieve(self, query: str, top_k: int, filter_dict: Dict[str, List[str]]) -> List[MemoryNode]:
pass
async def async_retrieve(self, query: str, top_k: int, filter_dict: Dict[str, List[str]]) -> List[MemoryNode]:
pass
def insert(self, node: MemoryNode):
pass

View file

@ -17,12 +17,13 @@ class PromptHandler(object):
def add_file_prompts(self, name: str, to_underscore: bool = True):
if to_underscore:
name: str = camelcase_to_underscore(name)
class_path = os.path.join(self._default_prompt_dir, name)
if os.path.exists(f"{class_path}.yaml"):
with open(class_path) as f:
with open(f"{class_path}.yaml") as f:
prompt_language_dict = yaml.load(f, yaml.FullLoader)
elif os.path.exists(f"{class_path}.json"):
with open(class_path) as f:
with open(f"{class_path}.json") as f:
prompt_language_dict = json.load(f)
else:
raise RuntimeError(f"{class_path}.yaml/json is not exists!")
@ -30,7 +31,7 @@ class PromptHandler(object):
for key, language_dict in prompt_language_dict.items():
prompts = language_dict.get(G_CONTEXT.language)
if not prompts:
raise RuntimeError(f"{key}.prompt is empty!")
raise RuntimeError(f"{key}.prompt.{G_CONTEXT.language} is empty!")
self._prompt_dict[key] = prompts
@property

View file

@ -16,7 +16,7 @@ from memory_scope.enumeration.message_role_enum import MessageRoleEnum
def underscore_to_camelcase(name: str, is_first_title: bool = True):
name_split = name.split("_")
if is_first_title:
return "".join(x.title() for x in name_split[1:])
return "".join(x.title() for x in name_split)
else:
return name_split[0] + ''.join(x.title() for x in name_split[1:])