fix:优化部分Log

pull/1396/head
SengokuCola 2025-11-30 16:57:15 +08:00
parent fdc0a87c31
commit 3368c38d05
8 changed files with 27 additions and 23 deletions

View File

@ -356,7 +356,7 @@ async def clean_unused_emojis(emoji_dir: str, emoji_objects: List["MaiEmoji"], r
if cleaned_count > 0:
logger.info(f"[清理] 在目录 {emoji_dir} 中清理了 {cleaned_count} 个破损表情包。")
else:
logger.info(f"[清理] 目录 {emoji_dir} 中没有需要清理的。")
logger.debug(f"[清理] 目录 {emoji_dir} 中没有需要清理的。")
except Exception as e:
logger.error(f"[错误] 清理未使用表情包文件时出错 ({emoji_dir}): {str(e)}")

View File

@ -25,7 +25,7 @@ class MemoryForgetTask(AsyncTask):
"""执行遗忘检查"""
try:
current_time = time.time()
logger.info("[记忆遗忘] 开始遗忘检查...")
# logger.info("[记忆遗忘] 开始遗忘检查...")
# 执行4个阶段的遗忘检查
await self._forget_stage_1(current_time)
@ -33,7 +33,7 @@ class MemoryForgetTask(AsyncTask):
await self._forget_stage_3(current_time)
await self._forget_stage_4(current_time)
logger.info("[记忆遗忘] 遗忘检查完成")
# logger.info("[记忆遗忘] 遗忘检查完成")
except Exception as e:
logger.error(f"[记忆遗忘] 执行遗忘检查时出错: {e}", exc_info=True)

View File

@ -151,7 +151,6 @@ class ExpressionSelector:
else:
selected_style = []
logger.info(f"随机选择,为聊天室 {chat_id} 选择了 {len(selected_style)} 个表达方式")
return selected_style
except Exception as e:
@ -294,7 +293,7 @@ class ExpressionSelector:
if valid_expressions:
self.update_expressions_last_active_time(valid_expressions)
logger.info(f"classic模式{len(all_expressions)}个情境中选择了{len(valid_expressions)}")
logger.debug(f"{len(all_expressions)}个情境中选择了{len(valid_expressions)}")
return valid_expressions, selected_ids
except Exception as e:

View File

@ -326,7 +326,7 @@ class ChatHistorySummarizer:
start_time=new_messages[0].time if new_messages else current_time,
end_time=current_time,
)
logger.info(f"{self.log_prefix} 新建聊天检查批次: {len(new_messages)} 条消息")
logger.debug(f"{self.log_prefix} 新建聊天检查批次: {len(new_messages)} 条消息")
# 创建批次后持久化
self._persist_topic_cache()
@ -362,7 +362,7 @@ class ChatHistorySummarizer:
else:
time_str = f"{time_since_last_check / 3600:.1f}小时"
logger.info(
logger.debug(
f"{self.log_prefix} 批次状态检查 | 消息数: {message_count} | 距上次检查: {time_str}"
)

View File

@ -138,7 +138,7 @@ class JargonExplainer:
query_duration = query_time - start_time
match_duration = match_time - query_time
logger.info(
logger.debug(
f"黑话匹配完成: 查询耗时 {query_duration:.3f}s, 匹配耗时 {match_duration:.3f}s, "
f"总耗时 {total_time:.3f}s, 匹配到 {len(matched_jargon)} 个黑话"
)

View File

@ -114,9 +114,9 @@ def init_memory_retrieval_prompt():
**执行步骤**
**第一步思考Think**
在思考中分析
- 当前信息是否足够回答问题
- 当前信息是否足够回答问题({question})
- **如果信息足够且能找到明确答案**在思考中直接给出答案格式为found_answer(answer="你的答案内容")
- **如果需要尝试搜集更多信息进一步调用工具进入第二步行动环节
- **如果信息不足以解答问题需要尝试搜集更多信息进一步调用工具进入第二步行动环节
- **如果已有信息不足或无法找到答案决定结束查询**在思考中给出not_enough_info(reason="结束查询的原因")
**第二步行动Action**
@ -229,6 +229,7 @@ async def _retrieve_concepts_with_jargon(concepts: List[str], chat_id: str) -> s
from src.jargon.jargon_miner import search_jargon
results = []
exact_matches = [] # 收集所有精确匹配的概念
for concept in concepts:
concept = concept.strip()
if not concept:
@ -264,11 +265,15 @@ async def _retrieve_concepts_with_jargon(concepts: List[str], chat_id: str) -> s
if meaning:
output_parts.append(f"'{concept}' 为黑话或者网络简写,含义为:{meaning}")
results.append("".join(output_parts) if len(output_parts) > 1 else output_parts[0])
logger.info(f"在jargon库中找到匹配精确匹配: {concept},找到{len(jargon_results)}条结果")
exact_matches.append(concept) # 收集精确匹配的概念,稍后统一打印
else:
# 未找到,不返回占位信息,只记录日志
logger.info(f"在jargon库中未找到匹配: {concept}")
# 合并所有精确匹配的日志
if exact_matches:
logger.info(f"找到黑话: {', '.join(exact_matches)},共找到{len(exact_matches)}条结果")
if results:
return "【概念检索结果】\n" + "\n".join(results) + "\n"
return ""
@ -276,7 +281,7 @@ async def _retrieve_concepts_with_jargon(concepts: List[str], chat_id: str) -> s
def _match_jargon_from_text(chat_text: str, chat_id: str) -> List[str]:
"""直接在聊天文本中匹配已知的jargon返回出现过的黑话列表"""
print(chat_text)
# print(chat_text)
if not chat_text or not chat_text.strip():
return []
@ -310,10 +315,10 @@ def _match_jargon_from_text(chat_text: str, chat_id: str) -> List[str]:
if re.search(search_pattern, chat_text, re.IGNORECASE):
matched[content] = None
end_time = time.time()
# end_time = time.time()
logger.info(
f"记忆检索黑话匹配: 查询耗时 {(query_time - start_time):.3f}s, "
f"匹配耗时 {(end_time - query_time):.3f}s, 总耗时 {(end_time - start_time):.3f}s, "
# f"记忆检索黑话匹配: 查询耗时 {(query_time - start_time):.3f}s, "
# f"匹配耗时 {(end_time - query_time):.3f}s, 总耗时 {(end_time - start_time):.3f}s, "
f"匹配到 {len(matched)} 个黑话"
)
@ -827,7 +832,7 @@ def _store_thinking_back(
create_time=now,
update_time=now,
)
logger.info(f"已创建思考过程到数据库,问题: {question[:50]}...")
# logger.info(f"已创建思考过程到数据库,问题: {question[:50]}...")
except Exception as e:
logger.error(f"存储思考过程失败: {e}")
@ -851,14 +856,14 @@ async def _process_single_question(
Returns:
Optional[str]: 如果找到答案返回格式化的结果字符串否则返回None
"""
logger.info(f"开始处理问题: {question}")
# logger.info(f"开始处理问题: {question}")
_cleanup_stale_not_found_thinking_back()
question_initial_info = initial_info or ""
# 直接使用ReAct Agent查询不再从thinking_back获取缓存
logger.info(f"使用ReAct Agent查询问题: {question[:50]}...")
# logger.info(f"使用ReAct Agent查询问题: {question[:50]}...")
jargon_concepts_for_agent = initial_jargon_concepts if global_config.memory.enable_jargon_detection else None
@ -942,7 +947,7 @@ async def build_memory_retrieval_prompt(
if global_config.debug.show_memory_prompt:
logger.info(f"记忆检索问题生成提示词: {question_prompt}")
logger.info(f"记忆检索问题生成响应: {response}")
# logger.info(f"记忆检索问题生成响应: {response}")
if not success:
logger.error(f"LLM生成问题失败: {response}")
@ -972,7 +977,7 @@ async def build_memory_retrieval_prompt(
concept_info = await _retrieve_concepts_with_jargon(concepts, chat_id)
if concept_info:
initial_info += concept_info
logger.info(f"概念检索完成,结果: {concept_info[:200]}...")
logger.info(f"概念检索完成,结果: {concept_info}")
else:
logger.info("概念检索未找到任何结果")
@ -984,7 +989,7 @@ async def build_memory_retrieval_prompt(
# 第二步:并行处理所有问题(使用配置的最大迭代次数/120秒超时
max_iterations = global_config.memory.max_agent_iterations
logger.info(f"问题数量: {len(questions)},设置最大迭代次数: {max_iterations},超时时间: 120秒")
logger.debug(f"问题数量: {len(questions)},设置最大迭代次数: {max_iterations},超时时间: 120秒")
# 并行处理所有问题,将概念检索结果作为初始信息传递
question_tasks = [

View File

@ -104,7 +104,7 @@ async def get_random(count: Optional[int] = 1) -> List[Tuple[str, str, str]]:
return []
if len(valid_emojis) < count:
logger.warning(
logger.debug(
f"[EmojiAPI] 有效表情包数量 ({len(valid_emojis)}) 少于请求的数量 ({count}),将返回所有有效表情包"
)
count = len(valid_emojis)

View File

@ -95,7 +95,7 @@ class ToolExecutor:
# 如果没有可用工具,直接返回空内容
if not tools:
logger.info(f"{self.log_prefix}没有可用工具,直接返回空内容")
logger.debug(f"{self.log_prefix}没有可用工具,直接返回空内容")
if return_details:
return [], [], ""
else: