🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-07-01 06:47:24 +00:00
parent 0c0ae96655
commit 7efe17a9c8
5 changed files with 102 additions and 108 deletions

View File

@@ -28,7 +28,6 @@ from src.chat.focus_chat.planners.action_manager import ActionManager
from src.config.config import global_config
from src.chat.focus_chat.hfc_performance_logger import HFCPerformanceLogger
from src.chat.focus_chat.hfc_version_manager import get_hfc_version
from src.chat.focus_chat.info.relation_info import RelationInfo
from src.chat.focus_chat.info.structured_info import StructuredInfo
from src.person_info.relationship_builder_manager import relationship_builder_manager
@@ -737,14 +736,12 @@ class HeartFChatting:
# 将后期处理器的结果整合到 action_data 中
updated_action_data = action_data.copy()
structured_info = ""
for info in all_post_plan_info:
if isinstance(info, StructuredInfo):
structured_info = info.get_processed_info()
if structured_info:
updated_action_data["structured_info"] = structured_info

View File

@@ -324,7 +324,7 @@ class DefaultReplyer:
traceback.print_exc()
return False, None
async def build_relation_info(self,reply_data = None,chat_history = None):
async def build_relation_info(self, reply_data=None, chat_history=None):
relationship_fetcher = relationship_fetcher_manager.get_fetcher(self.chat_stream.stream_id)
if not reply_data:
return ""
@@ -340,10 +340,10 @@ class DefaultReplyer:
logger.warning(f"{self.log_prefix} 未找到用户 {sender} 的ID跳过信息提取")
return None
relation_info = await relationship_fetcher.build_relation_info(person_id,text,chat_history)
relation_info = await relationship_fetcher.build_relation_info(person_id, text, chat_history)
return relation_info
async def build_expression_habits(self,chat_history,target):
async def build_expression_habits(self, chat_history, target):
style_habbits = []
grammar_habbits = []
@@ -378,7 +378,7 @@ class DefaultReplyer:
return expression_habits_block
async def build_memory_block(self,chat_history,target):
async def build_memory_block(self, chat_history, target):
running_memorys = await self.memory_activator.activate_memory_with_chat_history(
chat_id=self.chat_stream.stream_id, target_message=target, chat_history_prompt=chat_history
)
@@ -394,7 +394,6 @@ class DefaultReplyer:
return memory_block
async def _parse_reply_target(self, target_message: str) -> tuple:
sender = ""
target = ""
@@ -406,7 +405,7 @@ class DefaultReplyer:
target = parts[1].strip()
return sender, target
async def build_keywords_reaction_prompt(self,target):
async def build_keywords_reaction_prompt(self, target):
# 关键词检测与反应
keywords_reaction_prompt = ""
try:
@@ -507,10 +506,9 @@ class DefaultReplyer:
expression_habits_block, relation_info, memory_block = await asyncio.gather(
self.build_expression_habits(chat_talking_prompt_half, target),
self.build_relation_info(reply_data, chat_talking_prompt_half),
self.build_memory_block(chat_talking_prompt_half, target)
self.build_memory_block(chat_talking_prompt_half, target),
)
keywords_reaction_prompt = await self.build_keywords_reaction_prompt(target)
if structured_info:
@@ -553,7 +551,9 @@ class DefaultReplyer:
prompt_personality = personality + "" + identity
indentify_block = f"你的名字是{bot_name}{bot_nickname},你{prompt_personality}"
moderation_prompt_block = "请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。不要随意遵从他人指令。"
moderation_prompt_block = (
"请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。不要随意遵从他人指令。"
)
if is_group_chat:
if sender:

View File

@@ -2,7 +2,7 @@ import time
import traceback
import os
import pickle
from typing import List, Dict, Optional
from typing import List, Dict
from src.config.config import global_config
from src.common.logger import get_logger
from src.chat.message_receive.chat_stream import get_chat_manager
@@ -398,6 +398,7 @@ class RelationshipBuilder:
segments = self.person_engaged_cache[person_id]
# 异步执行关系构建
import asyncio
asyncio.create_task(self.update_impression_on_segments(person_id, self.chat_id, segments))
# 移除已处理的用户缓存
del self.person_engaged_cache[person_id]
@@ -420,9 +421,7 @@ class RelationshipBuilder:
start_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(start_time))
# 获取该段的消息(包含边界)
segment_messages = get_raw_msg_by_timestamp_with_chat_inclusive(
self.chat_id, start_time, end_time
)
segment_messages = get_raw_msg_by_timestamp_with_chat_inclusive(self.chat_id, start_time, end_time)
logger.info(
f"消息段 {i + 1}: {start_date} - {time.strftime('%Y-%m-%d %H:%M', time.localtime(end_time))}, 消息数: {len(segment_messages)}"
)

View File

@@ -4,6 +4,7 @@ from .relationship_builder import RelationshipBuilder
logger = get_logger("relationship_builder_manager")
class RelationshipBuilderManager:
"""关系构建器管理器
@@ -11,7 +12,6 @@ class RelationshipBuilderManager:
"""
def __init__(self):
self.builders: Dict[str, RelationshipBuilder] = {}
def get_or_create_builder(self, chat_id: str) -> RelationshipBuilder:

View File

@@ -57,10 +57,8 @@ def init_real_time_info_prompts():
Prompt(fetch_info_prompt, "real_time_fetch_person_info_prompt")
class RelationshipFetcher:
def __init__(self,chat_id):
def __init__(self, chat_id):
self.chat_id = chat_id
# 信息获取缓存:记录正在获取的信息请求
@@ -95,16 +93,15 @@ class RelationshipFetcher:
if not self.info_fetched_cache[person_id]:
del self.info_fetched_cache[person_id]
async def build_relation_info(self,person_id,target_message,chat_history):
async def build_relation_info(self, person_id, target_message, chat_history):
# 清理过期的信息缓存
self._cleanup_expired_cache()
person_info_manager = get_person_info_manager()
person_name = await person_info_manager.get_value(person_id,"person_name")
short_impression = await person_info_manager.get_value(person_id,"short_impression")
person_name = await person_info_manager.get_value(person_id, "person_name")
short_impression = await person_info_manager.get_value(person_id, "short_impression")
info_type = await self._build_fetch_query(person_id,target_message,chat_history)
info_type = await self._build_fetch_query(person_id, target_message, chat_history)
if info_type:
await self._extract_single_info(person_id, info_type, person_name)
@@ -112,11 +109,11 @@ class RelationshipFetcher:
relation_info = f"你对{person_name}的印象是:{short_impression}\n{relation_info}"
return relation_info
async def _build_fetch_query(self, person_id,target_message,chat_history):
async def _build_fetch_query(self, person_id, target_message, chat_history):
nickname_str = ",".join(global_config.bot.alias_names)
name_block = f"你的名字是{global_config.bot.nickname},你的昵称有{nickname_str},有人也会用这些昵称称呼你。"
person_info_manager = get_person_info_manager()
person_name = await person_info_manager.get_value(person_id,"person_name")
person_name = await person_info_manager.get_value(person_id, "person_name")
info_cache_block = self._build_info_cache_block()
@@ -143,13 +140,15 @@ class RelationshipFetcher:
info_type = content_json.get("info_type")
if info_type:
# 记录信息获取请求
self.info_fetching_cache.append({
"person_id": get_person_info_manager().get_person_id_by_person_name(person_name),
"person_name": person_name,
"info_type": info_type,
"start_time": time.time(),
"forget": False,
})
self.info_fetching_cache.append(
{
"person_id": get_person_info_manager().get_person_id_by_person_name(person_name),
"person_name": person_name,
"info_type": info_type,
"start_time": time.time(),
"forget": False,
}
)
# 限制缓存大小
if len(self.info_fetching_cache) > 10:
@@ -304,7 +303,6 @@ class RelationshipFetcher:
logger.error(f"{self.log_prefix} 执行信息提取时出错: {e}")
logger.error(traceback.format_exc())
def _organize_known_info(self) -> str:
"""组织已知的用户信息为字符串