mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-05 08:06:15 +00:00
fix api
This commit is contained in:
parent
31b2f80d57
commit
75d0129909
8 changed files with 81 additions and 76 deletions
|
|
@ -2,9 +2,9 @@
|
|||
"thread_pool_max_count": "",
|
||||
"worker": "config/worker.json",
|
||||
"pipeline": {
|
||||
"summary_short": "",
|
||||
"summary_long": "",
|
||||
"retrieve": ""
|
||||
"summary_short": "parse_params,[load_profile|es_new_obs|es_insight],[update_insight|get_reflection,get_insight|update_profile],summary_collect,memory_store",
|
||||
"summary_long": "parse_params,info_filter,[es_today_obs|get_observation|get_observation_with_time],contra_repeat,memory_store",
|
||||
"retrieve": "parse_params,load_profile,[extract_time|es_similar|es_keyword],semantic_rank,fuse_rerank"
|
||||
},
|
||||
"model_embedding": "config/model/dash_embedding.json",
|
||||
"model_rerank": "config/model/dash_rerank.json",
|
||||
|
|
|
|||
|
|
@ -1,52 +1,45 @@
|
|||
{
|
||||
"EsInsightWorker": {
|
||||
"module_name": "EsInsightWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"es_insight_top_k": 128
|
||||
}
|
||||
"es_insight": {
|
||||
"name": "EsInsightWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"es_insight_top_k": 128
|
||||
},
|
||||
"es_keyword": {
|
||||
"name": "EsKeywordWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"es_keyword_top_k": 10
|
||||
},
|
||||
"es_keyword2": {
|
||||
"module_name": "EsKeywordWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"es_keyword_top_k": 10
|
||||
},
|
||||
"EsNewObsWorker": {
|
||||
"module_name": "EsNewObsWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "EsNewObsWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"es_new_obs_top_k": 256
|
||||
}
|
||||
},
|
||||
"EsNotReflectedWorker": {
|
||||
"module_name": "EsNotReflectedWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "EsNotReflectedWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"es_not_reflected_top_k": 256
|
||||
}
|
||||
},
|
||||
"EsSimilarWorker": {
|
||||
"module_name": "EsSimilarWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "EsSimilarWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"es_similar_top_k": 128
|
||||
}
|
||||
},
|
||||
"EsTodayObsWorker": {
|
||||
"module_name": "EsTodayObsWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "EsTodayObsWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"es_today_obs_top_k": 128
|
||||
}
|
||||
},
|
||||
"GetInsightWorker": {
|
||||
"module_name": "GetInsightWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "GetInsightWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"es_insight_similar_top_k": 128,
|
||||
"insight_obs_max_cnt": 10,
|
||||
|
|
@ -57,17 +50,16 @@
|
|||
}
|
||||
},
|
||||
"ExtractTimeWorker": {
|
||||
"module_name": "ExtractTimeWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"parse_time_model": "",
|
||||
"name": "ExtractTimeWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"parse_time_model": "qwen_1_8_parse_time_service",
|
||||
"parse_time_max_token": 100,
|
||||
"parse_time_temperature": 0.6,
|
||||
"parse_time_top_k": 1,
|
||||
"parse_time_top_k": 1
|
||||
},
|
||||
"InfoFilterWorker": {
|
||||
"module_name": "InfoFilterWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "InfoFilterWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"info_filter_msg_max_size": 200,
|
||||
"info_filter_model": "qwen_max",
|
||||
|
|
@ -77,8 +69,8 @@
|
|||
}
|
||||
},
|
||||
"GetObservationWithTimeWorker": {
|
||||
"module_name": "GetObservationWithTimeWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "GetObservationWithTimeWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"summary_messages_model": "qwen_max",
|
||||
"summary_messages_max_token": 500,
|
||||
|
|
@ -87,8 +79,8 @@
|
|||
}
|
||||
},
|
||||
"GetObservationWorker": {
|
||||
"module_name": "GetObservationWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "GetObservationWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"summary_messages_model": "qwen_max",
|
||||
"summary_messages_max_token": 500,
|
||||
|
|
@ -97,8 +89,8 @@
|
|||
}
|
||||
},
|
||||
"ContraRepeatWorker": {
|
||||
"module_name": "ContraRepeatWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "ContraRepeatWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"merge_obs_model": "qwen_max",
|
||||
"merge_obs_max_token": 500,
|
||||
|
|
@ -107,8 +99,8 @@
|
|||
}
|
||||
},
|
||||
"FuseRerankWorker": {
|
||||
"module_name": "FuseRerankWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "FuseRerankWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"fuse_score_threshold": 0.1,
|
||||
"fuse_ratio_dict": {
|
||||
|
|
@ -123,8 +115,8 @@
|
|||
}
|
||||
},
|
||||
"UpdateProfileWorker": {
|
||||
"module_name": "UpdateProfileWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "UpdateProfileWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"update_profile_threshold": 0.1,
|
||||
"update_profile_model": "qwen_max",
|
||||
|
|
@ -135,8 +127,8 @@
|
|||
}
|
||||
},
|
||||
"GetReflectionWorker": {
|
||||
"module_name": "GetReflectionWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "GetReflectionWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"reflect_obs_cnt_threshold": 40,
|
||||
"reflect_num_questions": 3,
|
||||
|
|
@ -147,8 +139,8 @@
|
|||
}
|
||||
},
|
||||
"UpdateInsightWorker": {
|
||||
"module_name": "UpdateInsightWorker",
|
||||
"module_path": "memory_scope/worker",
|
||||
"name": "UpdateInsightWorker",
|
||||
"path": "memory_scope/worker",
|
||||
"kwargs": {
|
||||
"update_insight_threshold": 0.1,
|
||||
"update_insight_model": "qwen_max",
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
# 使用argparse库的示例
|
||||
import argparse
|
||||
import fire
|
||||
from config import C, init
|
||||
from chat.memory_chat import MemoryChat
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="示例CLI程序")
|
||||
parser.add_argument('--echo', help="输出传入的消息")
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.echo:
|
||||
print(f"收到的消息: {args.echo}")
|
||||
|
||||
def main(config_path:str):
|
||||
init(config_path)
|
||||
|
||||
agent = MemoryChat()
|
||||
agent.run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
fire.Fire(main)
|
||||
|
|
|
|||
|
|
@ -19,10 +19,8 @@ class Wrapper:
|
|||
raise AttributeError("Please run __init__ first!")
|
||||
return getattr(self._provider, key)
|
||||
|
||||
|
||||
C = Wrapper()
|
||||
|
||||
|
||||
def init(config_path: str):
|
||||
config = json.loads(config_path)
|
||||
C.register(config)
|
||||
|
|
|
|||
|
|
@ -11,4 +11,8 @@ class MemoryServiceRequestModel(BaseModel):
|
|||
messages: List[Message] = Field(...,
|
||||
description="summary: 多轮对话的list,默认按照时间正序,最后一条是最新的; retrieve: 最后一条是query")
|
||||
|
||||
messages_pick_n: int = Field(1, description="summary:传需要总结的msg的个数;retrieve:不传")
|
||||
user_profile: List[UserAttribute] = Field([], description="user_profile")
|
||||
|
||||
ext_info: Dict[str, str] = Field({}, description="extra information")
|
||||
|
||||
extra_user_attrs: List = []
|
||||
|
|
@ -144,10 +144,13 @@ def time_to_formatted_str(time: datetime | str | int | float = None,
|
|||
return return_str
|
||||
|
||||
|
||||
def init_instance_by_config(config: dict, default_module_path=None, try_kwargs={}):
|
||||
def init_instance_by_config(config: dict|object, default_module_path: str = None, try_kwargs: dict = {}, accept_types: type = None):
|
||||
if isinstance(config, accept_types):
|
||||
return config
|
||||
|
||||
import_module(config.pop("path", default_module_path))
|
||||
clazz = getattr(module, config.pop("name"))
|
||||
try:
|
||||
return clazz(**config,**try_kwargs)
|
||||
return clazz(**config, **try_kwargs)
|
||||
except:
|
||||
return clazz(**config)
|
||||
|
|
@ -8,6 +8,7 @@ from node.user_attribute import UserAttribute
|
|||
from pipeline.memory import MemoryServiceRequestModel
|
||||
from worker.base_worker import BaseWorker
|
||||
from cli.cli_config import C
|
||||
from utils.tool_functions import init_instance_by_config
|
||||
|
||||
class MemoryBaseWorker(BaseWorker):
|
||||
def __init__(self, **kwargs):
|
||||
|
|
@ -21,7 +22,7 @@ class MemoryBaseWorker(BaseWorker):
|
|||
def messages(self) -> List[Message]:
|
||||
messages: List[Message] = self.context_handler.get_context(MESSAGES)
|
||||
if messages is None:
|
||||
messages = self.request.messages[-self.request.messages_pick_n:]
|
||||
messages = self.request.messages
|
||||
self.context_handler.set_context(MESSAGES, messages)
|
||||
return messages
|
||||
|
||||
|
|
@ -51,20 +52,32 @@ class MemoryBaseWorker(BaseWorker):
|
|||
return self.request.user.prompt
|
||||
|
||||
@property
|
||||
def emb_client(self):
|
||||
return C.model_embedding
|
||||
def client(self, model_type: str, model_name:str):
|
||||
models = C.get(model_type)
|
||||
models["model_name"] = init_instance_by_config(
|
||||
config = models.get(model_name),
|
||||
try_kwargs={
|
||||
"is_multi_thread": is_multi_thread,
|
||||
"thread_pool": self.thread_pool
|
||||
}
|
||||
)
|
||||
return models["model_name"]
|
||||
|
||||
@property
|
||||
def emb_client(self, model_name: str):
|
||||
self.client("model_embedding", model_name)
|
||||
|
||||
@property
|
||||
def gene_client(self):
|
||||
return C.model_generate
|
||||
self.client("model_generate", model_name)
|
||||
|
||||
@property
|
||||
def rerank_client(self):
|
||||
return C.model_rerank
|
||||
self.client("model_rerank", model_name)
|
||||
|
||||
@property
|
||||
def es_client(self):
|
||||
return C.db
|
||||
self.client("db", model_name)
|
||||
|
||||
@property
|
||||
def tenant_id(self):
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ import os
|
|||
import time
|
||||
from typing import List, Dict
|
||||
|
||||
from utils.logger import Logger
|
||||
from constants.common_constants import NEW_USER_PROFILE, MODIFIED_MEMORIES, RELATED_MEMORIES
|
||||
from enumeration.memory_method_enum import MemoryMethodEnum
|
||||
from node.memory_node import MemoryNode
|
||||
from node.user_attribute import UserAttribute
|
||||
from pipeline.memory import MemoryServiceRequestModel
|
||||
from service.memory_service_bailian import MemoryServiceBailian
|
||||
from memory_scope.utils.logger import Logger
|
||||
from memory_scope.constants.common_constants import NEW_USER_PROFILE, MODIFIED_MEMORIES, RELATED_MEMORIES
|
||||
from memory_scope.enumeration.memory_method_enum import MemoryMethodEnum
|
||||
from memory_scope.node.memory_node import MemoryNode
|
||||
from memory_scope.node.user_attribute import UserAttribute
|
||||
from memory_scope.pipeline.memory import MemoryServiceRequestModel
|
||||
from memory_scope.pipeline.memory_service import MemoryService
|
||||
|
||||
"""
|
||||
任务:随机生成一个用户的画像,随机种子0,并根据用户的画像虚拟一段用户和AI的对话。
|
||||
|
|
@ -139,10 +139,8 @@ for i, msg in enumerate(messages3):
|
|||
|
||||
|
||||
def summary_short(messages):
|
||||
messages_pick_n = len(messages)
|
||||
request: MemoryServiceRequestModel = MemoryServiceRequestModel(
|
||||
messages=messages,
|
||||
messages_pick_n=messages_pick_n,
|
||||
memory_id=memory_id,
|
||||
workspace_id=workspace_id,
|
||||
api_key=api_key,
|
||||
|
|
@ -171,7 +169,6 @@ def summary_short(messages):
|
|||
def summary_long():
|
||||
request: MemoryServiceRequestModel = MemoryServiceRequestModel(
|
||||
messages=[],
|
||||
messages_pick_n=0,
|
||||
memory_id=memory_id,
|
||||
workspace_id=workspace_id,
|
||||
api_key=api_key,
|
||||
|
|
@ -204,7 +201,6 @@ def summary_long():
|
|||
def retrieve(messages):
|
||||
request: MemoryServiceRequestModel = MemoryServiceRequestModel(
|
||||
messages=messages,
|
||||
messages_pick_n=1,
|
||||
memory_id=memory_id,
|
||||
workspace_id=workspace_id,
|
||||
api_key=api_key,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue