mirror of https://github.com/Mai-with-u/MaiBot.git
feat:思考级别控制
parent
903e0f278a
commit
717b18be1e
|
|
@ -20,7 +20,7 @@ from src.express.expression_learner import expression_learner_manager
|
||||||
from src.chat.heart_flow.frequency_control import frequency_control_manager
|
from src.chat.heart_flow.frequency_control import frequency_control_manager
|
||||||
from src.express.reflect_tracker import reflect_tracker_manager
|
from src.express.reflect_tracker import reflect_tracker_manager
|
||||||
from src.express.expression_reflector import expression_reflector_manager
|
from src.express.expression_reflector import expression_reflector_manager
|
||||||
from src.jargon import extract_and_store_jargon
|
from src.bw_learner.message_recorder import extract_and_distribute_messages
|
||||||
from src.person_info.person_info import Person
|
from src.person_info.person_info import Person
|
||||||
from src.plugin_system.base.component_types import EventType, ActionInfo
|
from src.plugin_system.base.component_types import EventType, ActionInfo
|
||||||
from src.plugin_system.core import events_manager
|
from src.plugin_system.core import events_manager
|
||||||
|
|
@ -328,12 +328,12 @@ class HeartFChatting:
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
async with global_prompt_manager.async_message_scope(self.chat_stream.context.get_template_name()):
|
async with global_prompt_manager.async_message_scope(self.chat_stream.context.get_template_name()):
|
||||||
asyncio.create_task(self.expression_learner.trigger_learning_for_chat())
|
# 通过 MessageRecorder 统一提取消息并分发给 expression_learner 和 jargon_miner
|
||||||
|
# 在 replyer 执行时触发,统一管理时间窗口,避免重复获取消息
|
||||||
|
asyncio.create_task(extract_and_distribute_messages(self.stream_id))
|
||||||
|
|
||||||
# 添加curious检测任务 - 检测聊天记录中的矛盾、冲突或需要提问的内容
|
# 添加curious检测任务 - 检测聊天记录中的矛盾、冲突或需要提问的内容
|
||||||
# asyncio.create_task(check_and_make_question(self.stream_id))
|
# asyncio.create_task(check_and_make_question(self.stream_id))
|
||||||
# 添加jargon提取任务 - 提取聊天中的黑话/俚语并入库(内部自行取消息并带冷却)
|
|
||||||
asyncio.create_task(extract_and_store_jargon(self.stream_id))
|
|
||||||
# 添加聊天内容概括任务 - 累积、打包和压缩聊天记录
|
# 添加聊天内容概括任务 - 累积、打包和压缩聊天记录
|
||||||
# 注意:后台循环已在start()中启动,这里作为额外触发点,在有思考时立即处理
|
# 注意:后台循环已在start()中启动,这里作为额外触发点,在有思考时立即处理
|
||||||
# asyncio.create_task(self.chat_history_summarizer.process())
|
# asyncio.create_task(self.chat_history_summarizer.process())
|
||||||
|
|
@ -648,6 +648,7 @@ class HeartFChatting:
|
||||||
self.consecutive_no_reply_count = 0
|
self.consecutive_no_reply_count = 0
|
||||||
|
|
||||||
reason = action_planner_info.reasoning or ""
|
reason = action_planner_info.reasoning or ""
|
||||||
|
think_level = action_planner_info.action_data.get("think_level", 1)
|
||||||
# 使用 action_reasoning(planner 的整体思考理由)作为 reply_reason
|
# 使用 action_reasoning(planner 的整体思考理由)作为 reply_reason
|
||||||
planner_reasoning = action_planner_info.action_reasoning or reason
|
planner_reasoning = action_planner_info.action_reasoning or reason
|
||||||
await database_api.store_action_info(
|
await database_api.store_action_info(
|
||||||
|
|
@ -671,6 +672,7 @@ class HeartFChatting:
|
||||||
request_type="replyer",
|
request_type="replyer",
|
||||||
from_plugin=False,
|
from_plugin=False,
|
||||||
reply_time_point=action_planner_info.action_data.get("loop_start_time", time.time()),
|
reply_time_point=action_planner_info.action_data.get("loop_start_time", time.time()),
|
||||||
|
think_level=think_level,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not success or not llm_response or not llm_response.reply_set:
|
if not success or not llm_response or not llm_response.reply_set:
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,8 @@ reply
|
||||||
2.你可以自然的顺着正在进行的聊天内容进行回复或自然的提出一个问题
|
2.你可以自然的顺着正在进行的聊天内容进行回复或自然的提出一个问题
|
||||||
3.不要回复你自己发送的消息
|
3.不要回复你自己发送的消息
|
||||||
4.不要单独对表情包进行回复
|
4.不要单独对表情包进行回复
|
||||||
{{"action":"reply", "target_message_id":"消息id(m+数字)", "reason":"原因"}}
|
5.think_level表示思考深度,0表示该回复不需要思考,1表示该回复需要简单思考,2表示该回复需要深度思考
|
||||||
|
{{"action":"reply", "think_level":数值等级(0-2), "target_message_id":"消息id(m+数字)"}}
|
||||||
|
|
||||||
no_reply
|
no_reply
|
||||||
动作描述:
|
动作描述:
|
||||||
|
|
@ -60,7 +61,6 @@ no_reply
|
||||||
|
|
||||||
{action_options_text}
|
{action_options_text}
|
||||||
|
|
||||||
|
|
||||||
**你之前的action执行和思考记录**
|
**你之前的action执行和思考记录**
|
||||||
{actions_before_now_block}
|
{actions_before_now_block}
|
||||||
|
|
||||||
|
|
@ -72,12 +72,13 @@ no_reply
|
||||||
{plan_style}
|
{plan_style}
|
||||||
{moderation_prompt}
|
{moderation_prompt}
|
||||||
|
|
||||||
|
target_message_id为必填,表示触发消息的id
|
||||||
请选择所有符合使用要求的action,动作用json格式输出,用```json包裹,如果输出多个json,每个json都要单独一行放在同一个```json代码块内,你可以重复使用同一个动作或不同动作:
|
请选择所有符合使用要求的action,动作用json格式输出,用```json包裹,如果输出多个json,每个json都要单独一行放在同一个```json代码块内,你可以重复使用同一个动作或不同动作:
|
||||||
**示例**
|
**示例**
|
||||||
// 理由文本(简短)
|
// 理由文本(简短)
|
||||||
```json
|
```json
|
||||||
{{"action":"动作名", "target_message_id":"m123", "reason":"原因"}}
|
{{"action":"动作名", "target_message_id":"m123", .....}}
|
||||||
{{"action":"动作名", "target_message_id":"m456", "reason":"原因"}}
|
{{"action":"动作名", "target_message_id":"m456", .....}}
|
||||||
```""",
|
```""",
|
||||||
"planner_prompt",
|
"planner_prompt",
|
||||||
)
|
)
|
||||||
|
|
@ -112,8 +113,8 @@ no_reply
|
||||||
**示例**
|
**示例**
|
||||||
// 理由文本(简短)
|
// 理由文本(简短)
|
||||||
```json
|
```json
|
||||||
{{"action":"动作名", "target_message_id":"m123", "reason":"原因"}}
|
{{"action":"动作名", "target_message_id":"m123"}}
|
||||||
{{"action":"动作名", "target_message_id":"m456", "reason":"原因"}}
|
{{"action":"动作名", "target_message_id":"m456"}}
|
||||||
```""",
|
```""",
|
||||||
"planner_prompt_mentioned",
|
"planner_prompt_mentioned",
|
||||||
)
|
)
|
||||||
|
|
@ -124,7 +125,7 @@ no_reply
|
||||||
动作描述:{action_description}
|
动作描述:{action_description}
|
||||||
使用条件{parallel_text}:
|
使用条件{parallel_text}:
|
||||||
{action_require}
|
{action_require}
|
||||||
{{"action":"{action_name}",{action_parameters}, "target_message_id":"消息id(m+数字)", "reason":"原因"}}
|
{{"action":"{action_name}",{action_parameters}, "target_message_id":"消息id(m+数字)"}}
|
||||||
""",
|
""",
|
||||||
"action_prompt",
|
"action_prompt",
|
||||||
)
|
)
|
||||||
|
|
@ -218,11 +219,14 @@ class ActionPlanner:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
action = action_json.get("action", "no_reply")
|
action = action_json.get("action", "no_reply")
|
||||||
original_reasoning = action_json.get("reason", "未提供原因")
|
# 使用 extracted_reasoning(整体推理文本)作为 reasoning
|
||||||
reasoning = self._replace_message_ids_with_text(original_reasoning, message_id_list)
|
if extracted_reasoning:
|
||||||
if reasoning is None:
|
reasoning = self._replace_message_ids_with_text(extracted_reasoning, message_id_list)
|
||||||
reasoning = original_reasoning
|
if reasoning is None:
|
||||||
action_data = {key: value for key, value in action_json.items() if key not in ["action", "reason"]}
|
reasoning = extracted_reasoning
|
||||||
|
else:
|
||||||
|
reasoning = "未提供原因"
|
||||||
|
action_data = {key: value for key, value in action_json.items() if key not in ["action"]}
|
||||||
# 非no_reply动作需要target_message_id
|
# 非no_reply动作需要target_message_id
|
||||||
target_message = None
|
target_message = None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ class DefaultReplyer:
|
||||||
stream_id: Optional[str] = None,
|
stream_id: Optional[str] = None,
|
||||||
reply_message: Optional[DatabaseMessages] = None,
|
reply_message: Optional[DatabaseMessages] = None,
|
||||||
reply_time_point: Optional[float] = time.time(),
|
reply_time_point: Optional[float] = time.time(),
|
||||||
|
think_level: int = 1,
|
||||||
) -> Tuple[bool, LLMGenerationDataModel]:
|
) -> Tuple[bool, LLMGenerationDataModel]:
|
||||||
# sourcery skip: merge-nested-ifs
|
# sourcery skip: merge-nested-ifs
|
||||||
"""
|
"""
|
||||||
|
|
@ -106,6 +107,7 @@ class DefaultReplyer:
|
||||||
reply_message=reply_message,
|
reply_message=reply_message,
|
||||||
reply_reason=reply_reason,
|
reply_reason=reply_reason,
|
||||||
reply_time_point=reply_time_point,
|
reply_time_point=reply_time_point,
|
||||||
|
think_level=think_level,
|
||||||
)
|
)
|
||||||
llm_response.prompt = prompt
|
llm_response.prompt = prompt
|
||||||
llm_response.selected_expressions = selected_expressions
|
llm_response.selected_expressions = selected_expressions
|
||||||
|
|
@ -698,6 +700,7 @@ class DefaultReplyer:
|
||||||
chosen_actions: Optional[List[ActionPlannerInfo]] = None,
|
chosen_actions: Optional[List[ActionPlannerInfo]] = None,
|
||||||
enable_tool: bool = True,
|
enable_tool: bool = True,
|
||||||
reply_time_point: Optional[float] = time.time(),
|
reply_time_point: Optional[float] = time.time(),
|
||||||
|
think_level: int = 1,
|
||||||
) -> Tuple[str, List[int]]:
|
) -> Tuple[str, List[int]]:
|
||||||
"""
|
"""
|
||||||
构建回复器上下文
|
构建回复器上下文
|
||||||
|
|
@ -795,7 +798,7 @@ class DefaultReplyer:
|
||||||
self._time_and_run_task(self.build_personality_prompt(), "personality_prompt"),
|
self._time_and_run_task(self.build_personality_prompt(), "personality_prompt"),
|
||||||
self._time_and_run_task(
|
self._time_and_run_task(
|
||||||
build_memory_retrieval_prompt(
|
build_memory_retrieval_prompt(
|
||||||
chat_talking_prompt_short, sender, target, self.chat_stream, self.tool_executor
|
chat_talking_prompt_short, sender, target, self.chat_stream, self.tool_executor, think_level=think_level
|
||||||
),
|
),
|
||||||
"memory_retrieval",
|
"memory_retrieval",
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ class PrivateReplyer:
|
||||||
chosen_actions: Optional[List[ActionPlannerInfo]] = None,
|
chosen_actions: Optional[List[ActionPlannerInfo]] = None,
|
||||||
enable_tool: bool = True,
|
enable_tool: bool = True,
|
||||||
from_plugin: bool = True,
|
from_plugin: bool = True,
|
||||||
|
think_level: int = 1,
|
||||||
stream_id: Optional[str] = None,
|
stream_id: Optional[str] = None,
|
||||||
reply_message: Optional[DatabaseMessages] = None,
|
reply_message: Optional[DatabaseMessages] = None,
|
||||||
reply_time_point: Optional[float] = time.time(),
|
reply_time_point: Optional[float] = time.time(),
|
||||||
|
|
|
||||||
|
|
@ -44,23 +44,4 @@ def init_replyer_prompt():
|
||||||
请注意不要输出多余内容(包括前后缀,冒号和引号,括号,表情等),只输出回复内容。
|
请注意不要输出多余内容(包括前后缀,冒号和引号,括号,表情等),只输出回复内容。
|
||||||
{moderation_prompt}不要输出多余内容(包括前后缀,冒号和引号,括号,表情包,at或 @等 )。""",
|
{moderation_prompt}不要输出多余内容(包括前后缀,冒号和引号,括号,表情包,at或 @等 )。""",
|
||||||
"private_replyer_prompt",
|
"private_replyer_prompt",
|
||||||
)
|
)
|
||||||
|
|
||||||
Prompt(
|
|
||||||
"""{knowledge_prompt}{tool_info_block}{extra_info_block}
|
|
||||||
{expression_habits_block}{memory_retrieval}{jargon_explanation}
|
|
||||||
|
|
||||||
你正在和{sender_name}聊天,这是你们之前聊的内容:
|
|
||||||
{time_block}
|
|
||||||
{dialogue_prompt}
|
|
||||||
|
|
||||||
你现在想补充说明你刚刚自己的发言内容:{target},原因是{reason}
|
|
||||||
请你根据聊天内容,组织一条新回复。注意,{target} 是刚刚你自己的发言,你要在这基础上进一步发言,请按照你自己的角度来继续进行回复。注意保持上下文的连贯性。
|
|
||||||
{identity}
|
|
||||||
{chat_prompt}尽量简短一些。{keywords_reaction_prompt}请注意把握聊天内容,不要回复的太有条理,可以有个性。
|
|
||||||
{reply_style}
|
|
||||||
请注意不要输出多余内容(包括前后缀,冒号和引号,括号,表情等),只输出回复内容。
|
|
||||||
{moderation_prompt}不要输出多余内容(包括冒号和引号,括号,表情包,at或 @等 )。
|
|
||||||
""",
|
|
||||||
"private_replyer_self_prompt",
|
|
||||||
)
|
|
||||||
|
|
@ -81,6 +81,7 @@ async def generate_reply(
|
||||||
chat_id: Optional[str] = None,
|
chat_id: Optional[str] = None,
|
||||||
action_data: Optional[Dict[str, Any]] = None,
|
action_data: Optional[Dict[str, Any]] = None,
|
||||||
reply_message: Optional["DatabaseMessages"] = None,
|
reply_message: Optional["DatabaseMessages"] = None,
|
||||||
|
think_level: int = 1,
|
||||||
extra_info: str = "",
|
extra_info: str = "",
|
||||||
reply_reason: str = "",
|
reply_reason: str = "",
|
||||||
available_actions: Optional[Dict[str, ActionInfo]] = None,
|
available_actions: Optional[Dict[str, ActionInfo]] = None,
|
||||||
|
|
@ -136,6 +137,7 @@ async def generate_reply(
|
||||||
enable_tool=enable_tool,
|
enable_tool=enable_tool,
|
||||||
reply_message=reply_message,
|
reply_message=reply_message,
|
||||||
reply_reason=reply_reason,
|
reply_reason=reply_reason,
|
||||||
|
think_level=think_level,
|
||||||
from_plugin=from_plugin,
|
from_plugin=from_plugin,
|
||||||
stream_id=chat_stream.stream_id if chat_stream else chat_id,
|
stream_id=chat_stream.stream_id if chat_stream else chat_id,
|
||||||
reply_time_point=reply_time_point,
|
reply_time_point=reply_time_point,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue