config:修改配置,可以选择开启tool,focus也支持次要回复模型

This commit is contained in:
SengokuCola
2025-07-01 18:13:04 +08:00
parent 324eb62224
commit d0956bfe66
13 changed files with 66 additions and 100 deletions

View File

@@ -17,7 +17,6 @@ from src.chat.focus_chat.info_processors.working_memory_processor import Working
from src.chat.heart_flow.observation.hfcloop_observation import HFCloopObservation
from src.chat.heart_flow.observation.working_observation import WorkingMemoryObservation
from src.chat.heart_flow.observation.chatting_observation import ChattingObservation
from src.chat.heart_flow.observation.structure_observation import StructureObservation
from src.chat.heart_flow.observation.actions_observation import ActionObservation
from src.chat.focus_chat.memory_activator import MemoryActivator
@@ -28,7 +27,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.structured_info import StructuredInfo
from src.person_info.relationship_builder_manager import relationship_builder_manager
@@ -41,7 +39,6 @@ OBSERVATION_CLASSES = {
"ChattingObservation": (ChattingObservation, "chat_id"),
"WorkingMemoryObservation": (WorkingMemoryObservation, "observe_id"),
"HFCloopObservation": (HFCloopObservation, "observe_id"),
"StructureObservation": (StructureObservation, "observe_id"),
}
# 定义处理器映射:键是处理器名称,值是 (处理器类, 可选的配置键名)

View File

@@ -1,42 +0,0 @@
from datetime import datetime
from src.common.logger import get_logger
# Import the new utility function
logger = get_logger("observation")
# 所有观察的基类
class StructureObservation:
def __init__(self, observe_id):
self.observe_info = ""
self.observe_id = observe_id
self.last_observe_time = datetime.now().timestamp() # 初始化为当前时间
self.history_loop = []
self.structured_info = []
def to_dict(self) -> dict:
"""将观察对象转换为可序列化的字典"""
return {
"observe_info": self.observe_info,
"observe_id": self.observe_id,
"last_observe_time": self.last_observe_time,
"history_loop": self.history_loop,
"structured_info": self.structured_info,
}
def get_observe_info(self):
return self.structured_info
def add_structured_info(self, structured_info: dict):
self.structured_info.append(structured_info)
async def observe(self):
observed_structured_infos = []
for structured_info in self.structured_info:
if structured_info.get("ttl") > 0:
structured_info["ttl"] -= 1
observed_structured_infos.append(structured_info)
logger.debug(f"观察到结构化信息仍旧在: {structured_info}")
self.structured_info = observed_structured_infos

View File

@@ -69,7 +69,6 @@ class NormalChat:
# 初始化Normal Chat专用表达器
self.expressor = NormalChatExpressor(self.chat_stream)
self.replyer = DefaultReplyer(self.chat_stream)
# Interest dict
self.interest_dict = interest_dict

View File

@@ -16,7 +16,7 @@ class NormalChatGenerator:
model_config_1 = global_config.model.replyer_1.copy()
model_config_2 = global_config.model.replyer_2.copy()
prob_first = global_config.normal_chat.normal_chat_first_probability
prob_first = global_config.chat.replyer_random_probability
model_config_1["weight"] = prob_first
model_config_2["weight"] = 1.0 - prob_first
@@ -42,15 +42,13 @@ class NormalChatGenerator:
relation_info = await person_info_manager.get_value(person_id, "short_impression")
reply_to_str = f"{person_name}:{message.processed_plain_text}"
structured_info = ""
try:
success, reply_set, prompt = await generator_api.generate_reply(
chat_stream=message.chat_stream,
reply_to=reply_to_str,
relation_info=relation_info,
structured_info=structured_info,
available_actions=available_actions,
enable_tool=global_config.tool.enable_in_normal_chat,
model_configs=self.model_configs,
request_type="normal.replyer",
return_prompt=True,

View File

@@ -137,19 +137,28 @@ class DefaultReplyer:
def __init__(
self,
chat_stream: ChatStream,
enable_tool: bool = False,
model_configs: Optional[List[Dict[str, Any]]] = None,
request_type: str = "focus.replyer",
):
self.log_prefix = "replyer"
self.request_type = request_type
self.enable_tool = enable_tool
if model_configs:
self.express_model_configs = model_configs
else:
# 当未提供配置时,使用默认配置并赋予默认权重
default_config = global_config.model.replyer_1.copy()
default_config.setdefault("weight", 1.0)
self.express_model_configs = [default_config]
model_config_1 = global_config.model.replyer_1.copy()
model_config_2 = global_config.model.replyer_2.copy()
prob_first = global_config.chat.replyer_random_probability
model_config_1["weight"] = prob_first
model_config_2["weight"] = 1.0 - prob_first
self.express_model_configs = [model_config_1, model_config_2]
if not self.express_model_configs:
logger.warning("未找到有效的模型配置,回复生成可能会失败。")
@@ -169,9 +178,6 @@ class DefaultReplyer:
cache_ttl=3
)
def _select_weighted_model_config(self) -> Dict[str, Any]:
"""使用加权随机选择来挑选一个模型配置"""
configs = self.express_model_configs
@@ -214,7 +220,6 @@ class DefaultReplyer:
reply_data: Dict[str, Any] = None,
reply_to: str = "",
relation_info: str = "",
structured_info: str = "",
extra_info: str = "",
available_actions: List[str] = None,
) -> Tuple[bool, Optional[str]]:
@@ -231,7 +236,6 @@ class DefaultReplyer:
reply_data = {
"reply_to": reply_to,
"relation_info": relation_info,
"structured_info": structured_info,
"extra_info": extra_info,
}
for key, value in reply_data.items():
@@ -514,8 +518,6 @@ class DefaultReplyer:
person_info_manager = get_person_info_manager()
bot_person_id = person_info_manager.get_person_id("system", "bot_id")
is_group_chat = bool(chat_stream.group_info)
structured_info = reply_data.get("structured_info", "")
reply_to = reply_data.get("reply_to", "none")
extra_info_block = reply_data.get("extra_info", "") or reply_data.get("extra_info_block", "")
@@ -569,18 +571,15 @@ class DefaultReplyer:
keywords_reaction_prompt = await self.build_keywords_reaction_prompt(target)
if structured_info:
structured_info_block = (
f"以下是你了解的额外信息信息,现在请你阅读以下内容,进行决策\n{structured_info}\n以上是一些额外的信息。"
if tool_info:
tool_info_block = (
f"以下是你了解的额外信息信息,现在请你阅读以下内容,进行决策\n{tool_info}\n以上是一些额外的信息。"
)
else:
structured_info_block = ""
if tool_info:
tool_info_block = f"{tool_info}"
else:
tool_info_block = ""
if extra_info_block:
extra_info_block = f"以下是你在回复时需要参考的信息,现在请你阅读以下内容,进行决策\n{extra_info_block}\n以上是你在回复时需要参考的信息,现在请你阅读以下内容,进行决策"
else:
@@ -652,7 +651,6 @@ class DefaultReplyer:
chat_target=chat_target_1,
chat_info=chat_talking_prompt,
memory_block=memory_block,
structured_info_block=structured_info_block,
tool_info_block=tool_info_block,
extra_info_block=extra_info_block,
relation_info_block=relation_info,
@@ -683,7 +681,6 @@ class DefaultReplyer:
chat_target=chat_target_1,
chat_info=chat_talking_prompt,
memory_block=memory_block,
structured_info_block=structured_info_block,
tool_info_block=tool_info_block,
relation_info_block=relation_info,
extra_info_block=extra_info_block,

View File

@@ -14,6 +14,7 @@ class ReplyerManager:
self,
chat_stream: Optional[ChatStream] = None,
chat_id: Optional[str] = None,
enable_tool: bool = False,
model_configs: Optional[List[Dict[str, Any]]] = None,
request_type: str = "replyer",
) -> Optional[DefaultReplyer]:
@@ -49,6 +50,7 @@ class ReplyerManager:
# model_configs 只在此时(初始化时)生效
replyer = DefaultReplyer(
chat_stream=target_stream,
enable_tool=enable_tool,
model_configs=model_configs, # 可以是None此时使用默认模型
request_type=request_type,
)