fix: ruff format & check
This commit is contained in:
@@ -91,7 +91,6 @@ class HeartFChatting:
|
|||||||
self.action_manager = ActionManager()
|
self.action_manager = ActionManager()
|
||||||
self.action_planner = ActionPlanner(log_prefix=self.log_prefix, action_manager=self.action_manager)
|
self.action_planner = ActionPlanner(log_prefix=self.log_prefix, action_manager=self.action_manager)
|
||||||
|
|
||||||
|
|
||||||
# --- 处理器列表 ---
|
# --- 处理器列表 ---
|
||||||
self.processors: List[BaseProcessor] = []
|
self.processors: List[BaseProcessor] = []
|
||||||
self._register_default_processors()
|
self._register_default_processors()
|
||||||
@@ -526,5 +525,3 @@ class HeartFChatting:
|
|||||||
if last_n is not None:
|
if last_n is not None:
|
||||||
history = history[-last_n:]
|
history = history[-last_n:]
|
||||||
return [cycle.to_dict() for cycle in history]
|
return [cycle.to_dict() for cycle in history]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
from typing import Dict, List, Optional, Callable, Coroutine, Type, Any, Union
|
from typing import Dict, List, Optional, Callable, Coroutine, Type, Any
|
||||||
import os
|
from src.chat.focus_chat.planners.actions.base_action import BaseAction, _ACTION_REGISTRY
|
||||||
import importlib
|
|
||||||
from src.chat.focus_chat.planners.actions.base_action import BaseAction, _ACTION_REGISTRY, _DEFAULT_ACTIONS
|
|
||||||
from src.chat.heart_flow.observation.observation import Observation
|
from src.chat.heart_flow.observation.observation import Observation
|
||||||
from src.chat.focus_chat.expressors.default_expressor import DefaultExpressor
|
from src.chat.focus_chat.expressors.default_expressor import DefaultExpressor
|
||||||
from src.chat.message_receive.chat_stream import ChatStream
|
from src.chat.message_receive.chat_stream import ChatStream
|
||||||
@@ -9,8 +7,6 @@ from src.chat.focus_chat.heartFC_Cycleinfo import CycleDetail
|
|||||||
from src.common.logger_manager import get_logger
|
from src.common.logger_manager import get_logger
|
||||||
|
|
||||||
# 导入动作类,确保装饰器被执行
|
# 导入动作类,确保装饰器被执行
|
||||||
from src.chat.focus_chat.planners.actions.reply_action import ReplyAction
|
|
||||||
from src.chat.focus_chat.planners.actions.no_reply_action import NoReplyAction
|
|
||||||
|
|
||||||
logger = get_logger("action_factory")
|
logger = get_logger("action_factory")
|
||||||
|
|
||||||
@@ -45,7 +41,6 @@ class ActionManager:
|
|||||||
# for action_name, action_info in self._using_actions.items():
|
# for action_name, action_info in self._using_actions.items():
|
||||||
# logger.info(f"动作名称: {action_name}, 动作信息: {action_info}")
|
# logger.info(f"动作名称: {action_name}, 动作信息: {action_info}")
|
||||||
|
|
||||||
|
|
||||||
def _load_registered_actions(self) -> None:
|
def _load_registered_actions(self) -> None:
|
||||||
"""
|
"""
|
||||||
加载所有通过装饰器注册的动作
|
加载所有通过装饰器注册的动作
|
||||||
@@ -54,17 +49,17 @@ class ActionManager:
|
|||||||
# 从_ACTION_REGISTRY获取所有已注册动作
|
# 从_ACTION_REGISTRY获取所有已注册动作
|
||||||
for action_name, action_class in _ACTION_REGISTRY.items():
|
for action_name, action_class in _ACTION_REGISTRY.items():
|
||||||
# 获取动作相关信息
|
# 获取动作相关信息
|
||||||
action_description:str = getattr(action_class, "action_description", "")
|
action_description: str = getattr(action_class, "action_description", "")
|
||||||
action_parameters:dict[str:str] = getattr(action_class, "action_parameters", {})
|
action_parameters: dict[str:str] = getattr(action_class, "action_parameters", {})
|
||||||
action_require:list[str] = getattr(action_class, "action_require", [])
|
action_require: list[str] = getattr(action_class, "action_require", [])
|
||||||
is_default:bool = getattr(action_class, "default", False)
|
is_default: bool = getattr(action_class, "default", False)
|
||||||
|
|
||||||
if action_name and action_description:
|
if action_name and action_description:
|
||||||
# 创建动作信息字典
|
# 创建动作信息字典
|
||||||
action_info = {
|
action_info = {
|
||||||
"description": action_description,
|
"description": action_description,
|
||||||
"parameters": action_parameters,
|
"parameters": action_parameters,
|
||||||
"require": action_require
|
"require": action_require,
|
||||||
}
|
}
|
||||||
|
|
||||||
# 注册2
|
# 注册2
|
||||||
@@ -233,11 +228,7 @@ class ActionManager:
|
|||||||
if require is None:
|
if require is None:
|
||||||
require = []
|
require = []
|
||||||
|
|
||||||
action_info = {
|
action_info = {"description": description, "parameters": parameters, "require": require}
|
||||||
"description": description,
|
|
||||||
"parameters": parameters,
|
|
||||||
"require": require
|
|
||||||
}
|
|
||||||
|
|
||||||
self._registered_actions[action_name] = action_info
|
self._registered_actions[action_name] = action_info
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ def register_action(cls):
|
|||||||
logger.error(f"动作类 {cls.__name__} 缺少必要的属性: action_name 或 action_description")
|
logger.error(f"动作类 {cls.__name__} 缺少必要的属性: action_name 或 action_description")
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
action_name = getattr(cls, "action_name")
|
action_name = cls.action_name
|
||||||
action_description = getattr(cls, "action_description")
|
action_description = cls.action_description
|
||||||
is_default = getattr(cls, "default", False)
|
is_default = getattr(cls, "default", False)
|
||||||
|
|
||||||
if not action_name or not action_description:
|
if not action_name or not action_description:
|
||||||
@@ -60,14 +60,13 @@ class BaseAction(ABC):
|
|||||||
cycle_timers: 计时器字典
|
cycle_timers: 计时器字典
|
||||||
thinking_id: 思考ID
|
thinking_id: 思考ID
|
||||||
"""
|
"""
|
||||||
#每个动作必须实现
|
# 每个动作必须实现
|
||||||
self.action_name:str = "base_action"
|
self.action_name: str = "base_action"
|
||||||
self.action_description:str = "基础动作"
|
self.action_description: str = "基础动作"
|
||||||
self.action_parameters:dict = {}
|
self.action_parameters: dict = {}
|
||||||
self.action_require:list[str] = []
|
self.action_require: list[str] = []
|
||||||
|
|
||||||
self.default:bool = False
|
|
||||||
|
|
||||||
|
self.default: bool = False
|
||||||
|
|
||||||
self.action_data = action_data
|
self.action_data = action_data
|
||||||
self.reasoning = reasoning
|
self.reasoning = reasoning
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class NoReplyAction(BaseAction):
|
|||||||
action_require = [
|
action_require = [
|
||||||
"话题无关/无聊/不感兴趣/不懂",
|
"话题无关/无聊/不感兴趣/不懂",
|
||||||
"最后一条消息是你自己发的且无人回应你",
|
"最后一条消息是你自己发的且无人回应你",
|
||||||
"你发送了太多消息,且无人回复"
|
"你发送了太多消息,且无人回复",
|
||||||
]
|
]
|
||||||
default = True
|
default = True
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ class NoReplyAction(BaseAction):
|
|||||||
total_no_reply_count: int = 0,
|
total_no_reply_count: int = 0,
|
||||||
total_waiting_time: float = 0.0,
|
total_waiting_time: float = 0.0,
|
||||||
shutting_down: bool = False,
|
shutting_down: bool = False,
|
||||||
**kwargs
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""初始化不回复动作处理器
|
"""初始化不回复动作处理器
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from src.common.logger_manager import get_logger
|
from src.common.logger_manager import get_logger
|
||||||
from src.chat.utils.timer_calculator import Timer
|
|
||||||
from src.chat.focus_chat.planners.actions.base_action import BaseAction, register_action
|
from src.chat.focus_chat.planners.actions.base_action import BaseAction, register_action
|
||||||
from typing import Tuple, List, Optional
|
from typing import Tuple, List
|
||||||
from src.chat.heart_flow.observation.observation import Observation
|
from src.chat.heart_flow.observation.observation import Observation
|
||||||
from src.chat.focus_chat.expressors.default_expressor import DefaultExpressor
|
from src.chat.focus_chat.expressors.default_expressor import DefaultExpressor
|
||||||
from src.chat.message_receive.chat_stream import ChatStream
|
from src.chat.message_receive.chat_stream import ChatStream
|
||||||
@@ -22,14 +21,14 @@ class ReplyAction(BaseAction):
|
|||||||
处理构建和发送消息回复的动作。
|
处理构建和发送消息回复的动作。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
action_name:str = "reply"
|
action_name: str = "reply"
|
||||||
action_description:str = "表达想法,可以只包含文本、表情或两者都有"
|
action_description: str = "表达想法,可以只包含文本、表情或两者都有"
|
||||||
action_parameters:dict[str:str] = {
|
action_parameters: dict[str:str] = {
|
||||||
"text": "你想要表达的内容(可选)",
|
"text": "你想要表达的内容(可选)",
|
||||||
"emojis": "描述当前使用表情包的场景(可选)",
|
"emojis": "描述当前使用表情包的场景(可选)",
|
||||||
"target": "你想要回复的原始文本内容(非必须,仅文本,不包含发送者)(可选)",
|
"target": "你想要回复的原始文本内容(非必须,仅文本,不包含发送者)(可选)",
|
||||||
}
|
}
|
||||||
action_require:list[str] = [
|
action_require: list[str] = [
|
||||||
"有实质性内容需要表达",
|
"有实质性内容需要表达",
|
||||||
"有人提到你,但你还没有回应他",
|
"有人提到你,但你还没有回应他",
|
||||||
"在合适的时候添加表情(不要总是添加)",
|
"在合适的时候添加表情(不要总是添加)",
|
||||||
@@ -38,7 +37,7 @@ class ReplyAction(BaseAction):
|
|||||||
"一次只回复一个人,一次只回复一个话题,突出重点",
|
"一次只回复一个人,一次只回复一个话题,突出重点",
|
||||||
"如果是自己发的消息想继续,需自然衔接",
|
"如果是自己发的消息想继续,需自然衔接",
|
||||||
"避免重复或评价自己的发言,不要和自己聊天",
|
"避免重复或评价自己的发言,不要和自己聊天",
|
||||||
"注意:回复尽量简短一些。可以参考贴吧,知乎和微博的回复风格,回复不要浮夸,不要用夸张修辞,平淡一些。"
|
"注意:回复尽量简短一些。可以参考贴吧,知乎和微博的回复风格,回复不要浮夸,不要用夸张修辞,平淡一些。",
|
||||||
]
|
]
|
||||||
default = True
|
default = True
|
||||||
|
|
||||||
@@ -54,7 +53,7 @@ class ReplyAction(BaseAction):
|
|||||||
chat_stream: ChatStream,
|
chat_stream: ChatStream,
|
||||||
current_cycle: CycleDetail,
|
current_cycle: CycleDetail,
|
||||||
log_prefix: str,
|
log_prefix: str,
|
||||||
**kwargs
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""初始化回复动作处理器
|
"""初始化回复动作处理器
|
||||||
|
|
||||||
@@ -89,7 +88,7 @@ class ReplyAction(BaseAction):
|
|||||||
reasoning=self.reasoning,
|
reasoning=self.reasoning,
|
||||||
reply_data=self.action_data,
|
reply_data=self.action_data,
|
||||||
cycle_timers=self.cycle_timers,
|
cycle_timers=self.cycle_timers,
|
||||||
thinking_id=self.thinking_id
|
thinking_id=self.thinking_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _handle_reply(
|
async def _handle_reply(
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from typing import List, Dict, Any, Optional
|
|||||||
from rich.traceback import install
|
from rich.traceback import install
|
||||||
from src.chat.models.utils_model import LLMRequest
|
from src.chat.models.utils_model import LLMRequest
|
||||||
from src.config.config import global_config
|
from src.config.config import global_config
|
||||||
from src.chat.focus_chat.heartflow_prompt_builder import prompt_builder
|
|
||||||
from src.chat.focus_chat.info.info_base import InfoBase
|
from src.chat.focus_chat.info.info_base import InfoBase
|
||||||
from src.chat.focus_chat.info.obs_info import ObsInfo
|
from src.chat.focus_chat.info.obs_info import ObsInfo
|
||||||
from src.chat.focus_chat.info.cycle_info import CycleInfo
|
from src.chat.focus_chat.info.cycle_info import CycleInfo
|
||||||
@@ -15,10 +14,12 @@ from src.chat.utils.prompt_builder import Prompt, global_prompt_manager
|
|||||||
from src.individuality.individuality import Individuality
|
from src.individuality.individuality import Individuality
|
||||||
from src.chat.focus_chat.planners.action_factory import ActionManager
|
from src.chat.focus_chat.planners.action_factory import ActionManager
|
||||||
from src.chat.focus_chat.planners.action_factory import ActionInfo
|
from src.chat.focus_chat.planners.action_factory import ActionInfo
|
||||||
|
|
||||||
logger = get_logger("planner")
|
logger = get_logger("planner")
|
||||||
|
|
||||||
install(extra_lines=3)
|
install(extra_lines=3)
|
||||||
|
|
||||||
|
|
||||||
def init_prompt():
|
def init_prompt():
|
||||||
Prompt(
|
Prompt(
|
||||||
"""你的名字是{bot_name},{prompt_personality},{chat_context_description}。需要基于以下信息决定如何参与对话:
|
"""你的名字是{bot_name},{prompt_personality},{chat_context_description}。需要基于以下信息决定如何参与对话:
|
||||||
@@ -44,7 +45,8 @@ def init_prompt():
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
请输出你的决策 JSON:""",
|
请输出你的决策 JSON:""",
|
||||||
"planner_prompt",)
|
"planner_prompt",
|
||||||
|
)
|
||||||
|
|
||||||
Prompt(
|
Prompt(
|
||||||
"""
|
"""
|
||||||
@@ -103,7 +105,7 @@ class ActionPlanner:
|
|||||||
cycle_info = info.get_observe_info()
|
cycle_info = info.get_observe_info()
|
||||||
elif isinstance(info, StructuredInfo):
|
elif isinstance(info, StructuredInfo):
|
||||||
logger.debug(f"{self.log_prefix} 结构化信息: {info}")
|
logger.debug(f"{self.log_prefix} 结构化信息: {info}")
|
||||||
structured_info = info.get_data()
|
_structured_info = info.get_data()
|
||||||
|
|
||||||
current_available_actions = self.action_manager.get_using_actions()
|
current_available_actions = self.action_manager.get_using_actions()
|
||||||
|
|
||||||
@@ -197,7 +199,6 @@ class ActionPlanner:
|
|||||||
# 返回结果字典
|
# 返回结果字典
|
||||||
return plan_result
|
return plan_result
|
||||||
|
|
||||||
|
|
||||||
async def build_planner_prompt(
|
async def build_planner_prompt(
|
||||||
self,
|
self,
|
||||||
is_group_chat: bool, # Now passed as argument
|
is_group_chat: bool, # Now passed as argument
|
||||||
@@ -218,7 +219,6 @@ class ActionPlanner:
|
|||||||
)
|
)
|
||||||
chat_context_description = f"你正在和 {chat_target_name} 私聊"
|
chat_context_description = f"你正在和 {chat_target_name} 私聊"
|
||||||
|
|
||||||
|
|
||||||
chat_content_block = ""
|
chat_content_block = ""
|
||||||
if observed_messages_str:
|
if observed_messages_str:
|
||||||
chat_content_block = f"聊天记录:\n{observed_messages_str}"
|
chat_content_block = f"聊天记录:\n{observed_messages_str}"
|
||||||
@@ -234,7 +234,6 @@ class ActionPlanner:
|
|||||||
individuality = Individuality.get_instance()
|
individuality = Individuality.get_instance()
|
||||||
personality_block = individuality.get_prompt(x_person=2, level=2)
|
personality_block = individuality.get_prompt(x_person=2, level=2)
|
||||||
|
|
||||||
|
|
||||||
action_options_block = ""
|
action_options_block = ""
|
||||||
for using_actions_name, using_actions_info in current_available_actions.items():
|
for using_actions_name, using_actions_info in current_available_actions.items():
|
||||||
# print(using_actions_name)
|
# print(using_actions_name)
|
||||||
@@ -262,9 +261,6 @@ class ActionPlanner:
|
|||||||
|
|
||||||
action_options_block += using_action_prompt
|
action_options_block += using_action_prompt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
planner_prompt_template = await global_prompt_manager.get_prompt_async("planner_prompt")
|
planner_prompt_template = await global_prompt_manager.get_prompt_async("planner_prompt")
|
||||||
prompt = planner_prompt_template.format(
|
prompt = planner_prompt_template.format(
|
||||||
bot_name=global_config.BOT_NICKNAME,
|
bot_name=global_config.BOT_NICKNAME,
|
||||||
|
|||||||
Reference in New Issue
Block a user