🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -11,7 +11,12 @@ from json_repair import repair_json
|
||||
from src.chat.utils.utils import get_chat_type_and_target_info
|
||||
from datetime import datetime
|
||||
from src.chat.message_receive.chat_stream import get_chat_manager
|
||||
from src.chat.utils.chat_message_builder import build_readable_actions, build_readable_messages, get_actions_by_timestamp_with_chat, get_raw_msg_before_timestamp_with_chat
|
||||
from src.chat.utils.chat_message_builder import (
|
||||
build_readable_actions,
|
||||
build_readable_messages,
|
||||
get_actions_by_timestamp_with_chat,
|
||||
get_raw_msg_before_timestamp_with_chat,
|
||||
)
|
||||
import time
|
||||
|
||||
logger = get_logger("planner")
|
||||
@@ -226,13 +231,13 @@ class ActionPlanner:
|
||||
truncate=True,
|
||||
show_actions=True,
|
||||
)
|
||||
|
||||
actions_before_now = get_actions_by_timestamp_with_chat(
|
||||
|
||||
actions_before_now = get_actions_by_timestamp_with_chat(
|
||||
chat_id=self.chat_id,
|
||||
timestamp_end=time.time(),
|
||||
limit=5,
|
||||
)
|
||||
|
||||
|
||||
actions_before_now_block = build_readable_actions(
|
||||
actions=actions_before_now,
|
||||
)
|
||||
|
||||
@@ -78,7 +78,11 @@ def get_raw_msg_by_timestamp_with_chat_users(
|
||||
|
||||
|
||||
def get_actions_by_timestamp_with_chat(
|
||||
chat_id: str, timestamp_start: float = 0, timestamp_end: float = time.time(), limit: int = 0, limit_mode: str = "latest"
|
||||
chat_id: str,
|
||||
timestamp_start: float = 0,
|
||||
timestamp_end: float = time.time(),
|
||||
limit: int = 0,
|
||||
limit_mode: str = "latest",
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""获取在特定聊天从指定时间戳到指定时间戳的动作记录,按时间升序排序,返回动作记录列表"""
|
||||
query = ActionRecords.select().where(
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import json
|
||||
import math
|
||||
import random
|
||||
import time
|
||||
|
||||
from src.chat.message_receive.message import MessageRecv
|
||||
@@ -122,7 +120,7 @@ class ChatAction:
|
||||
logger.info(f"reasoning_content: {reasoning_content}")
|
||||
|
||||
action_data = json.loads(repair_json(response))
|
||||
|
||||
|
||||
if action_data:
|
||||
self.hand_action = action_data.get("hand_action", self.hand_action)
|
||||
self.upper_body_action = action_data.get("upper_body_action", self.upper_body_action)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import asyncio
|
||||
import json
|
||||
import math
|
||||
import random
|
||||
import time
|
||||
|
||||
from src.chat.message_receive.message import MessageRecv
|
||||
|
||||
@@ -126,7 +126,6 @@ class RelationshipFetcher:
|
||||
weights = [max(1, min(10, int(point[1]))) for point in current_points]
|
||||
# 使用加权采样不放回,保证不重复
|
||||
indices = list(range(len(current_points)))
|
||||
selected_indices = set()
|
||||
points = []
|
||||
for _ in range(3):
|
||||
if not indices:
|
||||
@@ -143,7 +142,7 @@ class RelationshipFetcher:
|
||||
|
||||
# info_type = await self._build_fetch_query(person_id, target_message, chat_history)
|
||||
# if info_type:
|
||||
# await self._extract_single_info(person_id, info_type, person_name)
|
||||
# await self._extract_single_info(person_id, info_type, person_name)
|
||||
|
||||
# relation_info = self._organize_known_info()
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import random
|
||||
import time
|
||||
import json
|
||||
from typing import Tuple
|
||||
|
||||
# 导入新插件系统
|
||||
@@ -12,11 +11,8 @@ from src.common.logger import get_logger
|
||||
# 导入API模块 - 标准Python包方式
|
||||
from src.plugin_system.apis import message_api
|
||||
from src.config.config import global_config
|
||||
from src.chat.message_receive.message import MessageRecv
|
||||
from src.chat.message_receive.chat_stream import get_chat_manager
|
||||
from src.chat.memory_system.Hippocampus import hippocampus_manager
|
||||
import math
|
||||
from src.chat.utils.utils import is_mentioned_bot_in_message
|
||||
|
||||
|
||||
logger = get_logger("core_actions")
|
||||
@@ -91,7 +87,9 @@ class NoReplyAction(BaseAction):
|
||||
|
||||
# 2. 检查消息数量是否达到阈值
|
||||
if new_message_count >= exit_message_count_threshold:
|
||||
logger.info(f"{self.log_prefix} 累计消息数量达到{new_message_count}条(>{exit_message_count_threshold}),结束等待")
|
||||
logger.info(
|
||||
f"{self.log_prefix} 累计消息数量达到{new_message_count}条(>{exit_message_count_threshold}),结束等待"
|
||||
)
|
||||
exit_reason = f"{global_config.bot.nickname}(你)看到了{new_message_count}条新消息,可以考虑一下是否要进行回复"
|
||||
await self.store_action_info(
|
||||
action_build_into_prompt=False,
|
||||
@@ -114,11 +112,16 @@ class NoReplyAction(BaseAction):
|
||||
action_prompt_display=exit_reason,
|
||||
action_done=True,
|
||||
)
|
||||
return True, f"累计兴趣值达到{accumulated_interest:.2f},结束等待 (等待时间: {elapsed_time:.1f}秒)"
|
||||
return (
|
||||
True,
|
||||
f"累计兴趣值达到{accumulated_interest:.2f},结束等待 (等待时间: {elapsed_time:.1f}秒)",
|
||||
)
|
||||
|
||||
# 每10秒输出一次等待状态
|
||||
if int(elapsed_time) > 0 and int(elapsed_time) % 10 == 0:
|
||||
logger.debug(f"{self.log_prefix} 已等待{elapsed_time:.0f}秒,累计{new_message_count}条消息,继续等待...")
|
||||
logger.debug(
|
||||
f"{self.log_prefix} 已等待{elapsed_time:.0f}秒,累计{new_message_count}条消息,继续等待..."
|
||||
)
|
||||
# 使用 asyncio.sleep(1) 来避免在同一秒内重复打印日志
|
||||
await asyncio.sleep(1)
|
||||
|
||||
@@ -141,8 +144,6 @@ class NoReplyAction(BaseAction):
|
||||
if not messages_dicts:
|
||||
return 0.0
|
||||
|
||||
|
||||
|
||||
combined_text_parts = []
|
||||
is_any_mentioned = False
|
||||
|
||||
@@ -159,7 +160,7 @@ class NoReplyAction(BaseAction):
|
||||
return 0.0
|
||||
|
||||
# --- 使用合并后的文本计算兴趣值 ---
|
||||
|
||||
|
||||
if global_config.bot.nickname in full_text:
|
||||
is_any_mentioned = True
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class ReplyAction(BaseAction):
|
||||
|
||||
# 关联类型
|
||||
associated_types = ["text"]
|
||||
|
||||
|
||||
def _parse_reply_target(self, target_message: str) -> tuple:
|
||||
sender = ""
|
||||
target = ""
|
||||
@@ -71,11 +71,9 @@ class ReplyAction(BaseAction):
|
||||
logger.info(f"{self.log_prefix} 决定进行回复")
|
||||
|
||||
start_time = self.action_data.get("loop_start_time", time.time())
|
||||
|
||||
|
||||
reply_to = self.action_data.get("reply_to", "")
|
||||
sender, target = self._parse_reply_target(reply_to)
|
||||
|
||||
|
||||
|
||||
try:
|
||||
try:
|
||||
@@ -126,7 +124,7 @@ class ReplyAction(BaseAction):
|
||||
reply_text = f"你对{sender}说的{target},进行了回复:{reply_text}"
|
||||
else:
|
||||
reply_text = f"你进行发言:{reply_text}"
|
||||
|
||||
|
||||
await self.store_action_info(
|
||||
action_build_into_prompt=False,
|
||||
action_prompt_display=reply_text,
|
||||
|
||||
Reference in New Issue
Block a user