feat:表达方式现在可以选择在不同群互通
This commit is contained in:
@@ -69,7 +69,7 @@ class ExpressionLearner:
|
|||||||
# TODO: API-Adapter修改标记
|
# TODO: API-Adapter修改标记
|
||||||
self.express_learn_model: LLMRequest = LLMRequest(
|
self.express_learn_model: LLMRequest = LLMRequest(
|
||||||
model=global_config.model.replyer_1,
|
model=global_config.model.replyer_1,
|
||||||
temperature=0.1,
|
temperature=0.2,
|
||||||
request_type="expressor.learner",
|
request_type="expressor.learner",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -78,18 +78,62 @@ class ExpressionLearner:
|
|||||||
读取/data/expression/learnt/{chat_id}/expressions.json和/data/expression/personality/expressions.json
|
读取/data/expression/learnt/{chat_id}/expressions.json和/data/expression/personality/expressions.json
|
||||||
返回(learnt_expressions, personality_expressions)
|
返回(learnt_expressions, personality_expressions)
|
||||||
"""
|
"""
|
||||||
learnt_style_file = os.path.join("data", "expression", "learnt_style", str(chat_id), "expressions.json")
|
expression_groups = global_config.expression.expression_groups
|
||||||
learnt_grammar_file = os.path.join("data", "expression", "learnt_grammar", str(chat_id), "expressions.json")
|
chat_ids_to_load = [chat_id]
|
||||||
personality_file = os.path.join("data", "expression", "personality", "expressions.json")
|
|
||||||
|
# 获取当前chat_id的类型
|
||||||
|
chat_stream = get_chat_manager().get_stream(chat_id)
|
||||||
|
platform = chat_stream.platform
|
||||||
|
if chat_stream and chat_stream.group_info:
|
||||||
|
current_chat_type = "group"
|
||||||
|
typed_chat_id = f"{platform}:{chat_stream.group_info.group_id}:{current_chat_type}"
|
||||||
|
else:
|
||||||
|
typed_chat_id = f"{platform}:{chat_stream.user_info.user_id}:{current_chat_type}"
|
||||||
|
|
||||||
|
logger.info(f"正在为 {typed_chat_id} 查找互通组...")
|
||||||
|
|
||||||
|
found_group = None
|
||||||
|
for group in expression_groups:
|
||||||
|
# logger.info(f"正在检查互通组: {group}")
|
||||||
|
# logger.info(f"当前chat_id: {typed_chat_id}")
|
||||||
|
if typed_chat_id in group:
|
||||||
|
found_group = group
|
||||||
|
# logger.info(f"找到互通组: {group}")
|
||||||
|
break
|
||||||
|
|
||||||
|
if not found_group:
|
||||||
|
logger.info(f"未找到互通组,仅加载 {chat_id} 的表达方式")
|
||||||
|
|
||||||
|
if found_group:
|
||||||
|
# 从带类型的id中解析出原始id
|
||||||
|
parsed_ids = []
|
||||||
|
for item in found_group:
|
||||||
|
try:
|
||||||
|
platform, id, type = item.split(":")
|
||||||
|
chat_id = get_chat_manager().get_stream_id(platform, id, type == "group")
|
||||||
|
parsed_ids.append(chat_id)
|
||||||
|
except Exception:
|
||||||
|
logger.warning(f"无法解析互通组中的ID: {item}")
|
||||||
|
chat_ids_to_load = parsed_ids
|
||||||
|
logger.info(f"将要加载以下id的表达方式: {chat_ids_to_load}")
|
||||||
|
|
||||||
learnt_style_expressions = []
|
learnt_style_expressions = []
|
||||||
learnt_grammar_expressions = []
|
learnt_grammar_expressions = []
|
||||||
personality_expressions = []
|
|
||||||
|
for id_to_load in chat_ids_to_load:
|
||||||
|
learnt_style_file = os.path.join("data", "expression", "learnt_style", str(id_to_load), "expressions.json")
|
||||||
|
learnt_grammar_file = os.path.join(
|
||||||
|
"data", "expression", "learnt_grammar", str(id_to_load), "expressions.json"
|
||||||
|
)
|
||||||
if os.path.exists(learnt_style_file):
|
if os.path.exists(learnt_style_file):
|
||||||
with open(learnt_style_file, "r", encoding="utf-8") as f:
|
with open(learnt_style_file, "r", encoding="utf-8") as f:
|
||||||
learnt_style_expressions = json.load(f)
|
learnt_style_expressions.extend(json.load(f))
|
||||||
if os.path.exists(learnt_grammar_file):
|
if os.path.exists(learnt_grammar_file):
|
||||||
with open(learnt_grammar_file, "r", encoding="utf-8") as f:
|
with open(learnt_grammar_file, "r", encoding="utf-8") as f:
|
||||||
learnt_grammar_expressions = json.load(f)
|
learnt_grammar_expressions.extend(json.load(f))
|
||||||
|
|
||||||
|
personality_file = os.path.join("data", "expression", "personality", "expressions.json")
|
||||||
|
personality_expressions = []
|
||||||
if os.path.exists(personality_file):
|
if os.path.exists(personality_file):
|
||||||
with open(personality_file, "r", encoding="utf-8") as f:
|
with open(personality_file, "r", encoding="utf-8") as f:
|
||||||
personality_expressions = json.load(f)
|
personality_expressions = json.load(f)
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class ExpressionSelectorProcessor(BaseProcessor):
|
|||||||
|
|
||||||
self.subheartflow_id = subheartflow_id
|
self.subheartflow_id = subheartflow_id
|
||||||
self.last_selection_time = 0
|
self.last_selection_time = 0
|
||||||
self.selection_interval = 60 # 1分钟间隔
|
self.selection_interval = 40 # 1分钟间隔
|
||||||
self.cached_expressions = [] # 缓存上一次选择的表达方式
|
self.cached_expressions = [] # 缓存上一次选择的表达方式
|
||||||
|
|
||||||
# 表达方式选择模式
|
# 表达方式选择模式
|
||||||
@@ -158,16 +158,11 @@ class ExpressionSelectorProcessor(BaseProcessor):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# 根据模式选择表达方式
|
# 根据模式选择表达方式
|
||||||
if self.selection_mode == "llm":
|
|
||||||
# LLM模式:调用LLM选择15个,然后随机选5个
|
# LLM模式:调用LLM选择15个,然后随机选5个
|
||||||
selected_expressions = await self._select_suitable_expressions_llm(chat_info)
|
selected_expressions = await self._select_suitable_expressions_llm(chat_info)
|
||||||
cache_size = len(selected_expressions) if selected_expressions else 0
|
cache_size = len(selected_expressions) if selected_expressions else 0
|
||||||
mode_desc = f"LLM模式(已缓存{cache_size}个)"
|
mode_desc = f"LLM模式(已缓存{cache_size}个)"
|
||||||
else:
|
|
||||||
# 随机模式:直接随机选择5个
|
|
||||||
selected_expressions = await self._select_suitable_expressions_random(chat_info)
|
|
||||||
cache_size = len(selected_expressions) if selected_expressions else 0
|
|
||||||
mode_desc = f"随机模式(已缓存{cache_size}个)"
|
|
||||||
|
|
||||||
if selected_expressions:
|
if selected_expressions:
|
||||||
# 缓存选择的表达方式
|
# 缓存选择的表达方式
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ class RelationshipProcessor(BaseProcessor):
|
|||||||
self.person_engaged_cache: Dict[str, List[Dict[str, any]]] = {}
|
self.person_engaged_cache: Dict[str, List[Dict[str, any]]] = {}
|
||||||
|
|
||||||
# 持久化存储文件路径
|
# 持久化存储文件路径
|
||||||
self.cache_file_path = os.path.join("data", f"relationship_cache_{self.subheartflow_id}.pkl")
|
self.cache_file_path = os.path.join("data", "relationship", f"relationship_cache_{self.subheartflow_id}.pkl")
|
||||||
|
|
||||||
# 最后处理的消息时间,避免重复处理相同消息
|
# 最后处理的消息时间,避免重复处理相同消息
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class NormalChat:
|
|||||||
self.person_engaged_cache: Dict[str, List[Dict[str, any]]] = {}
|
self.person_engaged_cache: Dict[str, List[Dict[str, any]]] = {}
|
||||||
|
|
||||||
# 持久化存储文件路径
|
# 持久化存储文件路径
|
||||||
self.cache_file_path = os.path.join("data", f"relationship_cache_{self.stream_id}.pkl")
|
self.cache_file_path = os.path.join("data", "relationship", f"relationship_cache_{self.stream_id}.pkl")
|
||||||
|
|
||||||
# 最后处理的消息时间,避免重复处理相同消息
|
# 最后处理的消息时间,避免重复处理相同消息
|
||||||
self.last_processed_message_time = 0.0
|
self.last_processed_message_time = 0.0
|
||||||
|
|||||||
@@ -193,8 +193,13 @@ class ExpressionConfig(ConfigBase):
|
|||||||
enable_expression_learning: bool = True
|
enable_expression_learning: bool = True
|
||||||
"""是否启用表达学习"""
|
"""是否启用表达学习"""
|
||||||
|
|
||||||
selection_mode: str = "llm"
|
|
||||||
"""表达方式选择模式:'llm' 使用LLM智能选择,'random' 使用传统随机选择"""
|
|
||||||
|
expression_groups: list[list[str]] = field(default_factory=list)
|
||||||
|
"""
|
||||||
|
表达学习互通组
|
||||||
|
格式: [["qq:12345:group", "qq:67890:private"]]
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@@ -43,7 +43,13 @@ identity_detail = [
|
|||||||
expression_style = "描述麦麦说话的表达风格,表达习惯,例如:(回复尽量简短一些。可以参考贴吧,知乎和微博的回复风格,回复不要浮夸,不要用夸张修辞,平淡一些。不要有额外的符号,尽量简单简短)"
|
expression_style = "描述麦麦说话的表达风格,表达习惯,例如:(回复尽量简短一些。可以参考贴吧,知乎和微博的回复风格,回复不要浮夸,不要用夸张修辞,平淡一些。不要有额外的符号,尽量简单简短)"
|
||||||
enable_expression_learning = false # 是否启用表达学习,麦麦会学习不同群里人类说话风格(群之间不互通)
|
enable_expression_learning = false # 是否启用表达学习,麦麦会学习不同群里人类说话风格(群之间不互通)
|
||||||
learning_interval = 600 # 学习间隔 单位秒
|
learning_interval = 600 # 学习间隔 单位秒
|
||||||
selection_mode = "random" # 专注模式下 表达方式选择模式:'llm' 使用LLM智能选择,'random' 使用传统随机选择
|
|
||||||
|
expression_groups = [
|
||||||
|
["qq:1919810:private","qq:114514:private","qq:1111111:group"], # 在这里设置互通组,相同组的chat_id会共享学习到的表达方式
|
||||||
|
# 格式:["qq:123456:private","qq:654321:group"]
|
||||||
|
# 注意:如果为群聊,则需要设置为group,如果设置为私聊,则需要设置为private
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
[relationship]
|
[relationship]
|
||||||
enable_relationship = true # 是否启用关系系统
|
enable_relationship = true # 是否启用关系系统
|
||||||
|
|||||||
Reference in New Issue
Block a user