feat:添加时段talk_frequency控制
This commit is contained in:
@@ -23,7 +23,7 @@ def init_prompt():
|
||||
以下是可选的表达情境:
|
||||
{all_situations}
|
||||
|
||||
请你分析聊天内容的语境、情绪、话题类型,从上述情境中选择最适合当前聊天情境的5-10个情境。
|
||||
请你分析聊天内容的语境、情绪、话题类型,从上述情境中选择最适合当前聊天情境的{min_num}-{max_num}个情境。
|
||||
考虑因素包括:
|
||||
1. 聊天的情绪氛围(轻松、严肃、幽默等)
|
||||
2. 话题类型(日常、技术、游戏、情感等)
|
||||
@@ -32,11 +32,11 @@ def init_prompt():
|
||||
请以JSON格式输出,只需要输出选中的情境编号:
|
||||
例如:
|
||||
{{
|
||||
"selected_situations": [2, 3, 5, 7, 9, 12, 15, 18, 21, 25]
|
||||
"selected_situations": [2, 3, 5, 7, 19, 22, 25, 38, 39, 45, 48 , 64]
|
||||
}}
|
||||
例如:
|
||||
{{
|
||||
"selected_situations": [1, 4, 7, 9, 13, 18, 24]
|
||||
"selected_situations": [1, 4, 7, 9, 23, 38, 44]
|
||||
}}
|
||||
|
||||
请严格按照JSON格式输出,不要包含其他内容:
|
||||
@@ -145,8 +145,8 @@ class ExpressionSelector:
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"更新表达方式count失败: {e}")
|
||||
|
||||
async def select_suitable_expressions_llm(self, chat_id: str, chat_info: str) -> List[Dict[str, str]]:
|
||||
|
||||
async def select_suitable_expressions_llm(self, chat_id: str, chat_info: str, max_num: int = 10, min_num: int = 5) -> List[Dict[str, str]]:
|
||||
"""使用LLM选择适合的表达方式"""
|
||||
|
||||
# 1. 获取35个随机表达方式(现在按权重抽取)
|
||||
@@ -191,9 +191,10 @@ class ExpressionSelector:
|
||||
bot_name=global_config.bot.nickname,
|
||||
chat_observe_info=chat_info,
|
||||
all_situations=all_situations_str,
|
||||
min_num=min_num,
|
||||
max_num=max_num,
|
||||
)
|
||||
|
||||
print(prompt)
|
||||
|
||||
# 4. 调用LLM
|
||||
try:
|
||||
|
||||
@@ -96,7 +96,7 @@ class ExpressionLearner:
|
||||
current_chat_type = "private"
|
||||
typed_chat_id = f"{platform}:{chat_stream.user_info.user_id}:{current_chat_type}"
|
||||
|
||||
logger.info(f"正在为 {typed_chat_id} 查找互通组...")
|
||||
logger.debug(f"正在为 {typed_chat_id} 查找互通组...")
|
||||
|
||||
found_group = None
|
||||
for group in expression_groups:
|
||||
@@ -108,7 +108,7 @@ class ExpressionLearner:
|
||||
break
|
||||
|
||||
if not found_group:
|
||||
logger.info(f"未找到互通组,仅加载 {chat_id} 的表达方式")
|
||||
logger.debug(f"未找到互通组,仅加载 {chat_id} 的表达方式")
|
||||
|
||||
if found_group:
|
||||
# 从带类型的id中解析出原始id
|
||||
@@ -121,7 +121,7 @@ class ExpressionLearner:
|
||||
except Exception:
|
||||
logger.warning(f"无法解析互通组中的ID: {item}")
|
||||
chat_ids_to_load = parsed_ids
|
||||
logger.info(f"将要加载以下id的表达方式: {chat_ids_to_load}")
|
||||
logger.debug(f"将要加载以下id的表达方式: {chat_ids_to_load}")
|
||||
|
||||
learnt_style_expressions = []
|
||||
learnt_grammar_expressions = []
|
||||
|
||||
@@ -180,7 +180,8 @@ class HeartFCMessageReceiver:
|
||||
# 7. 日志记录
|
||||
mes_name = chat.group_info.group_name if chat.group_info else "私聊"
|
||||
# current_time = time.strftime("%H:%M:%S", time.localtime(message.message_info.time))
|
||||
logger.info(f"[{mes_name}]{userinfo.user_nickname}:{message.processed_plain_text}")
|
||||
current_talk_frequency = global_config.chat.get_current_talk_frequency(chat.stream_id)
|
||||
logger.info(f"[{mes_name}]{userinfo.user_nickname}:{message.processed_plain_text}[当前回复频率: {current_talk_frequency}]")
|
||||
|
||||
# 8. 关系处理
|
||||
if global_config.relationship.enable_relationship:
|
||||
|
||||
@@ -71,9 +71,7 @@ class ExpressionSelectorProcessor(BaseProcessor):
|
||||
|
||||
try:
|
||||
# LLM模式:调用LLM选择5-10个,然后随机选5个
|
||||
selected_expressions = await expression_selector.select_suitable_expressions_llm(
|
||||
self.subheartflow_id, chat_info
|
||||
)
|
||||
selected_expressions = await expression_selector.select_suitable_expressions_llm(self.subheartflow_id, chat_info, max_num=12, min_num=2)
|
||||
cache_size = len(selected_expressions) if selected_expressions else 0
|
||||
mode_desc = f"LLM模式(已缓存{cache_size}个)"
|
||||
|
||||
|
||||
@@ -292,8 +292,11 @@ class PersonImpressionpProcessor(BaseProcessor):
|
||||
"message_count": self._count_messages_in_timerange(potential_start_time, message_time),
|
||||
}
|
||||
segments.append(new_segment)
|
||||
|
||||
|
||||
person_name = get_person_info_manager().get_value(person_id, "person_name")
|
||||
logger.info(
|
||||
f"{self.log_prefix} 为用户 {person_id} 创建新消息段: 时间范围 {time.strftime('%H:%M:%S', time.localtime(potential_start_time))} - {time.strftime('%H:%M:%S', time.localtime(message_time))}, 消息数: {new_segment['message_count']}"
|
||||
f"{self.log_prefix} 眼熟用户 {person_name} 在 {time.strftime('%H:%M:%S', time.localtime(potential_start_time))} - {time.strftime('%H:%M:%S', time.localtime(message_time))} 之间有 {new_segment['message_count']} 条消息"
|
||||
)
|
||||
self._save_cache()
|
||||
return
|
||||
@@ -339,7 +342,7 @@ class PersonImpressionpProcessor(BaseProcessor):
|
||||
"message_count": self._count_messages_in_timerange(potential_start_time, message_time),
|
||||
}
|
||||
segments.append(new_segment)
|
||||
logger.info(f"{self.log_prefix} 为用户 {person_id} 创建新消息段(超过10条消息间隔): {new_segment}")
|
||||
logger.info(f"{self.log_prefix} 重新眼熟用户 {person_name} 创建新消息段(超过10条消息间隔): {new_segment}")
|
||||
|
||||
self._save_cache()
|
||||
|
||||
|
||||
@@ -172,12 +172,12 @@ class ChatManager:
|
||||
key = "_".join(components)
|
||||
return hashlib.md5(key.encode()).hexdigest()
|
||||
|
||||
def get_stream_id(self, platform: str, chat_id: str, is_group: bool = True) -> str:
|
||||
def get_stream_id(self, platform: str, id: str, is_group: bool = True) -> str:
|
||||
"""获取聊天流ID"""
|
||||
if is_group:
|
||||
components = [platform, str(chat_id)]
|
||||
components = [platform, str(id)]
|
||||
else:
|
||||
components = [platform, str(chat_id), "private"]
|
||||
components = [platform, str(id), "private"]
|
||||
key = "_".join(components)
|
||||
return hashlib.md5(key.encode()).hexdigest()
|
||||
|
||||
|
||||
@@ -1000,7 +1000,7 @@ class NormalChat:
|
||||
"""
|
||||
# --- 1. 定义参数 ---
|
||||
evaluation_minutes = 10.0
|
||||
target_replies_per_min = global_config.chat.talk_frequency # 目标频率:e.g. 1条/分钟
|
||||
target_replies_per_min = global_config.chat.get_current_talk_frequency(self.stream_id) # 目标频率:e.g. 1条/分钟
|
||||
target_replies_in_window = target_replies_per_min * evaluation_minutes # 10分钟内的目标回复数
|
||||
|
||||
if target_replies_in_window <= 0:
|
||||
|
||||
@@ -163,7 +163,7 @@ class PromptBuilder:
|
||||
show_actions=True,
|
||||
)
|
||||
|
||||
expressions = await expression_selector.select_suitable_expressions_llm(chat_stream.stream_id, chat_talking_prompt_half)
|
||||
expressions = await expression_selector.select_suitable_expressions_llm(chat_stream.stream_id, chat_talking_prompt_half, max_num=8, min_num=3)
|
||||
style_habbits = []
|
||||
grammar_habbits = []
|
||||
if expressions:
|
||||
|
||||
Reference in New Issue
Block a user