fix: ruff
This commit is contained in:
@@ -8,7 +8,6 @@ from collections import deque
|
|||||||
import json # 引入 json
|
import json # 引入 json
|
||||||
|
|
||||||
# --- 引入 Matplotlib ---
|
# --- 引入 Matplotlib ---
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
from matplotlib.figure import Figure
|
from matplotlib.figure import Figure
|
||||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
||||||
import matplotlib.dates as mdates # 用于处理日期格式
|
import matplotlib.dates as mdates # 用于处理日期格式
|
||||||
@@ -165,7 +164,7 @@ class InterestMonitorApp:
|
|||||||
error_count += 1
|
error_count += 1
|
||||||
# logger.warning(f"Skipping invalid JSON line: {line.strip()}")
|
# logger.warning(f"Skipping invalid JSON line: {line.strip()}")
|
||||||
continue # 跳过无法解析的行
|
continue # 跳过无法解析的行
|
||||||
except (TypeError, ValueError) as e:
|
except (TypeError, ValueError):
|
||||||
error_count += 1
|
error_count += 1
|
||||||
# logger.warning(f"Skipping line due to data type error ({e}): {line.strip()}")
|
# logger.warning(f"Skipping line due to data type error ({e}): {line.strip()}")
|
||||||
continue # 跳过数据类型错误的行
|
continue # 跳过数据类型错误的行
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
from src.plugins.models.utils_model import LLMRequest
|
from src.plugins.models.utils_model import LLMRequest
|
||||||
from src.config.config import global_config
|
from src.config.config import global_config
|
||||||
from src.plugins.chat.chat_stream import ChatStream
|
from src.plugins.chat.chat_stream import ChatStream
|
||||||
from src.common.database import db
|
|
||||||
import time
|
|
||||||
import json
|
import json
|
||||||
from src.common.logger import get_module_logger, TOOL_USE_STYLE_CONFIG, LogConfig
|
from src.common.logger import get_module_logger, TOOL_USE_STYLE_CONFIG, LogConfig
|
||||||
from src.do_tool.tool_can_use import get_all_tool_definitions, get_tool_instance
|
from src.do_tool.tool_can_use import get_all_tool_definitions, get_tool_instance
|
||||||
from src.heart_flow.sub_heartflow import SubHeartflow
|
from src.heart_flow.sub_heartflow import SubHeartflow
|
||||||
import traceback
|
import traceback
|
||||||
from src.plugins.chat.utils import get_recent_group_detailed_plain_text
|
|
||||||
|
|
||||||
tool_use_config = LogConfig(
|
tool_use_config = LogConfig(
|
||||||
# 使用消息发送专用样式
|
# 使用消息发送专用样式
|
||||||
@@ -62,7 +59,7 @@ class ToolUser:
|
|||||||
prompt = ""
|
prompt = ""
|
||||||
prompt += mid_memory_info
|
prompt += mid_memory_info
|
||||||
prompt += "你正在思考如何回复群里的消息。\n"
|
prompt += "你正在思考如何回复群里的消息。\n"
|
||||||
prompt += f"之前群里进行了如下讨论:\n"
|
prompt += "之前群里进行了如下讨论:\n"
|
||||||
prompt += message_txt
|
prompt += message_txt
|
||||||
# prompt += f"你注意到{sender_name}刚刚说:{message_txt}\n"
|
# prompt += f"你注意到{sender_name}刚刚说:{message_txt}\n"
|
||||||
prompt += f"注意你就是{bot_name},{bot_name}是你的名字。根据之前的聊天记录补充问题信息,搜索时避开你的名字。\n"
|
prompt += f"注意你就是{bot_name},{bot_name}是你的名字。根据之前的聊天记录补充问题信息,搜索时避开你的名字。\n"
|
||||||
|
|||||||
@@ -238,12 +238,18 @@ class SubHeartflow:
|
|||||||
extra_info_prompt = "无工具信息。\n" # 提供默认值
|
extra_info_prompt = "无工具信息。\n" # 提供默认值
|
||||||
|
|
||||||
individuality = Individuality.get_instance()
|
individuality = Individuality.get_instance()
|
||||||
prompt_personality = f"你的名字是{self.bot_name},你"
|
prompt_personality = f"你的名字是{self.bot_name},你"
|
||||||
prompt_personality += individuality.personality.personality_core
|
prompt_personality += individuality.personality.personality_core
|
||||||
personality_sides = individuality.personality.personality_sides
|
|
||||||
if personality_sides: random.shuffle(personality_sides); prompt_personality += f",{personality_sides[0]}"
|
# 添加随机性格侧面
|
||||||
identity_detail = individuality.identity.identity_detail
|
if individuality.personality.personality_sides:
|
||||||
if identity_detail: random.shuffle(identity_detail); prompt_personality += f",{identity_detail[0]}"
|
random_side = random.choice(individuality.personality.personality_sides)
|
||||||
|
prompt_personality += f",{random_side}"
|
||||||
|
|
||||||
|
# 添加随机身份细节
|
||||||
|
if individuality.identity.identity_detail:
|
||||||
|
random_detail = random.choice(individuality.identity.identity_detail)
|
||||||
|
prompt_personality += f",{random_detail}"
|
||||||
|
|
||||||
time_now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
time_now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
import random
|
|
||||||
|
|
||||||
|
|
||||||
from ...models.utils_model import LLMRequest
|
from ...models.utils_model import LLMRequest
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import time
|
import time
|
||||||
from random import random
|
|
||||||
import traceback
|
import traceback
|
||||||
from typing import List, Optional, Dict
|
from typing import List, Optional, Dict
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -18,7 +17,7 @@ from ...person_info.relationship_manager import relationship_manager
|
|||||||
from src.plugins.respon_info_catcher.info_catcher import info_catcher_manager
|
from src.plugins.respon_info_catcher.info_catcher import info_catcher_manager
|
||||||
from ...utils.timer_calculater import Timer
|
from ...utils.timer_calculater import Timer
|
||||||
from src.do_tool.tool_use import ToolUser
|
from src.do_tool.tool_use import ToolUser
|
||||||
from .interest import InterestManager, InterestChatting
|
from .interest import InterestManager
|
||||||
from src.plugins.chat.chat_stream import chat_manager
|
from src.plugins.chat.chat_stream import chat_manager
|
||||||
from src.plugins.chat.message import BaseMessageInfo
|
from src.plugins.chat.message import BaseMessageInfo
|
||||||
from .pf_chatting import PFChatting
|
from .pf_chatting import PFChatting
|
||||||
@@ -405,7 +404,8 @@ class HeartFC_Chat:
|
|||||||
# 假设 detailed_plain_text 字段包含所需文本
|
# 假设 detailed_plain_text 字段包含所需文本
|
||||||
# 你可能需要更复杂的逻辑来格式化,例如添加发送者和时间
|
# 你可能需要更复杂的逻辑来格式化,例如添加发送者和时间
|
||||||
text = msg_dict.get('detailed_plain_text', '')
|
text = msg_dict.get('detailed_plain_text', '')
|
||||||
if text: context_texts.append(text)
|
if text:
|
||||||
|
context_texts.append(text)
|
||||||
observation_context_text = "\n".join(context_texts)
|
observation_context_text = "\n".join(context_texts)
|
||||||
logger.debug(f"[{stream_name}] Context for tools:\n{observation_context_text[-200:]}...") # 打印部分上下文
|
logger.debug(f"[{stream_name}] Context for tools:\n{observation_context_text[-200:]}...") # 打印部分上下文
|
||||||
else:
|
else:
|
||||||
@@ -446,7 +446,8 @@ class HeartFC_Chat:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"[{stream_name}] SubHeartflow 思考失败: {e}")
|
logger.error(f"[{stream_name}] SubHeartflow 思考失败: {e}")
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
if info_catcher: info_catcher.done_catch()
|
if info_catcher:
|
||||||
|
info_catcher.done_catch()
|
||||||
return # 思考失败则不继续
|
return # 思考失败则不继续
|
||||||
if info_catcher:
|
if info_catcher:
|
||||||
info_catcher.catch_afer_shf_step(timing_results.get("生成内心想法(SubHF)"), past_mind, current_mind)
|
info_catcher.catch_afer_shf_step(timing_results.get("生成内心想法(SubHF)"), past_mind, current_mind)
|
||||||
@@ -459,13 +460,15 @@ class HeartFC_Chat:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"[{stream_name}] GPT 生成回复失败: {e}")
|
logger.error(f"[{stream_name}] GPT 生成回复失败: {e}")
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
if info_catcher: info_catcher.done_catch()
|
if info_catcher:
|
||||||
|
info_catcher.done_catch()
|
||||||
return
|
return
|
||||||
if info_catcher:
|
if info_catcher:
|
||||||
info_catcher.catch_after_generate_response(timing_results.get("生成最终回复(GPT)"))
|
info_catcher.catch_after_generate_response(timing_results.get("生成最终回复(GPT)"))
|
||||||
if not response_set:
|
if not response_set:
|
||||||
logger.info(f"[{stream_name}] 回复生成失败或为空。")
|
logger.info(f"[{stream_name}] 回复生成失败或为空。")
|
||||||
if info_catcher: info_catcher.done_catch()
|
if info_catcher:
|
||||||
|
info_catcher.done_catch()
|
||||||
return
|
return
|
||||||
|
|
||||||
# --- 10. 发送消息 (使用 anchor_message) ---
|
# --- 10. 发送消息 (使用 anchor_message) ---
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import asyncio
|
|
||||||
from ...memory_system.Hippocampus import HippocampusManager
|
from ...memory_system.Hippocampus import HippocampusManager
|
||||||
from ....config.config import global_config
|
from ....config.config import global_config
|
||||||
from ...chat.message import MessageRecv
|
from ...chat.message import MessageRecv
|
||||||
from ...storage.storage import MessageStorage
|
from ...storage.storage import MessageStorage
|
||||||
from ...chat.utils import is_mentioned_bot_in_message
|
from ...chat.utils import is_mentioned_bot_in_message
|
||||||
from ...message import UserInfo, Seg
|
from ...message import Seg
|
||||||
from src.heart_flow.heartflow import heartflow
|
from src.heart_flow.heartflow import heartflow
|
||||||
from src.common.logger import get_module_logger, CHAT_STYLE_CONFIG, LogConfig
|
from src.common.logger import get_module_logger, CHAT_STYLE_CONFIG, LogConfig
|
||||||
from ...chat.chat_stream import chat_manager
|
from ...chat.chat_stream import chat_manager
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ import asyncio
|
|||||||
import threading
|
import threading
|
||||||
import json # 引入 json
|
import json # 引入 json
|
||||||
import os # 引入 os
|
import os # 引入 os
|
||||||
import traceback # <--- 添加导入
|
|
||||||
from typing import Optional # <--- 添加导入
|
from typing import Optional # <--- 添加导入
|
||||||
import random # <--- 添加导入 random
|
import random # <--- 添加导入 random
|
||||||
from src.common.logger import get_module_logger, LogConfig, DEFAULT_CONFIG # 引入 DEFAULT_CONFIG
|
from src.common.logger import get_module_logger, LogConfig, DEFAULT_CONFIG # 引入 DEFAULT_CONFIG
|
||||||
from src.plugins.chat.chat_stream import chat_manager # *** Import ChatManager ***
|
from src.plugins.chat.chat_stream import chat_manager # *** Import ChatManager ***
|
||||||
from ...chat.message import MessageRecv # 导入 MessageRecv
|
|
||||||
|
|
||||||
# 定义日志配置 (使用 loguru 格式)
|
# 定义日志配置 (使用 loguru 格式)
|
||||||
interest_log_config = LogConfig(
|
interest_log_config = LogConfig(
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import time
|
|||||||
from typing import Dict, List, Optional, Union
|
from typing import Dict, List, Optional, Union
|
||||||
|
|
||||||
from src.common.logger import get_module_logger
|
from src.common.logger import get_module_logger
|
||||||
from ....common.database import db
|
|
||||||
from ...message.api import global_api
|
from ...message.api import global_api
|
||||||
from ...chat.message import MessageSending, MessageThinking, MessageSet
|
from ...chat.message import MessageSending, MessageThinking, MessageSet
|
||||||
from ...storage.storage import MessageStorage
|
from ...storage.storage import MessageStorage
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from typing import List, Optional, Dict, Any, Deque, Union, TYPE_CHECKING
|
from typing import List, Optional, Dict, Any, TYPE_CHECKING
|
||||||
from collections import deque
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from ....config.config import global_config
|
from ....config.config import global_config
|
||||||
@@ -14,7 +13,6 @@ from src.plugins.chat.chat_stream import chat_manager
|
|||||||
from .messagesender import MessageManager
|
from .messagesender import MessageManager
|
||||||
from src.common.logger import get_module_logger, LogConfig, DEFAULT_CONFIG # 引入 DEFAULT_CONFIG
|
from src.common.logger import get_module_logger, LogConfig, DEFAULT_CONFIG # 引入 DEFAULT_CONFIG
|
||||||
from src.plugins.models.utils_model import LLMRequest
|
from src.plugins.models.utils_model import LLMRequest
|
||||||
from src.individuality.individuality import Individuality
|
|
||||||
|
|
||||||
# 定义日志配置 (使用 loguru 格式)
|
# 定义日志配置 (使用 loguru 格式)
|
||||||
interest_log_config = LogConfig(
|
interest_log_config = LogConfig(
|
||||||
@@ -475,24 +473,36 @@ class PFChatting:
|
|||||||
logger.info(f"{log_prefix}[Planner] LLM 决策: {action}, 理由: {reasoning}, EmojiQuery: '{emoji_query}'")
|
logger.info(f"{log_prefix}[Planner] LLM 决策: {action}, 理由: {reasoning}, EmojiQuery: '{emoji_query}'")
|
||||||
except json.JSONDecodeError as json_e:
|
except json.JSONDecodeError as json_e:
|
||||||
logger.error(f"{log_prefix}[Planner] 解析工具参数失败: {json_e}. Arguments: {tool_call['function'].get('arguments')}")
|
logger.error(f"{log_prefix}[Planner] 解析工具参数失败: {json_e}. Arguments: {tool_call['function'].get('arguments')}")
|
||||||
action = "error"; reasoning = "工具参数解析失败"; llm_error = True
|
action = "error"
|
||||||
|
reasoning = "工具参数解析失败"
|
||||||
|
llm_error = True
|
||||||
except Exception as parse_e:
|
except Exception as parse_e:
|
||||||
logger.error(f"{log_prefix}[Planner] 处理工具参数时出错: {parse_e}")
|
logger.error(f"{log_prefix}[Planner] 处理工具参数时出错: {parse_e}")
|
||||||
action = "error"; reasoning = "处理工具参数时出错"; llm_error = True
|
action = "error"
|
||||||
|
reasoning = "处理工具参数时出错"
|
||||||
|
llm_error = True
|
||||||
else:
|
else:
|
||||||
logger.warning(f"{log_prefix}[Planner] LLM 未按预期调用 'decide_reply_action' 工具。Tool calls: {tool_calls}")
|
logger.warning(f"{log_prefix}[Planner] LLM 未按预期调用 'decide_reply_action' 工具。Tool calls: {tool_calls}")
|
||||||
action = "error"; reasoning = "LLM未调用预期工具"; llm_error = True
|
action = "error"
|
||||||
|
reasoning = "LLM未调用预期工具"
|
||||||
|
llm_error = True
|
||||||
else:
|
else:
|
||||||
logger.warning(f"{log_prefix}[Planner] LLM 响应中未包含有效的工具调用。Tool calls: {tool_calls}")
|
logger.warning(f"{log_prefix}[Planner] LLM 响应中未包含有效的工具调用。Tool calls: {tool_calls}")
|
||||||
action = "error"; reasoning = "LLM响应无工具调用"; llm_error = True
|
action = "error"
|
||||||
|
reasoning = "LLM响应无工具调用"
|
||||||
|
llm_error = True
|
||||||
else:
|
else:
|
||||||
logger.warning(f"{log_prefix}[Planner] LLM 未返回预期的工具调用响应。Response parts: {len(response)}")
|
logger.warning(f"{log_prefix}[Planner] LLM 未返回预期的工具调用响应。Response parts: {len(response)}")
|
||||||
action = "error"; reasoning = "LLM响应格式错误"; llm_error = True
|
action = "error"
|
||||||
|
reasoning = "LLM响应格式错误"
|
||||||
|
llm_error = True
|
||||||
|
|
||||||
except Exception as llm_e:
|
except Exception as llm_e:
|
||||||
logger.error(f"{log_prefix}[Planner] Planner LLM 调用失败: {llm_e}")
|
logger.error(f"{log_prefix}[Planner] Planner LLM 调用失败: {llm_e}")
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
action = "error"; reasoning = f"LLM 调用失败: {llm_e}"; llm_error = True
|
action = "error"
|
||||||
|
reasoning = f"LLM 调用失败: {llm_e}"
|
||||||
|
llm_error = True
|
||||||
|
|
||||||
# --- 返回决策结果 ---
|
# --- 返回决策结果 ---
|
||||||
# Note: Lock release is handled by the loop now
|
# Note: Lock release is handled by the loop now
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from .think_flow_generator import ResponseGenerator
|
|||||||
from ...chat.message import MessageSending, MessageRecv, MessageThinking, MessageSet
|
from ...chat.message import MessageSending, MessageRecv, MessageThinking, MessageSet
|
||||||
from ...chat.messagesender import message_manager
|
from ...chat.messagesender import message_manager
|
||||||
from ...storage.storage import MessageStorage
|
from ...storage.storage import MessageStorage
|
||||||
from ...chat.utils import is_mentioned_bot_in_message, get_recent_group_detailed_plain_text
|
from ...chat.utils import is_mentioned_bot_in_message
|
||||||
from ...chat.utils_image import image_path_to_base64
|
from ...chat.utils_image import image_path_to_base64
|
||||||
from ...willing.willing_manager import willing_manager
|
from ...willing.willing_manager import willing_manager
|
||||||
from ...message import UserInfo, Seg
|
from ...message import UserInfo, Seg
|
||||||
|
|||||||
Reference in New Issue
Block a user